1 #if __STDC__
2 #define _Cdecl
3 #else
4 #define _Cdecl cdecl
5 #endif
6
7 #if !defined(__STDIO_DEF_)
8 #define __STDIO_DEF_
9
10 #ifndef _SIZE_T
11 #define _SIZE_T
12 typedef unsigned size_t;
13 #endif
14 #ifndef NULL
15 # if defined(__TINY__) || defined(__SMALL__) || defined(__MEDIUM__)
16 # define NULL 0
17 # else
18 # define NULL 0L
19 # endif
20 #endif
21
22 #if !defined(__STDARG)
23 #include <stdarg.h>
24 #endif
25
26 /* Definition of the file position type
27 */
28 typedef long fpos_t;
29
30 /* Definition of the control structure for streams
31 */
32 typedef struct {
33 short level; /* fill/empty level of buffer */
34 unsigned flags; /* File status flags */
35 char fd; /* File descriptor */
36 unsigned char hold; /* Ungetc char if no buffer */
37 short bsize; /* Buffer size */
38 unsigned char *buffer; /* Data transfer buffer */
39 unsigned char *curp; /* Current active pointer */
40 unsigned istemp; /* Temporary file indicator */
41 short token; /* Used for validity checking */
42 } FILE; /* This is the FILE object */
43
44 /* Bufferisation type to be used as 3rd argument for "setvbuf" function
45 */
46 #define _IOFBF 0
47 #define _IOLBF 1
48 #define _IONBF 2
49
50 /* "flags" bits definitions
51 */
52 #define _F_RDWR 0x0003 /* Read/write flag */
53 #define _F_READ 0x0001 /* Read only file */
54 #define _F_WRIT 0x0002 /* Write only file */
55 #define _F_BUF 0x0004 /* Malloc'ed Buffer data */
56 #define _F_LBUF 0x0008 /* line-buffered file */
57 #define _F_ERR 0x0010 /* Error indicator */
58 #define _F_EOF 0x0020 /* EOF indicator */
59 #define _F_BIN 0x0040 /* Binary file indicator */
60 #define _F_IN 0x0080 /* Data is incoming */
61 #define _F_OUT 0x0100 /* Data is outgoing */
62 #define _F_TERM 0x0200 /* File is a terminal */
63
64 /* End-of-file constant definition
65 */
66 #define EOF (-1) /* End of file indicator */
67
68 /* Number of files that can be open simultaneously
69 */
70 #define OPEN_MAX 20 /* Total of 20 open files */
71 #define SYS_OPEN 20
72
73 /* Default buffer size use by "setbuf" function
74 */
75 #define BUFSIZ 512 /* Buffer size for stdio */
76
77 /* Size of an arry large enough to hold a temporary file name string
78 */
79 #define L_ctermid 5 /* CON: plus null byte */
80 #define L_tmpnam 13 /* tmpnam buffer size */
81
82 /* Constants to be used as 3rd argument for "fseek" function
83 */
84 #define SEEK_CUR 1
85 #define SEEK_END 2
86 #define SEEK_SET 0
87
88 /* Number of unique file names that shall be generated by "tmpnam" function
89 */
90 #define TMP_MAX 0xFFFF
91
92 /* Standard I/O predefined streams
93 */
94 extern FILE _Cdecl _streams[];
95
96 #define stdin (&_streams[0])
97 #define stdout (&_streams[1])
98 #define stderr (&_streams[2])
99 #define stdaux (&_streams[3])
100 #define stdprn (&_streams[4])
101
102 void _Cdecl clearerr (FILE *stream);
103 int _Cdecl fclose (FILE *stream);
104 int _Cdecl fflush (FILE *stream);
105 int _Cdecl fgetc (FILE *stream);
106 int _Cdecl fgetpos (FILE *stream, fpos_t *pos);
107 char *_Cdecl fgets (char *s, int n, FILE *stream);
108 FILE *_Cdecl fopen (const char *path, const char *mode);
109 int _Cdecl fprintf (FILE *stream, const char *format, ...);
110 int _Cdecl fputc (int c, FILE *stream);
111 int _Cdecl fputs (const char *s, FILE *stream);
112 size_t _Cdecl fread (void *ptr, size_t size, size_t n, FILE *stream);
113 FILE *_Cdecl freopen (const char *path, const char *mode,
114 FILE *stream);
115 int _Cdecl fscanf (FILE *stream, const char *format, ...);
116 int _Cdecl fseek (FILE *stream, long offset, int whence);
117 int _Cdecl fsetpos (FILE *stream, const fpos_t *pos);
118 long _Cdecl ftell (FILE *stream);
119 size_t _Cdecl fwrite (const void *ptr, size_t size, size_t n,
120 FILE *stream);
121 char *_Cdecl gets (char *s);
122 void _Cdecl perror (const char *s);
123 int _Cdecl printf (const char *format, ...);
124 int _Cdecl puts (const char *s);
125 int _Cdecl rename (const char *oldname, const char *newname);
126 void _Cdecl rewind (FILE *stream);
127 int _Cdecl scanf (const char *format, ...);
128 void _Cdecl setbuf (FILE *stream, char *buf);
129 int _Cdecl setvbuf (FILE *stream, char *buf, int type, size_t size);
130 int _Cdecl sprintf (char *buffer, const char *format, ...);
131 int _Cdecl sscanf (const char *buffer, const char *format, ...);
132 char *_Cdecl strerror (int errnum);
133 FILE *_Cdecl tmpfile (void);
134 char *_Cdecl tmpnam (char *s);
135 int _Cdecl ungetc (int c, FILE *stream);
136 int _Cdecl vfprintf (FILE *stream, const char *format, va_list arglist);
137 int _Cdecl vfscanf (FILE *stream, const char *format, va_list arglist);
138 int _Cdecl vprintf (const char *format, va_list arglist);
139 int _Cdecl vscanf (const char *format, va_list arglist);
140 int _Cdecl vsprintf (char *buffer, const char *format, va_list arglist);
141 int _Cdecl vsscanf (const char *buffer, const char *format, va_list arglist);
142
143 #if !__STDC__
144 int _Cdecl fcloseall(void);
145 FILE *_Cdecl fdopen (int handle, char *type);
146 int _Cdecl fgetchar (void);
147 int _Cdecl flushall (void);
148 int _Cdecl fputchar (int c);
149 int _Cdecl getw (FILE *stream);
150 int _Cdecl putw (int w, FILE *stream);
151 char *_Cdecl _strerror(const char *s);
152 int _Cdecl unlink (const char *path);
153
154 #endif
155
156 int _Cdecl _fgetc (FILE *stream); /* used by getc() macro */
157 int _Cdecl _fputc (char c, FILE *stream); /* used by putc() macro */
158
159 /* The following macros provide for common functions */
160
161 #define ferror(f) ((f)->flags & _F_ERR)
162 #define feof(f) ((f)->flags & _F_EOF)
163 #define fileno(f) ((f)->fd)
164 #pragma warn -pro
165 #define remove(path) unlink(path)
166 #pragma warn .pro
167
168 #define getc(f) \
169 ((--((f)->level) >= 0) ? (unsigned char)(++(f)->curp)[-1] : \
170 _fgetc (f))
171 #define putc(c,f) \
172 ((++((f)->level) < 0) ? (unsigned char)((++(f)->curp)[-1]=(c)) : \
173 _fputc ((c),f))
174
175 #define getchar() getc(stdin)
176 #define putchar(c) putc((c), stdout)
177
178 #define ungetc(c,f) ungetc((c),f) /* traditionally a macro */
179
180 #endif
181
182