summaryrefslogtreecommitdiff
path: root/include/stdio.h
diff options
context:
space:
mode:
authorErik Andersen <andersen@codepoet.org>2000-05-14 04:16:35 +0000
committerErik Andersen <andersen@codepoet.org>2000-05-14 04:16:35 +0000
commit64bc6412188b141c010ac3b8e813b837dd991e80 (patch)
treeffa12b79ea4b13191754f54b872eb1a4f9e3a04b /include/stdio.h
Initial revision
Diffstat (limited to 'include/stdio.h')
-rw-r--r--include/stdio.h118
1 files changed, 118 insertions, 0 deletions
diff --git a/include/stdio.h b/include/stdio.h
new file mode 100644
index 000000000..1f63f6002
--- /dev/null
+++ b/include/stdio.h
@@ -0,0 +1,118 @@
+
+#ifndef __STDIO_H
+#define __STDIO_H
+
+#include <features.h>
+#include <sys/types.h>
+
+#ifndef SEEK_SET
+#define SEEK_SET 0
+#define SEEK_CUR 1
+#define SEEK_END 2
+#endif
+
+#define _IOFBF 0x00 /* full buffering */
+#define _IOLBF 0x01 /* line buffering */
+#define _IONBF 0x02 /* no buffering */
+#define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */
+
+#define __MODE_FREEBUF 0x04 /* Buffer allocated with malloc, can free */
+#define __MODE_FREEFIL 0x08 /* FILE allocated with malloc, can free */
+
+#define __MODE_READ 0x10 /* Opened in read only */
+#define __MODE_WRITE 0x20 /* Opened in write only */
+#define __MODE_RDWR 0x30 /* Opened in read/write */
+
+#define __MODE_READING 0x40 /* Buffer has pending read data */
+#define __MODE_WRITING 0x80 /* Buffer has pending write data */
+
+#define __MODE_EOF 0x100 /* EOF status */
+#define __MODE_ERR 0x200 /* Error status */
+#define __MODE_UNGOT 0x400 /* Buffer has been polluted by ungetc */
+
+#define __MODE_IOTRAN 0
+
+/* when you add or change fields here, be sure to change the initialization
+ * in stdio_init and fopen */
+struct __stdio_file {
+ unsigned char *bufpos; /* the next byte to write to or read from */
+ unsigned char *bufread; /* the end of data returned by last read() */
+ unsigned char *bufwrite; /* highest address writable by macro */
+ unsigned char *bufstart; /* the start of the buffer */
+ unsigned char *bufend; /* the end of the buffer; ie the byte after the last
+ malloc()ed byte */
+
+ int fd; /* the file descriptor associated with the stream */
+ int mode;
+
+ char unbuf[8]; /* The buffer for 'unbuffered' streams */
+
+ struct __stdio_file * next;
+};
+
+#define EOF (-1)
+#ifndef NULL
+#define NULL (0)
+#endif
+
+typedef struct __stdio_file FILE;
+
+#define BUFSIZ (500) /*(508) should get us a fully used kmalloc bucket */
+
+extern FILE stdin[1];
+extern FILE stdout[1];
+extern FILE stderr[1];
+
+
+#define putc(c, stream) \
+ (((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \
+ : (unsigned char) (*(stream)->bufpos++ = (c)) )
+
+#define getc(stream) \
+ (((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \
+ (*(stream)->bufpos++))
+
+#define putchar(c) putc((c), stdout)
+#define getchar() getc(stdin)
+
+#define ferror(fp) (((fp)->mode&__MODE_ERR) != 0)
+#define feof(fp) (((fp)->mode&__MODE_EOF) != 0)
+#define clearerr(fp) ((fp)->mode &= ~(__MODE_EOF|__MODE_ERR),0)
+#define fileno(fp) ((fp)->fd)
+
+/* These two call malloc */
+#define setlinebuf(__fp) setvbuf((__fp), (char*)0, _IOLBF, 0)
+extern int setvbuf __P((FILE*, char*, int, size_t));
+
+/* These don't */
+#define setbuf(__fp, __buf) setbuffer((__fp), (__buf), BUFSIZ)
+extern void setbuffer __P((FILE*, char*, int));
+
+extern int fgetc __P((FILE*));
+extern int fputc __P((int, FILE*));
+
+extern int fclose __P((FILE*));
+extern int fflush __P((FILE*));
+extern char *fgets __P((char*, size_t, FILE*));
+extern FILE *__fopen __P((char*, int, FILE*, char*));
+
+#define fopen(__file, __mode) __fopen((__file), -1, (FILE*)0, (__mode))
+#define freopen(__file, __mode, __fp) __fopen((__file), -1, (__fp), (__mode))
+#define fdopen(__file, __mode) __fopen((char*)0, (__file), (FILE*)0, (__mode))
+
+extern int fseek __P((FILE*, long, int));
+extern long ftell __P((FILE*));
+extern void rewind __P((FILE*));
+
+extern int fputs __P((char*, FILE*));
+extern int puts __P((char*));
+
+extern int printf __P ((__const char*, ...));
+extern int fprintf __P ((FILE*, __const char*, ...));
+extern int sprintf __P ((char*, __const char*, ...));
+
+extern int ungetc __P ((int c, FILE * stream));
+
+#define stdio_pending(fp) ((fp)->bufread>(fp)->bufpos)
+
+#endif /* __STDIO_H */