1 2 #ifndef __STDIO_H 3 #define __STDIO_H 4 5 #include <features.h> 6 #include <sys/types.h> 7 8 #ifndef SEEK_SET 9 #define SEEK_SET 0 10 #define SEEK_CUR 1 11 #define SEEK_END 2 12 #endif 13 14 #define _IOFBF 0x00 /* full buffering */ 15 #define _IOLBF 0x01 /* line buffering */ 16 #define _IONBF 0x02 /* no buffering */ 17 #define __MODE_BUF 0x03 /* Modal buffering dependent on isatty */ 18 19 #define __MODE_FREEBUF 0x04 /* Buffer allocated with malloc, can free */ 20 #define __MODE_FREEFIL 0x08 /* FILE allocated with malloc, can free */ 21 22 #define __MODE_READ 0x10 /* Opened in read only */ 23 #define __MODE_WRITE 0x20 /* Opened in write only */ 24 #define __MODE_RDWR 0x30 /* Opened in read/write */ 25 26 #define __MODE_READING 0x40 /* Buffer has pending read data */ 27 #define __MODE_WRITING 0x80 /* Buffer has pending write data */ 28 29 #define __MODE_EOF 0x100 /* EOF status */ 30 #define __MODE_ERR 0x200 /* Error status */ 31 #define __MODE_UNGOT 0x400 /* Buffer has been polluted by ungetc */ 32 33 #ifdef __MSDOS__ 34 #define __MODE_IOTRAN 0x1000 /* MSDOS nl <-> cr,nl translation */ 35 #else 36 #define __MODE_IOTRAN 0 37 #endif 38 39 /* when you add or change fields here, be sure to change the initialization 40 * in stdio_init and fopen */ 41 struct __stdio_file { 42 unsigned char *bufpos; /* the next byte to write to or read from */ 43 unsigned char *bufread; /* the end of data returned by last read() */ 44 unsigned char *bufwrite; /* highest address writable by macro */ 45 unsigned char *bufstart; /* the start of the buffer */ 46 unsigned char *bufend; /* the end of the buffer; ie the byte after the last 47 malloc()ed byte */ 48 49 int fd; /* the file descriptor associated with the stream */ 50 int mode; 51 52 char unbuf[8]; /* The buffer for 'unbuffered' streams */ 53 54 struct __stdio_file * next; 55 }; 56 57 #define EOF (-1) 58 #ifndef NULL 59 #define NULL ((void*)0) 60 #endif 61 62 typedef struct __stdio_file FILE; 63 64 #ifdef __AS386_16__ 65 #define BUFSIZ (256) 66 #else 67 #define BUFSIZ (2048) 68 #endif 69 70 extern FILE stdin[1]; 71 extern FILE stdout[1]; 72 extern FILE stderr[1]; 73 74 #ifdef __MSDOS__ 75 #define putc(c, fp) fputc(c, fp) 76 #define getc(fp) fgetc(fp) 77 #else 78 #define putc(c, stream) \ 79 (((stream)->bufpos >= (stream)->bufwrite) ? fputc((c), (stream)) \ 80 : (unsigned char) (*(stream)->bufpos++ = (c)) ) 81 82 #define getc(stream) \ 83 (((stream)->bufpos >= (stream)->bufread) ? fgetc(stream): \ 84 (*(stream)->bufpos++)) 85 #endif 86 87 #define putchar(c) putc((c), stdout) 88 #define getchar() getc(stdin) 89 90 #define ferror(fp) (((fp)->mode&__MODE_ERR) != 0) 91 #define feof(fp) (((fp)->mode&__MODE_EOF) != 0) 92 #define clearerr(fp) ((fp)->mode &= ~(__MODE_EOF|__MODE_ERR),0) 93 #define fileno(fp) ((fp)->fd) 94 95 /* declare functions; not like it makes much difference without ANSI */ 96 /* RDB: The return values _are_ important, especially if we ever use 97 8086 'large' model 98 */ 99 100 /* These two call malloc */ 101 #define setlinebuf(__fp) setvbuf((__fp), (char*)0, _IOLBF, 0) 102 extern int setvbuf __P((FILE*, char*, int, size_t)); 103 104 /* These don't */ 105 #define setbuf(__fp, __buf) setbuffer((__fp), (__buf), BUFSIZ) 106 extern void setbuffer __P((FILE*, char*, int)); 107 108 extern int fgetc __P((FILE*)); 109 extern int fputc __P((int, FILE*)); 110 111 extern int fclose __P((FILE*)); 112 extern int fflush __P((FILE*)); 113 extern char *fgets __P((char*, size_t, FILE*)); 114 115 extern FILE *fopen __P((char*, char*)); 116 extern FILE *fdopen __P((int, char*)); 117 extern FILE *freopen __P((char*, char*, FILE*)); 118 119 #ifdef __LIBC__ 120 extern FILE *__fopen __P((char*, int, FILE*, char*)); 121 #endif 122 123 extern int fputs __P((char*, FILE*)); 124 extern int puts __P((char*)); 125 126 extern int printf __P ((__const char*, ...)); 127 extern int fprintf __P ((FILE*, __const char*, ...)); 128 extern int sprintf __P ((char*, __const char*, ...)); 129 130 #define stdio_pending(fp) ((fp)->bufread>(fp)->bufpos) 131 132 #endif /* __STDIO_H */ 133