Cygwin: mmap: allow remapping part of an existing anonymous mapping
[newlib-cygwin.git] / newlib / libc / include / stdio.h
blob77966578d802e11ff2b4746a23566c55bb18e861
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 * and/or 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 #define _STDIO_H_
29 #include "_ansi.h"
31 #define _FSTDIO /* ``function stdio'' */
33 #define __need_size_t
34 #define __need_NULL
35 #include <sys/cdefs.h>
36 #include <stddef.h>
38 /* typedef only __gnuc_va_list, used throughout the header */
39 #define __need___va_list
40 #include <stdarg.h>
42 /* typedef va_list only when required */
43 #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
44 #ifdef __GNUC__
45 #ifndef _VA_LIST_DEFINED
46 typedef __gnuc_va_list va_list;
47 #define _VA_LIST_DEFINED
48 #endif
49 #else /* !__GNUC__ */
50 #include <stdarg.h>
51 #endif
52 #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
55 * <sys/reent.h> defines __FILE, _fpos_t.
56 * They must be defined there because struct _reent needs them (and we don't
57 * want reent.h to include this file.
60 #include <sys/reent.h>
61 #include <sys/_types.h>
63 _BEGIN_STD_C
65 #if !defined(__FILE_defined)
66 typedef __FILE FILE;
67 # define __FILE_defined
68 #endif
70 typedef _fpos_t fpos_t;
71 #ifdef __LARGE64_FILES
72 typedef _fpos64_t fpos64_t;
73 #endif
75 #ifndef _OFF_T_DECLARED
76 typedef __off_t off_t;
77 #define _OFF_T_DECLARED
78 #endif
80 #ifndef _SSIZE_T_DECLARED
81 typedef _ssize_t ssize_t;
82 #define _SSIZE_T_DECLARED
83 #endif
85 #include <sys/stdio.h>
87 #define __SLBF 0x0001 /* line buffered */
88 #define __SNBF 0x0002 /* unbuffered */
89 #define __SRD 0x0004 /* OK to read */
90 #define __SWR 0x0008 /* OK to write */
91 /* RD and WR are never simultaneously asserted */
92 #define __SRW 0x0010 /* open for reading & writing */
93 #define __SEOF 0x0020 /* found EOF */
94 #define __SERR 0x0040 /* found error */
95 #define __SMBF 0x0080 /* _buf is from malloc */
96 #define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */
97 #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
98 #define __SOPT 0x0400 /* do fseek() optimisation */
99 #define __SNPT 0x0800 /* do not do fseek() optimisation */
100 #define __SOFF 0x1000 /* set iff _offset is in fact correct */
101 #define __SORD 0x2000 /* true => stream orientation (byte/wide) decided */
102 #if defined(__CYGWIN__)
103 # define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */
104 #endif
105 #define __SL64 0x8000 /* is 64-bit offset large file */
107 /* _flags2 flags */
108 #define __SNLK 0x0001 /* stdio functions do not lock streams themselves */
109 #define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
112 * The following three definitions are for ANSI C, which took them
113 * from System V, which stupidly took internal interface macros and
114 * made them official arguments to setvbuf(), without renaming them.
115 * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
117 * Although these happen to match their counterparts above, the
118 * implementation does not rely on that (so these could be renumbered).
120 #define _IOFBF 0 /* setvbuf should set fully buffered */
121 #define _IOLBF 1 /* setvbuf should set line buffered */
122 #define _IONBF 2 /* setvbuf should set unbuffered */
124 #define EOF (-1)
126 #ifdef __BUFSIZ__
127 #define BUFSIZ __BUFSIZ__
128 #else
129 #define BUFSIZ 1024
130 #endif
132 #ifdef __FOPEN_MAX__
133 #define FOPEN_MAX __FOPEN_MAX__
134 #else
135 #define FOPEN_MAX 20
136 #endif
138 #ifdef __FILENAME_MAX__
139 #define FILENAME_MAX __FILENAME_MAX__
140 #else
141 #define FILENAME_MAX 1024
142 #endif
144 #ifdef __L_tmpnam__
145 #define L_tmpnam __L_tmpnam__
146 #else
147 #define L_tmpnam FILENAME_MAX
148 #endif
150 #if __BSD_VISIBLE || __XSI_VISIBLE
151 #define P_tmpdir "/tmp"
152 #endif
154 #ifndef SEEK_SET
155 #define SEEK_SET 0 /* set file offset to offset */
156 #endif
157 #ifndef SEEK_CUR
158 #define SEEK_CUR 1 /* set file offset to current plus offset */
159 #endif
160 #ifndef SEEK_END
161 #define SEEK_END 2 /* set file offset to EOF plus offset */
162 #endif
164 #define TMP_MAX 26
166 #define stdin _REENT_STDIN(_REENT)
167 #define stdout _REENT_STDOUT(_REENT)
168 #define stderr _REENT_STDERR(_REENT)
170 #define _stdin_r(x) _REENT_STDIN(x)
171 #define _stdout_r(x) _REENT_STDOUT(x)
172 #define _stderr_r(x) _REENT_STDERR(x)
175 * Functions defined in ANSI C standard.
178 #ifndef __VALIST
179 #ifdef __GNUC__
180 #define __VALIST __gnuc_va_list
181 #else
182 #define __VALIST char*
183 #endif
184 #endif
186 #if __POSIX_VISIBLE
187 char * ctermid (char *);
188 #endif
189 #if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)
190 char * cuserid (char *);
191 #endif
192 FILE * tmpfile (void);
193 char * tmpnam (char *);
194 #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
195 char * tempnam (const char *, const char *) __malloc_like __result_use_check;
196 #endif
197 int fclose (FILE *);
198 int fflush (FILE *);
199 FILE * freopen (const char *__restrict, const char *__restrict, FILE *__restrict);
200 void setbuf (FILE *__restrict, char *__restrict);
201 int setvbuf (FILE *__restrict, char *__restrict, int, size_t);
202 int fprintf (FILE *__restrict, const char *__restrict, ...)
203 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
204 int fscanf (FILE *__restrict, const char *__restrict, ...)
205 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
206 int printf (const char *__restrict, ...)
207 _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
208 int scanf (const char *__restrict, ...)
209 _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
210 int sscanf (const char *__restrict, const char *__restrict, ...)
211 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
212 int vfprintf (FILE *__restrict, const char *__restrict, __VALIST)
213 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
214 int vprintf (const char *, __VALIST)
215 _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
216 int vsprintf (char *__restrict, const char *__restrict, __VALIST)
217 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
218 int fgetc (FILE *);
219 char * fgets (char *__restrict, int, FILE *__restrict);
220 int fputc (int, FILE *);
221 int fputs (const char *__restrict, FILE *__restrict);
222 int getc (FILE *);
223 int getchar (void);
224 char * gets (char *);
225 int putc (int, FILE *);
226 int putchar (int);
227 int puts (const char *);
228 int ungetc (int, FILE *);
229 size_t fread (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
230 size_t fwrite (const void *__restrict , size_t _size, size_t _n, FILE *);
231 #ifdef _LIBC
232 int fgetpos (FILE *, _fpos_t *);
233 #else
234 int fgetpos (FILE *__restrict, fpos_t *__restrict);
235 #endif
236 int fseek (FILE *, long, int);
237 #ifdef _LIBC
238 int fsetpos (FILE *, const _fpos_t *);
239 #else
240 int fsetpos (FILE *, const fpos_t *);
241 #endif
242 long ftell ( FILE *);
243 void rewind (FILE *);
244 void clearerr (FILE *);
245 int feof (FILE *);
246 int ferror (FILE *);
247 void perror (const char *);
248 #ifndef _REENT_ONLY
249 FILE * fopen (const char *__restrict _name, const char *__restrict _type);
250 int sprintf (char *__restrict, const char *__restrict, ...)
251 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
252 int remove (const char *);
253 int rename (const char *, const char *);
254 #ifdef _LIBC
255 int _rename (const char *, const char *);
256 #endif
257 #endif
258 #if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112
259 #ifdef _LIBC
260 int fseeko (FILE *, _off_t, int);
261 _off_t ftello (FILE *);
262 #else
263 int fseeko (FILE *, off_t, int);
264 off_t ftello (FILE *);
265 #endif
266 #endif
267 #if __GNU_VISIBLE
268 int fcloseall (void);
269 #endif
270 #ifndef _REENT_ONLY
271 #if __ISO_C_VISIBLE >= 1999
272 int snprintf (char *__restrict, size_t, const char *__restrict, ...)
273 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
274 int vsnprintf (char *__restrict, size_t, const char *__restrict, __VALIST)
275 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
276 int vfscanf (FILE *__restrict, const char *__restrict, __VALIST)
277 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
278 int vscanf (const char *, __VALIST)
279 _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
280 int vsscanf (const char *__restrict, const char *__restrict, __VALIST)
281 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
282 #endif
283 #if __GNU_VISIBLE
284 int asprintf (char **__restrict, const char *__restrict, ...)
285 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
286 int vasprintf (char **, const char *, __VALIST)
287 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
288 #endif
289 #if __MISC_VISIBLE /* Newlib-specific */
290 int asiprintf (char **, const char *, ...)
291 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
292 char * asniprintf (char *, size_t *, const char *, ...)
293 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
294 char * asnprintf (char *__restrict, size_t *__restrict, const char *__restrict, ...)
295 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
296 #ifndef diprintf
297 int diprintf (int, const char *, ...)
298 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
299 #endif
300 int fiprintf (FILE *, const char *, ...)
301 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
302 int fiscanf (FILE *, const char *, ...)
303 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
304 int iprintf (const char *, ...)
305 _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
306 int iscanf (const char *, ...)
307 _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
308 int siprintf (char *, const char *, ...)
309 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
310 int siscanf (const char *, const char *, ...)
311 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
312 int sniprintf (char *, size_t, const char *, ...)
313 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
314 int vasiprintf (char **, const char *, __VALIST)
315 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
316 char * vasniprintf (char *, size_t *, const char *, __VALIST)
317 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
318 char * vasnprintf (char *, size_t *, const char *, __VALIST)
319 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
320 int vdiprintf (int, const char *, __VALIST)
321 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
322 int vfiprintf (FILE *, const char *, __VALIST)
323 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
324 int vfiscanf (FILE *, const char *, __VALIST)
325 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
326 int viprintf (const char *, __VALIST)
327 _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
328 int viscanf (const char *, __VALIST)
329 _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
330 int vsiprintf (char *, const char *, __VALIST)
331 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
332 int vsiscanf (const char *, const char *, __VALIST)
333 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
334 int vsniprintf (char *, size_t, const char *, __VALIST)
335 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
336 #endif /* __MISC_VISIBLE */
337 #endif /* !_REENT_ONLY */
340 * Routines in POSIX 1003.1:2001.
343 #if __POSIX_VISIBLE
344 #ifndef _REENT_ONLY
345 FILE * fdopen (int, const char *);
346 #endif
347 int fileno (FILE *);
348 #endif
349 #if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209
350 int pclose (FILE *);
351 FILE * popen (const char *, const char *);
352 #endif
354 #if __BSD_VISIBLE
355 void setbuffer (FILE *, char *, int);
356 int setlinebuf (FILE *);
357 #endif
359 #if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
360 int getw (FILE *);
361 int putw (int, FILE *);
362 #endif
363 #if __MISC_VISIBLE || __POSIX_VISIBLE
364 int getc_unlocked (FILE *);
365 int getchar_unlocked (void);
366 void flockfile (FILE *);
367 int ftrylockfile (FILE *);
368 void funlockfile (FILE *);
369 int putc_unlocked (int, FILE *);
370 int putchar_unlocked (int);
371 #endif
374 * Routines in POSIX 1003.1:200x.
377 #if __POSIX_VISIBLE >= 200809
378 # ifndef _REENT_ONLY
379 # ifndef dprintf
380 int dprintf (int, const char *__restrict, ...)
381 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
382 # endif
383 FILE * fmemopen (void *__restrict, size_t, const char *__restrict);
384 /* getdelim - see __getdelim for now */
385 /* getline - see __getline for now */
386 FILE * open_memstream (char **, size_t *);
387 int vdprintf (int, const char *__restrict, __VALIST)
388 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
389 # endif
390 #endif
391 #if __ATFILE_VISIBLE
392 int renameat (int, const char *, int, const char *);
393 # ifdef __CYGWIN__
394 int renameat2 (int, const char *, int, const char *, unsigned int);
395 # endif
396 #endif
399 * Recursive versions of the above.
402 int _asiprintf_r (struct _reent *, char **, const char *, ...)
403 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
404 char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)
405 _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
406 char * _asnprintf_r (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)
407 _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
408 int _asprintf_r (struct _reent *, char **__restrict, const char *__restrict, ...)
409 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
410 int _diprintf_r (struct _reent *, int, const char *, ...)
411 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
412 int _dprintf_r (struct _reent *, int, const char *__restrict, ...)
413 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
414 int _fclose_r (struct _reent *, FILE *);
415 int _fcloseall_r (struct _reent *);
416 FILE * _fdopen_r (struct _reent *, int, const char *);
417 int _fflush_r (struct _reent *, FILE *);
418 int _fgetc_r (struct _reent *, FILE *);
419 int _fgetc_unlocked_r (struct _reent *, FILE *);
420 char * _fgets_r (struct _reent *, char *__restrict, int, FILE *__restrict);
421 char * _fgets_unlocked_r (struct _reent *, char *__restrict, int, FILE *__restrict);
422 #ifdef _LIBC
423 int _fgetpos_r (struct _reent *, FILE *__restrict, _fpos_t *__restrict);
424 int _fsetpos_r (struct _reent *, FILE *, const _fpos_t *);
425 #else
426 int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
427 int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
428 #endif
429 int _fiprintf_r (struct _reent *, FILE *, const char *, ...)
430 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
431 int _fiscanf_r (struct _reent *, FILE *, const char *, ...)
432 _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
433 FILE * _fmemopen_r (struct _reent *, void *__restrict, size_t, const char *__restrict);
434 FILE * _fopen_r (struct _reent *, const char *__restrict, const char *__restrict);
435 FILE * _freopen_r (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict);
436 int _fprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
437 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
438 int _fpurge_r (struct _reent *, FILE *);
439 int _fputc_r (struct _reent *, int, FILE *);
440 int _fputc_unlocked_r (struct _reent *, int, FILE *);
441 int _fputs_r (struct _reent *, const char *__restrict, FILE *__restrict);
442 int _fputs_unlocked_r (struct _reent *, const char *__restrict, FILE *__restrict);
443 size_t _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
444 size_t _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
445 int _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
446 _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
447 int _fseek_r (struct _reent *, FILE *, long, int);
448 int _fseeko_r (struct _reent *, FILE *, _off_t, int);
449 long _ftell_r (struct _reent *, FILE *);
450 _off_t _ftello_r (struct _reent *, FILE *);
451 void _rewind_r (struct _reent *, FILE *);
452 size_t _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
453 size_t _fwrite_unlocked_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
454 int _getc_r (struct _reent *, FILE *);
455 int _getc_unlocked_r (struct _reent *, FILE *);
456 int _getchar_r (struct _reent *);
457 int _getchar_unlocked_r (struct _reent *);
458 char * _gets_r (struct _reent *, char *);
459 int _iprintf_r (struct _reent *, const char *, ...)
460 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
461 int _iscanf_r (struct _reent *, const char *, ...)
462 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
463 FILE * _open_memstream_r (struct _reent *, char **, size_t *);
464 void _perror_r (struct _reent *, const char *);
465 int _printf_r (struct _reent *, const char *__restrict, ...)
466 _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
467 int _putc_r (struct _reent *, int, FILE *);
468 int _putc_unlocked_r (struct _reent *, int, FILE *);
469 int _putchar_unlocked_r (struct _reent *, int);
470 int _putchar_r (struct _reent *, int);
471 int _puts_r (struct _reent *, const char *);
472 int _remove_r (struct _reent *, const char *);
473 int _rename_r (struct _reent *,
474 const char *_old, const char *_new);
475 int _scanf_r (struct _reent *, const char *__restrict, ...)
476 _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
477 int _siprintf_r (struct _reent *, char *, const char *, ...)
478 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
479 int _siscanf_r (struct _reent *, const char *, const char *, ...)
480 _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
481 int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)
482 _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
483 int _snprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)
484 _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
485 int _sprintf_r (struct _reent *, char *__restrict, const char *__restrict, ...)
486 _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
487 int _sscanf_r (struct _reent *, const char *__restrict, const char *__restrict, ...)
488 _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
489 char * _tempnam_r (struct _reent *, const char *, const char *);
490 FILE * _tmpfile_r (struct _reent *);
491 char * _tmpnam_r (struct _reent *, char *);
492 int _ungetc_r (struct _reent *, int, FILE *);
493 int _vasiprintf_r (struct _reent *, char **, const char *, __VALIST)
494 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
495 char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
496 _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
497 char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
498 _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
499 int _vasprintf_r (struct _reent *, char **, const char *, __VALIST)
500 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
501 int _vdiprintf_r (struct _reent *, int, const char *, __VALIST)
502 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
503 int _vdprintf_r (struct _reent *, int, const char *__restrict, __VALIST)
504 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
505 int _vfiprintf_r (struct _reent *, FILE *, const char *, __VALIST)
506 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
507 int _vfiscanf_r (struct _reent *, FILE *, const char *, __VALIST)
508 _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
509 int _vfprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
510 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
511 int _vfscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
512 _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
513 int _viprintf_r (struct _reent *, const char *, __VALIST)
514 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
515 int _viscanf_r (struct _reent *, const char *, __VALIST)
516 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
517 int _vprintf_r (struct _reent *, const char *__restrict, __VALIST)
518 _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
519 int _vscanf_r (struct _reent *, const char *__restrict, __VALIST)
520 _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
521 int _vsiprintf_r (struct _reent *, char *, const char *, __VALIST)
522 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
523 int _vsiscanf_r (struct _reent *, const char *, const char *, __VALIST)
524 _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
525 int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __VALIST)
526 _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
527 int _vsnprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)
528 _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
529 int _vsprintf_r (struct _reent *, char *__restrict, const char *__restrict, __VALIST)
530 _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
531 int _vsscanf_r (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)
532 _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
534 /* Other extensions. */
536 int fpurge (FILE *);
537 ssize_t __getdelim (char **, size_t *, int, FILE *);
538 ssize_t __getline (char **, size_t *, FILE *);
540 #if __MISC_VISIBLE
541 void clearerr_unlocked (FILE *);
542 int feof_unlocked (FILE *);
543 int ferror_unlocked (FILE *);
544 int fileno_unlocked (FILE *);
545 int fflush_unlocked (FILE *);
546 int fgetc_unlocked (FILE *);
547 int fputc_unlocked (int, FILE *);
548 size_t fread_unlocked (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
549 size_t fwrite_unlocked (const void *__restrict , size_t _size, size_t _n, FILE *);
550 #endif
552 #if __GNU_VISIBLE
553 char * fgets_unlocked (char *__restrict, int, FILE *__restrict);
554 int fputs_unlocked (const char *__restrict, FILE *__restrict);
555 #endif
557 #ifdef __LARGE64_FILES
558 #if !defined(__CYGWIN__) || defined(_LIBC)
559 FILE * fdopen64 (int, const char *);
560 FILE * fopen64 (const char *, const char *);
561 FILE * freopen64 (const char *, const char *, FILE *);
562 _off64_t ftello64 (FILE *);
563 _off64_t fseeko64 (FILE *, _off64_t, int);
564 int fgetpos64 (FILE *, _fpos64_t *);
565 int fsetpos64 (FILE *, const _fpos64_t *);
566 FILE * tmpfile64 (void);
568 FILE * _fdopen64_r (struct _reent *, int, const char *);
569 FILE * _fopen64_r (struct _reent *,const char *, const char *);
570 FILE * _freopen64_r (struct _reent *, const char *, const char *, FILE *);
571 _off64_t _ftello64_r (struct _reent *, FILE *);
572 _off64_t _fseeko64_r (struct _reent *, FILE *, _off64_t, int);
573 int _fgetpos64_r (struct _reent *, FILE *, _fpos64_t *);
574 int _fsetpos64_r (struct _reent *, FILE *, const _fpos64_t *);
575 FILE * _tmpfile64_r (struct _reent *);
576 #endif /* !__CYGWIN__ */
577 #endif /* __LARGE64_FILES */
580 * Routines internal to the implementation.
583 int __srget_r (struct _reent *, FILE *);
584 int __swbuf_r (struct _reent *, int, FILE *);
587 * Stdio function-access interface.
590 #if __BSD_VISIBLE
591 # ifdef __LARGE64_FILES
592 FILE *funopen (const void *__cookie,
593 int (*__readfn)(void *__c, char *__buf,
594 _READ_WRITE_BUFSIZE_TYPE __n),
595 int (*__writefn)(void *__c, const char *__buf,
596 _READ_WRITE_BUFSIZE_TYPE __n),
597 _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
598 int (*__closefn)(void *__c));
599 FILE *_funopen_r (struct _reent *, const void *__cookie,
600 int (*__readfn)(void *__c, char *__buf,
601 _READ_WRITE_BUFSIZE_TYPE __n),
602 int (*__writefn)(void *__c, const char *__buf,
603 _READ_WRITE_BUFSIZE_TYPE __n),
604 _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
605 int (*__closefn)(void *__c));
606 # else
607 FILE *funopen (const void *__cookie,
608 int (*__readfn)(void *__cookie, char *__buf,
609 _READ_WRITE_BUFSIZE_TYPE __n),
610 int (*__writefn)(void *__cookie, const char *__buf,
611 _READ_WRITE_BUFSIZE_TYPE __n),
612 fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
613 int (*__closefn)(void *__cookie));
614 FILE *_funopen_r (struct _reent *, const void *__cookie,
615 int (*__readfn)(void *__cookie, char *__buf,
616 _READ_WRITE_BUFSIZE_TYPE __n),
617 int (*__writefn)(void *__cookie, const char *__buf,
618 _READ_WRITE_BUFSIZE_TYPE __n),
619 fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
620 int (*__closefn)(void *__cookie));
621 # endif /* !__LARGE64_FILES */
623 # define fropen(__cookie, __fn) funopen(__cookie, __fn, NULL, NULL, NULL)
624 # define fwopen(__cookie, __fn) funopen(__cookie, NULL, __fn, NULL, NULL)
625 #endif /* __BSD_VISIBLE */
627 #if __GNU_VISIBLE
628 typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
629 typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
630 size_t __n);
631 # ifdef __LARGE64_FILES
632 typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
633 int __whence);
634 # else
635 typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
636 # endif /* !__LARGE64_FILES */
637 typedef int cookie_close_function_t(void *__cookie);
638 typedef struct
640 /* These four struct member names are dictated by Linux; hopefully,
641 they don't conflict with any macros. */
642 cookie_read_function_t *read;
643 cookie_write_function_t *write;
644 cookie_seek_function_t *seek;
645 cookie_close_function_t *close;
646 } cookie_io_functions_t;
647 FILE *fopencookie (void *__cookie,
648 const char *__mode, cookie_io_functions_t __functions);
649 FILE *_fopencookie_r (struct _reent *, void *__cookie,
650 const char *__mode, cookie_io_functions_t __functions);
651 #endif /* __GNU_VISIBLE */
653 #ifndef __CUSTOM_FILE_IO__
655 * The __sfoo macros are here so that we can
656 * define function versions in the C library.
658 #define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
660 #ifdef __SCLE
661 /* For a platform with CR/LF, additional logic is required by
662 __sgetc_r which would otherwise simply be a macro; therefore we
663 use an inlined function. The function is only meant to be inlined
664 in place as used and the function body should never be emitted.
666 There are two possible means to this end when compiling with GCC,
667 one when compiling with a standard C99 compiler, and for other
668 compilers we're just stuck. At the moment, this issue only
669 affects the Cygwin target, so we'll most likely be using GCC. */
671 _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
673 _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
675 int __c = __sgetc_raw_r(__ptr, __p);
676 if ((__p->_flags & __SCLE) && (__c == '\r'))
678 int __c2 = __sgetc_raw_r(__ptr, __p);
679 if (__c2 == '\n')
680 __c = __c2;
681 else
682 ungetc(__c2, __p);
684 return __c;
686 #else
687 #define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
688 #endif
690 #ifdef __GNUC__
691 _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
692 #ifdef __SCLE
693 if ((_p->_flags & __SCLE) && _c == '\n')
694 __sputc_r (_ptr, '\r', _p);
695 #endif
696 if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
697 return (*_p->_p++ = _c);
698 else
699 return (__swbuf_r(_ptr, _c, _p));
701 #else
703 * This has been tuned to generate reasonable code on the vax using pcc
705 #define __sputc_raw_r(__ptr, __c, __p) \
706 (--(__p)->_w < 0 ? \
707 (__p)->_w >= (__p)->_lbfsize ? \
708 (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
709 (int)*(__p)->_p++ : \
710 __swbuf_r(__ptr, '\n', __p) : \
711 __swbuf_r(__ptr, (int)(__c), __p) : \
712 (*(__p)->_p = (__c), (int)*(__p)->_p++))
713 #ifdef __SCLE
714 #define __sputc_r(__ptr, __c, __p) \
715 ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
716 ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
717 __sputc_raw_r((__ptr), (__c), (__p)))
718 #else
719 #define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
720 #endif
721 #endif
723 #define __sfeof(p) ((int)(((p)->_flags & __SEOF) != 0))
724 #define __sferror(p) ((int)(((p)->_flags & __SERR) != 0))
725 #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
726 #define __sfileno(p) ((p)->_file)
728 #ifndef __cplusplus
729 #ifndef _REENT_SMALL
730 #define feof(p) __sfeof(p)
731 #define ferror(p) __sferror(p)
732 #define clearerr(p) __sclearerr(p)
734 #if __MISC_VISIBLE
735 #define feof_unlocked(p) __sfeof(p)
736 #define ferror_unlocked(p) __sferror(p)
737 #define clearerr_unlocked(p) __sclearerr(p)
738 #endif /* __MISC_VISIBLE */
739 #endif /* _REENT_SMALL */
741 #if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */
742 #define fileno(p) __sfileno(p)
743 #endif
745 static __inline int
746 _getchar_unlocked(void)
748 struct _reent *_ptr;
750 _ptr = _REENT;
751 return (__sgetc_r(_ptr, _stdin_r(_ptr)));
754 static __inline int
755 _putchar_unlocked(int _c)
757 struct _reent *_ptr;
759 _ptr = _REENT;
760 return (__sputc_r(_ptr, _c, _stdout_r(_ptr)));
763 #ifdef __SINGLE_THREAD__
764 #define getc(_p) __sgetc_r(_REENT, _p)
765 #define putc(_c, _p) __sputc_r(_REENT, _c, _p)
766 #define getchar() _getchar_unlocked()
767 #define putchar(_c) _putchar_unlocked(_c)
768 #endif /* __SINGLE_THREAD__ */
770 #if __MISC_VISIBLE || __POSIX_VISIBLE
771 #define getchar_unlocked() _getchar_unlocked()
772 #define putchar_unlocked(_c) _putchar_unlocked(_c)
773 #endif
774 #endif /* __cplusplus */
776 #if __MISC_VISIBLE
777 /* fast always-buffered version, true iff error */
778 #define fast_putc(x,p) (--(p)->_w < 0 ? \
779 __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
780 #endif
782 #if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)
783 #define L_cuserid 9 /* posix says it goes in stdio.h :( */
784 #endif
785 #if __POSIX_VISIBLE
786 #define L_ctermid 16
787 #endif
789 #else /* __CUSTOM_FILE_IO__ */
791 #define getchar() getc(stdin)
792 #define putchar(x) putc(x, stdout)
794 #if __MISC_VISIBLE || __POSIX_VISIBLE
795 #define getchar_unlocked() getc_unlocked(stdin)
796 #define putchar_unlocked(x) putc_unlocked(x, stdout)
797 #endif
799 #endif /* !__CUSTOM_FILE_IO__ */
801 _END_STD_C
803 #if __SSP_FORTIFY_LEVEL > 0
804 #include <ssp/stdio.h>
805 #endif
807 #endif /* _STDIO_H_ */