/src/rt/release.sh: avoid requiring another MSys install
[msysgit.git] / include / stdio.h
blob49087ca52ecc7d0828cc94e012abd07a08d8ca13
1 /*
2 * Copyright (c) 1990 The Regents of the University of California.
3 * All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Berkeley. The name of the
11 * University may not be used to endorse or promote products derived
12 * from this software without specific prior written permission.
13 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
14 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
15 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 * @(#)stdio.h 5.3 (Berkeley) 3/15/86
21 * NB: to fit things in six character monocase externals, the
22 * stdio code uses the prefix `__s' for stdio objects, typically
23 * followed by a three-character attempt at a mnemonic.
26 #ifndef _STDIO_H_
27 #ifdef __cplusplus
28 extern "C" {
29 #endif
30 #define _STDIO_H_
32 #include "_ansi.h"
34 #define _FSTDIO /* ``function stdio'' */
36 #define __need_size_t
37 #include <stddef.h>
39 #define __need___va_list
40 #include <stdarg.h>
43 * <sys/reent.h> defines __sFILE, _fpos_t.
44 * They must be defined there because struct _reent needs them (and we don't
45 * want reent.h to include this file.
48 #include <sys/reent.h>
50 typedef _fpos_t fpos_t;
52 typedef struct __sFILE FILE;
54 #define __SLBF 0x0001 /* line buffered */
55 #define __SNBF 0x0002 /* unbuffered */
56 #define __SRD 0x0004 /* OK to read */
57 #define __SWR 0x0008 /* OK to write */
58 /* RD and WR are never simultaneously asserted */
59 #define __SRW 0x0010 /* open for reading & writing */
60 #define __SEOF 0x0020 /* found EOF */
61 #define __SERR 0x0040 /* found error */
62 #define __SMBF 0x0080 /* _buf is from malloc */
63 #define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */
64 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
65 #define __SOPT 0x0400 /* do fseek() optimisation */
66 #define __SNPT 0x0800 /* do not do fseek() optimisation */
67 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
68 #define __SMOD 0x2000 /* true => fgetline modified _p text */
69 #if defined(__CYGWIN__) || defined(__MSYS__)
70 #define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */
71 #endif
74 * The following three definitions are for ANSI C, which took them
75 * from System V, which stupidly took internal interface macros and
76 * made them official arguments to setvbuf(), without renaming them.
77 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
79 * Although these happen to match their counterparts above, the
80 * implementation does not rely on that (so these could be renumbered).
82 #define _IOFBF 0 /* setvbuf should set fully buffered */
83 #define _IOLBF 1 /* setvbuf should set line buffered */
84 #define _IONBF 2 /* setvbuf should set unbuffered */
86 #ifndef NULL
87 #define NULL 0
88 #endif
90 #define EOF (-1)
92 #ifdef __BUFSIZ__
93 #define BUFSIZ __BUFSIZ__
94 #else
95 #define BUFSIZ 1024
96 #endif
98 #ifdef __FOPEN_MAX__
99 #define FOPEN_MAX __FOPEN_MAX__
100 #else
101 #define FOPEN_MAX 20
102 #endif
104 #ifdef __FILENAME_MAX__
105 #define FILENAME_MAX __FILENAME_MAX__
106 #else
107 #define FILENAME_MAX 1024
108 #endif
110 #ifdef __L_tmpnam__
111 #define L_tmpnam __L_tmpnam__
112 #else
113 #define L_tmpnam FILENAME_MAX
114 #endif
116 #ifndef __STRICT_ANSI__
117 #define P_tmpdir "/tmp"
118 #endif
120 #ifndef SEEK_SET
121 #define SEEK_SET 0 /* set file offset to offset */
122 #endif
123 #ifndef SEEK_CUR
124 #define SEEK_CUR 1 /* set file offset to current plus offset */
125 #endif
126 #ifndef SEEK_END
127 #define SEEK_END 2 /* set file offset to EOF plus offset */
128 #endif
130 #define TMP_MAX 26
132 #define stdin (_impure_ptr->_stdin)
133 #define stdout (_impure_ptr->_stdout)
134 #define stderr (_impure_ptr->_stderr)
136 #define _stdin_r(x) ((x)->_stdin)
137 #define _stdout_r(x) ((x)->_stdout)
138 #define _stderr_r(x) ((x)->_stderr)
141 * Functions defined in ANSI C standard.
144 #ifdef __GNUC__
145 #define __VALIST __gnuc_va_list
146 #else
147 #define __VALIST char*
148 #endif
150 FILE * _EXFUN(tmpfile, (void));
151 char * _EXFUN(tmpnam, (char *));
152 int _EXFUN(fclose, (FILE *));
153 int _EXFUN(fflush, (FILE *));
154 FILE * _EXFUN(freopen, (const char *, const char *, FILE *));
155 void _EXFUN(setbuf, (FILE *, char *));
156 int _EXFUN(setvbuf, (FILE *, char *, int, size_t));
157 int _EXFUN(fprintf, (FILE *, const char *, ...));
158 int _EXFUN(fscanf, (FILE *, const char *, ...));
159 int _EXFUN(printf, (const char *, ...));
160 int _EXFUN(scanf, (const char *, ...));
161 int _EXFUN(sscanf, (const char *, const char *, ...));
162 int _EXFUN(vfprintf, (FILE *, const char *, __VALIST));
163 int _EXFUN(vprintf, (const char *, __VALIST));
164 int _EXFUN(vsprintf, (char *, const char *, __VALIST));
165 int _EXFUN(fgetc, (FILE *));
166 char * _EXFUN(fgets, (char *, int, FILE *));
167 int _EXFUN(fputc, (int, FILE *));
168 int _EXFUN(fputs, (const char *, FILE *));
169 int _EXFUN(getc, (FILE *));
170 int _EXFUN(getchar, (void));
171 char * _EXFUN(gets, (char *));
172 int _EXFUN(putc, (int, FILE *));
173 int _EXFUN(putchar, (int));
174 int _EXFUN(puts, (const char *));
175 int _EXFUN(ungetc, (int, FILE *));
176 size_t _EXFUN(fread, (_PTR, size_t _size, size_t _n, FILE *));
177 size_t _EXFUN(fwrite, (const _PTR , size_t _size, size_t _n, FILE *));
178 int _EXFUN(fgetpos, (FILE *, fpos_t *));
179 int _EXFUN(fseek, (FILE *, long, int));
180 int _EXFUN(fsetpos, (FILE *, const fpos_t *));
181 long _EXFUN(ftell, ( FILE *));
182 void _EXFUN(rewind, (FILE *));
183 void _EXFUN(clearerr, (FILE *));
184 int _EXFUN(feof, (FILE *));
185 int _EXFUN(ferror, (FILE *));
186 void _EXFUN(perror, (const char *));
187 #ifndef _REENT_ONLY
188 FILE * _EXFUN(fopen, (const char *_name, const char *_type));
189 int _EXFUN(sprintf, (char *, const char *, ...));
190 int _EXFUN(remove, (const char *));
191 int _EXFUN(rename, (const char *, const char *));
192 #endif
193 #ifndef __STRICT_ANSI__
194 int _EXFUN(vfiprintf, (FILE *, const char *, __VALIST));
195 int _EXFUN(iprintf, (const char *, ...));
196 int _EXFUN(fiprintf, (FILE *, const char *, ...));
197 int _EXFUN(siprintf, (char *, const char *, ...));
198 char * _EXFUN(tempnam, (const char *, const char *));
199 int _EXFUN(vsnprintf, (char *, size_t, const char *, __VALIST));
200 int _EXFUN(vfscanf, (FILE *, const char *, __VALIST));
201 int _EXFUN(vscanf, (const char *, __VALIST));
202 int _EXFUN(vsscanf, (const char *, const char *, __VALIST));
203 #ifndef _REENT_ONLY
204 int _EXFUN(snprintf, (char *, size_t, const char *, ...));
205 #endif
206 #endif
209 * Routines in POSIX 1003.1.
212 #ifndef __STRICT_ANSI__
213 #ifndef _REENT_ONLY
214 FILE * _EXFUN(fdopen, (int, const char *));
215 #endif
216 int _EXFUN(fileno, (FILE *));
217 int _EXFUN(getw, (FILE *));
218 int _EXFUN(pclose, (FILE *));
219 FILE * _EXFUN(popen, (const char *, const char *));
220 int _EXFUN(putw, (int, FILE *));
221 void _EXFUN(setbuffer, (FILE *, char *, int));
222 int _EXFUN(setlinebuf, (FILE *));
223 #endif
226 * Recursive versions of the above.
229 FILE * _EXFUN(_fdopen_r, (struct _reent *, int, const char *));
230 FILE * _EXFUN(_fopen_r, (struct _reent *, const char *, const char *));
231 int _EXFUN(_fscanf_r, (struct _reent *, FILE *, const char *, ...));
232 int _EXFUN(_getchar_r, (struct _reent *));
233 char * _EXFUN(_gets_r, (struct _reent *, char *));
234 int _EXFUN(_iprintf_r, (struct _reent *, const char *, ...));
235 int _EXFUN(_mkstemp_r, (struct _reent *, char *));
236 char * _EXFUN(_mktemp_r, (struct _reent *, char *));
237 void _EXFUN(_perror_r, (struct _reent *, const char *));
238 int _EXFUN(_printf_r, (struct _reent *, const char *, ...));
239 int _EXFUN(_putchar_r, (struct _reent *, int));
240 int _EXFUN(_puts_r, (struct _reent *, const char *));
241 int _EXFUN(_remove_r, (struct _reent *, const char *));
242 int _EXFUN(_rename_r, (struct _reent *,
243 const char *_old, const char *_new));
244 int _EXFUN(_scanf_r, (struct _reent *, const char *, ...));
245 int _EXFUN(_sprintf_r, (struct _reent *, char *, const char *, ...));
246 int _EXFUN(_snprintf_r, (struct _reent *, char *, size_t, const char *, ...));
247 int _EXFUN(_sscanf_r, (struct _reent *, const char *, const char *, ...));
248 char * _EXFUN(_tempnam_r, (struct _reent *, const char *, const char *));
249 FILE * _EXFUN(_tmpfile_r, (struct _reent *));
250 char * _EXFUN(_tmpnam_r, (struct _reent *, char *));
251 int _EXFUN(_vfprintf_r, (struct _reent *, FILE *, const char *, __VALIST));
252 int _EXFUN(_vprintf_r, (struct _reent *, const char *, __VALIST));
253 int _EXFUN(_vsprintf_r, (struct _reent *, char *, const char *, __VALIST));
254 int _EXFUN(_vsnprintf_r, (struct _reent *, char *, size_t, const char *, __VALIST));
255 int _EXFUN(_vfscanf_r, (struct _reent *, FILE *, const char *, __VALIST));
256 int _EXFUN(_vscanf_r, (struct _reent *, const char *, __VALIST));
257 int _EXFUN(_vsscanf_r, (struct _reent *, const char *, const char *, __VALIST));
260 * Routines internal to the implementation.
263 int _EXFUN(__srget, (FILE *));
264 int _EXFUN(__swbuf, (int, FILE *));
267 * Stdio function-access interface.
270 #ifndef __STRICT_ANSI__
271 FILE *_EXFUN(funopen,(const _PTR _cookie,
272 int (*readfn)(_PTR _cookie, char *_buf, int _n),
273 int (*writefn)(_PTR _cookie, const char *_buf, int _n),
274 fpos_t (*seekfn)(_PTR _cookie, fpos_t _off, int _whence),
275 int (*closefn)(_PTR _cookie)));
277 #define fropen(cookie, fn) funopen(cookie, fn, (int (*)())0, (fpos_t (*)())0, (int (*)())0)
278 #define fwopen(cookie, fn) funopen(cookie, (int (*)())0, fn, (fpos_t (*)())0, (int (*)())0)
279 #endif
282 * The __sfoo macros are here so that we can
283 * define function versions in the C library.
285 #define __sgetc_raw(p) (--(p)->_r < 0 ? __srget(p) : (int)(*(p)->_p++))
287 #ifdef __SCLE
288 static __inline__ int __sgetc(FILE *__p)
290 int __c = __sgetc_raw(__p);
291 if ((__p->_flags & __SCLE) && (__c == '\r'))
293 int __c2 = __sgetc_raw(__p);
294 if (__c2 == '\n')
295 __c = __c2;
296 else
297 ungetc(__c2, __p);
299 return __c;
301 #else
302 #define __sgetc(p) __sgetc_raw(p)
303 #endif
305 #ifdef _never /* __GNUC__ */
306 /* If this inline is actually used, then systems using coff debugging
307 info get hopelessly confused. 21sept93 rich@cygnus.com. */
308 static __inline int __sputc(int _c, FILE *_p) {
309 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
310 return (*_p->_p++ = _c);
311 else
312 return (__swbuf(_c, _p));
314 #else
316 * This has been tuned to generate reasonable code on the vax using pcc
318 #define __sputc_raw(c, p) \
319 (--(p)->_w < 0 ? \
320 (p)->_w >= (p)->_lbfsize ? \
321 (*(p)->_p = (c)), *(p)->_p != '\n' ? \
322 (int)*(p)->_p++ : \
323 __swbuf('\n', p) : \
324 __swbuf((int)(c), p) : \
325 (*(p)->_p = (c), (int)*(p)->_p++))
326 #ifdef __SCLE
327 #define __sputc(c, p) \
328 ((((p)->_flags & __SCLE) && ((c) == '\n')) \
329 ? __sputc_raw('\r', (p)) : 0 , \
330 __sputc_raw((c), (p)))
331 #else
332 #define __sputc(c, p) __sputc_raw(c, p)
333 #endif
334 #endif
336 #define __sfeof(p) (((p)->_flags & __SEOF) != 0)
337 #define __sferror(p) (((p)->_flags & __SERR) != 0)
338 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
339 #define __sfileno(p) ((p)->_file)
341 #define feof(p) __sfeof(p)
342 #define ferror(p) __sferror(p)
343 #define clearerr(p) __sclearerr(p)
345 #if 0 /*ndef __STRICT_ANSI__ - FIXME: must initialize stdio first, use fn */
346 #define fileno(p) __sfileno(p)
347 #endif
349 #if !defined (__CYGWIN__) && !defined (__MSYS__)
350 #ifndef lint
351 #define getc(fp) __sgetc(fp)
352 #define putc(x, fp) __sputc(x, fp)
353 #endif /* not lint */
354 #endif /* not __CYGWIN__ and not __MSYS__*/
356 #define getchar() getc(stdin)
357 #define putchar(x) putc(x, stdout)
359 #ifndef __STRICT_ANSI__
360 /* fast always-buffered version, true iff error */
361 #define fast_putc(x,p) (--(p)->_w < 0 ? \
362 __swbuf((int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
364 #define L_cuserid 9 /* posix says it goes in stdio.h :( */
365 #if defined (__CYGWIN__) || defined (__MSYS__)
366 #define L_ctermid 16
367 #endif
368 #endif
370 #ifdef __cplusplus
372 #endif
373 #endif /* _STDIO_H_ */