Further harden glibc malloc metadata against 1-byte overflows.
[glibc.git] / libio / stdio.h
blob3e01d54eb28dd07c7e0ed928c13bc67f72fb6389
1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2017 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <http://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.19 Input/output <stdio.h>
23 #ifndef _STDIO_H
25 #if !defined __need_FILE && !defined __need___FILE
26 # define _STDIO_H 1
27 # define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
28 # include <bits/libc-header-start.h>
30 __BEGIN_DECLS
32 # define __need_size_t
33 # define __need_NULL
34 # include <stddef.h>
36 # include <bits/types.h>
37 # define __need_FILE
38 # define __need___FILE
39 #endif /* Don't need FILE. */
42 #if !defined __FILE_defined && defined __need_FILE
44 /* Define outside of namespace so the C++ is happy. */
45 struct _IO_FILE;
47 /* The opaque type of streams. This is the definition used elsewhere. */
48 typedef struct _IO_FILE FILE;
50 # define __FILE_defined 1
51 #endif /* FILE not defined. */
52 #undef __need_FILE
55 #if !defined ____FILE_defined && defined __need___FILE
57 /* The opaque type of streams. This is the definition used elsewhere. */
58 typedef struct _IO_FILE __FILE;
60 # define ____FILE_defined 1
61 #endif /* __FILE not defined. */
62 #undef __need___FILE
65 #ifdef _STDIO_H
66 #define _STDIO_USES_IOSTREAM
68 #include <libio.h>
70 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
71 # ifdef __GNUC__
72 # ifndef _VA_LIST_DEFINED
73 typedef _G_va_list va_list;
74 # define _VA_LIST_DEFINED
75 # endif
76 # else
77 # include <stdarg.h>
78 # endif
79 #endif
81 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
82 # ifndef __off_t_defined
83 # ifndef __USE_FILE_OFFSET64
84 typedef __off_t off_t;
85 # else
86 typedef __off64_t off_t;
87 # endif
88 # define __off_t_defined
89 # endif
90 # if defined __USE_LARGEFILE64 && !defined __off64_t_defined
91 typedef __off64_t off64_t;
92 # define __off64_t_defined
93 # endif
94 #endif
96 #ifdef __USE_XOPEN2K8
97 # ifndef __ssize_t_defined
98 typedef __ssize_t ssize_t;
99 # define __ssize_t_defined
100 # endif
101 #endif
103 /* The type of the second argument to `fgetpos' and `fsetpos'. */
104 #ifndef __USE_FILE_OFFSET64
105 typedef _G_fpos_t fpos_t;
106 #else
107 typedef _G_fpos64_t fpos_t;
108 #endif
109 #ifdef __USE_LARGEFILE64
110 typedef _G_fpos64_t fpos64_t;
111 #endif
113 /* The possibilities for the third argument to `setvbuf'. */
114 #define _IOFBF 0 /* Fully buffered. */
115 #define _IOLBF 1 /* Line buffered. */
116 #define _IONBF 2 /* No buffering. */
119 /* Default buffer size. */
120 #ifndef BUFSIZ
121 # define BUFSIZ _IO_BUFSIZ
122 #endif
125 /* End of file character.
126 Some things throughout the library rely on this being -1. */
127 #ifndef EOF
128 # define EOF (-1)
129 #endif
132 /* The possibilities for the third argument to `fseek'.
133 These values should not be changed. */
134 #define SEEK_SET 0 /* Seek from beginning of file. */
135 #define SEEK_CUR 1 /* Seek from current position. */
136 #define SEEK_END 2 /* Seek from end of file. */
137 #ifdef __USE_GNU
138 # define SEEK_DATA 3 /* Seek to next data. */
139 # define SEEK_HOLE 4 /* Seek to next hole. */
140 #endif
143 #if defined __USE_MISC || defined __USE_XOPEN
144 /* Default path prefix for `tempnam' and `tmpnam'. */
145 # define P_tmpdir "/tmp"
146 #endif
149 /* Get the values:
150 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
151 TMP_MAX The minimum number of unique filenames generated by tmpnam
152 (and tempnam when it uses tmpnam's name space),
153 or tempnam (the two are separate).
154 L_ctermid How long an array to pass to `ctermid'.
155 L_cuserid How long an array to pass to `cuserid'.
156 FOPEN_MAX Minimum number of files that can be open at once.
157 FILENAME_MAX Maximum length of a filename. */
158 #include <bits/stdio_lim.h>
161 /* Standard streams. */
162 extern struct _IO_FILE *stdin; /* Standard input stream. */
163 extern struct _IO_FILE *stdout; /* Standard output stream. */
164 extern struct _IO_FILE *stderr; /* Standard error output stream. */
165 /* C89/C99 say they're macros. Make them happy. */
166 #define stdin stdin
167 #define stdout stdout
168 #define stderr stderr
170 /* Remove file FILENAME. */
171 extern int remove (const char *__filename) __THROW;
172 /* Rename file OLD to NEW. */
173 extern int rename (const char *__old, const char *__new) __THROW;
175 #ifdef __USE_ATFILE
176 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
177 extern int renameat (int __oldfd, const char *__old, int __newfd,
178 const char *__new) __THROW;
179 #endif
181 /* Create a temporary file and open it read/write.
183 This function is a possible cancellation point and therefore not
184 marked with __THROW. */
185 #ifndef __USE_FILE_OFFSET64
186 extern FILE *tmpfile (void) __wur;
187 #else
188 # ifdef __REDIRECT
189 extern FILE *__REDIRECT (tmpfile, (void), tmpfile64) __wur;
190 # else
191 # define tmpfile tmpfile64
192 # endif
193 #endif
195 #ifdef __USE_LARGEFILE64
196 extern FILE *tmpfile64 (void) __wur;
197 #endif
199 /* Generate a temporary filename. */
200 extern char *tmpnam (char *__s) __THROW __wur;
202 #ifdef __USE_MISC
203 /* This is the reentrant variant of `tmpnam'. The only difference is
204 that it does not allow S to be NULL. */
205 extern char *tmpnam_r (char *__s) __THROW __wur;
206 #endif
209 #if defined __USE_MISC || defined __USE_XOPEN
210 /* Generate a unique temporary filename using up to five characters of PFX
211 if it is not NULL. The directory to put this file in is searched for
212 as follows: First the environment variable "TMPDIR" is checked.
213 If it contains the name of a writable directory, that directory is used.
214 If not and if DIR is not NULL, that value is checked. If that fails,
215 P_tmpdir is tried and finally "/tmp". The storage for the filename
216 is allocated by `malloc'. */
217 extern char *tempnam (const char *__dir, const char *__pfx)
218 __THROW __attribute_malloc__ __wur;
219 #endif
222 /* Close STREAM.
224 This function is a possible cancellation point and therefore not
225 marked with __THROW. */
226 extern int fclose (FILE *__stream);
227 /* Flush STREAM, or all streams if STREAM is NULL.
229 This function is a possible cancellation point and therefore not
230 marked with __THROW. */
231 extern int fflush (FILE *__stream);
233 #ifdef __USE_MISC
234 /* Faster versions when locking is not required.
236 This function is not part of POSIX and therefore no official
237 cancellation point. But due to similarity with an POSIX interface
238 or due to the implementation it is a cancellation point and
239 therefore not marked with __THROW. */
240 extern int fflush_unlocked (FILE *__stream);
241 #endif
243 #ifdef __USE_GNU
244 /* Close all streams.
246 This function is not part of POSIX and therefore no official
247 cancellation point. But due to similarity with an POSIX interface
248 or due to the implementation it is a cancellation point and
249 therefore not marked with __THROW. */
250 extern int fcloseall (void);
251 #endif
254 #ifndef __USE_FILE_OFFSET64
255 /* Open a file and create a new stream for it.
257 This function is a possible cancellation point and therefore not
258 marked with __THROW. */
259 extern FILE *fopen (const char *__restrict __filename,
260 const char *__restrict __modes) __wur;
261 /* Open a file, replacing an existing stream with it.
263 This function is a possible cancellation point and therefore not
264 marked with __THROW. */
265 extern FILE *freopen (const char *__restrict __filename,
266 const char *__restrict __modes,
267 FILE *__restrict __stream) __wur;
268 #else
269 # ifdef __REDIRECT
270 extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
271 const char *__restrict __modes), fopen64)
272 __wur;
273 extern FILE *__REDIRECT (freopen, (const char *__restrict __filename,
274 const char *__restrict __modes,
275 FILE *__restrict __stream), freopen64)
276 __wur;
277 # else
278 # define fopen fopen64
279 # define freopen freopen64
280 # endif
281 #endif
282 #ifdef __USE_LARGEFILE64
283 extern FILE *fopen64 (const char *__restrict __filename,
284 const char *__restrict __modes) __wur;
285 extern FILE *freopen64 (const char *__restrict __filename,
286 const char *__restrict __modes,
287 FILE *__restrict __stream) __wur;
288 #endif
290 #ifdef __USE_POSIX
291 /* Create a new stream that refers to an existing system file descriptor. */
292 extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
293 #endif
295 #ifdef __USE_GNU
296 /* Create a new stream that refers to the given magic cookie,
297 and uses the given functions for input and output. */
298 extern FILE *fopencookie (void *__restrict __magic_cookie,
299 const char *__restrict __modes,
300 _IO_cookie_io_functions_t __io_funcs) __THROW __wur;
301 #endif
303 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
304 /* Create a new stream that refers to a memory buffer. */
305 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
306 __THROW __wur;
308 /* Open a stream that writes into a malloc'd buffer that is expanded as
309 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
310 and the number of characters written on fflush or fclose. */
311 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
312 #endif
315 /* If BUF is NULL, make STREAM unbuffered.
316 Else make it use buffer BUF, of size BUFSIZ. */
317 extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
318 /* Make STREAM use buffering mode MODE.
319 If BUF is not NULL, use N bytes of it for buffering;
320 else allocate an internal buffer N bytes long. */
321 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
322 int __modes, size_t __n) __THROW;
324 #ifdef __USE_MISC
325 /* If BUF is NULL, make STREAM unbuffered.
326 Else make it use SIZE bytes of BUF for buffering. */
327 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
328 size_t __size) __THROW;
330 /* Make STREAM line-buffered. */
331 extern void setlinebuf (FILE *__stream) __THROW;
332 #endif
335 /* Write formatted output to STREAM.
337 This function is a possible cancellation point and therefore not
338 marked with __THROW. */
339 extern int fprintf (FILE *__restrict __stream,
340 const char *__restrict __format, ...);
341 /* Write formatted output to stdout.
343 This function is a possible cancellation point and therefore not
344 marked with __THROW. */
345 extern int printf (const char *__restrict __format, ...);
346 /* Write formatted output to S. */
347 extern int sprintf (char *__restrict __s,
348 const char *__restrict __format, ...) __THROWNL;
350 /* Write formatted output to S from argument list ARG.
352 This function is a possible cancellation point and therefore not
353 marked with __THROW. */
354 extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
355 _G_va_list __arg);
356 /* Write formatted output to stdout from argument list ARG.
358 This function is a possible cancellation point and therefore not
359 marked with __THROW. */
360 extern int vprintf (const char *__restrict __format, _G_va_list __arg);
361 /* Write formatted output to S from argument list ARG. */
362 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
363 _G_va_list __arg) __THROWNL;
365 #if defined __USE_ISOC99 || defined __USE_UNIX98
366 /* Maximum chars of output to write in MAXLEN. */
367 extern int snprintf (char *__restrict __s, size_t __maxlen,
368 const char *__restrict __format, ...)
369 __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
371 extern int vsnprintf (char *__restrict __s, size_t __maxlen,
372 const char *__restrict __format, _G_va_list __arg)
373 __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
374 #endif
376 #if __GLIBC_USE (LIB_EXT2)
377 /* Write formatted output to a string dynamically allocated with `malloc'.
378 Store the address of the string in *PTR. */
379 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
380 _G_va_list __arg)
381 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
382 extern int __asprintf (char **__restrict __ptr,
383 const char *__restrict __fmt, ...)
384 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
385 extern int asprintf (char **__restrict __ptr,
386 const char *__restrict __fmt, ...)
387 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
388 #endif
390 #ifdef __USE_XOPEN2K8
391 /* Write formatted output to a file descriptor. */
392 extern int vdprintf (int __fd, const char *__restrict __fmt,
393 _G_va_list __arg)
394 __attribute__ ((__format__ (__printf__, 2, 0)));
395 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
396 __attribute__ ((__format__ (__printf__, 2, 3)));
397 #endif
400 /* Read formatted input from STREAM.
402 This function is a possible cancellation point and therefore not
403 marked with __THROW. */
404 extern int fscanf (FILE *__restrict __stream,
405 const char *__restrict __format, ...) __wur;
406 /* Read formatted input from stdin.
408 This function is a possible cancellation point and therefore not
409 marked with __THROW. */
410 extern int scanf (const char *__restrict __format, ...) __wur;
411 /* Read formatted input from S. */
412 extern int sscanf (const char *__restrict __s,
413 const char *__restrict __format, ...) __THROW;
415 #if defined __USE_ISOC99 && !defined __USE_GNU \
416 && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
417 && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
418 # ifdef __REDIRECT
419 /* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[
420 GNU extension which conflicts with valid %a followed by letter
421 s, S or [. */
422 extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
423 const char *__restrict __format, ...),
424 __isoc99_fscanf) __wur;
425 extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
426 __isoc99_scanf) __wur;
427 extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
428 const char *__restrict __format, ...),
429 __isoc99_sscanf);
430 # else
431 extern int __isoc99_fscanf (FILE *__restrict __stream,
432 const char *__restrict __format, ...) __wur;
433 extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
434 extern int __isoc99_sscanf (const char *__restrict __s,
435 const char *__restrict __format, ...) __THROW;
436 # define fscanf __isoc99_fscanf
437 # define scanf __isoc99_scanf
438 # define sscanf __isoc99_sscanf
439 # endif
440 #endif
442 #ifdef __USE_ISOC99
443 /* Read formatted input from S into argument list ARG.
445 This function is a possible cancellation point and therefore not
446 marked with __THROW. */
447 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
448 _G_va_list __arg)
449 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
451 /* Read formatted input from stdin into argument list ARG.
453 This function is a possible cancellation point and therefore not
454 marked with __THROW. */
455 extern int vscanf (const char *__restrict __format, _G_va_list __arg)
456 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
458 /* Read formatted input from S into argument list ARG. */
459 extern int vsscanf (const char *__restrict __s,
460 const char *__restrict __format, _G_va_list __arg)
461 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
463 # if !defined __USE_GNU \
464 && (!defined __LDBL_COMPAT || !defined __REDIRECT) \
465 && (defined __STRICT_ANSI__ || defined __USE_XOPEN2K)
466 # ifdef __REDIRECT
467 /* For strict ISO C99 or POSIX compliance disallow %as, %aS and %a[
468 GNU extension which conflicts with valid %a followed by letter
469 s, S or [. */
470 extern int __REDIRECT (vfscanf,
471 (FILE *__restrict __s,
472 const char *__restrict __format, _G_va_list __arg),
473 __isoc99_vfscanf)
474 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
475 extern int __REDIRECT (vscanf, (const char *__restrict __format,
476 _G_va_list __arg), __isoc99_vscanf)
477 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
478 extern int __REDIRECT_NTH (vsscanf,
479 (const char *__restrict __s,
480 const char *__restrict __format,
481 _G_va_list __arg), __isoc99_vsscanf)
482 __attribute__ ((__format__ (__scanf__, 2, 0)));
483 # else
484 extern int __isoc99_vfscanf (FILE *__restrict __s,
485 const char *__restrict __format,
486 _G_va_list __arg) __wur;
487 extern int __isoc99_vscanf (const char *__restrict __format,
488 _G_va_list __arg) __wur;
489 extern int __isoc99_vsscanf (const char *__restrict __s,
490 const char *__restrict __format,
491 _G_va_list __arg) __THROW;
492 # define vfscanf __isoc99_vfscanf
493 # define vscanf __isoc99_vscanf
494 # define vsscanf __isoc99_vsscanf
495 # endif
496 # endif
497 #endif /* Use ISO C9x. */
500 /* Read a character from STREAM.
502 These functions are possible cancellation points and therefore not
503 marked with __THROW. */
504 extern int fgetc (FILE *__stream);
505 extern int getc (FILE *__stream);
507 /* Read a character from stdin.
509 This function is a possible cancellation point and therefore not
510 marked with __THROW. */
511 extern int getchar (void);
513 /* The C standard explicitly says this is a macro, so we always do the
514 optimization for it. */
515 #define getc(_fp) _IO_getc (_fp)
517 #ifdef __USE_POSIX199506
518 /* These are defined in POSIX.1:1996.
520 These functions are possible cancellation points and therefore not
521 marked with __THROW. */
522 extern int getc_unlocked (FILE *__stream);
523 extern int getchar_unlocked (void);
524 #endif /* Use POSIX. */
526 #ifdef __USE_MISC
527 /* Faster version when locking is not necessary.
529 This function is not part of POSIX and therefore no official
530 cancellation point. But due to similarity with an POSIX interface
531 or due to the implementation it is a cancellation point and
532 therefore not marked with __THROW. */
533 extern int fgetc_unlocked (FILE *__stream);
534 #endif /* Use MISC. */
537 /* Write a character to STREAM.
539 These functions are possible cancellation points and therefore not
540 marked with __THROW.
542 These functions is a possible cancellation point and therefore not
543 marked with __THROW. */
544 extern int fputc (int __c, FILE *__stream);
545 extern int putc (int __c, FILE *__stream);
547 /* Write a character to stdout.
549 This function is a possible cancellation point and therefore not
550 marked with __THROW. */
551 extern int putchar (int __c);
553 /* The C standard explicitly says this can be a macro,
554 so we always do the optimization for it. */
555 #define putc(_ch, _fp) _IO_putc (_ch, _fp)
557 #ifdef __USE_MISC
558 /* Faster version when locking is not necessary.
560 This function is not part of POSIX and therefore no official
561 cancellation point. But due to similarity with an POSIX interface
562 or due to the implementation it is a cancellation point and
563 therefore not marked with __THROW. */
564 extern int fputc_unlocked (int __c, FILE *__stream);
565 #endif /* Use MISC. */
567 #ifdef __USE_POSIX199506
568 /* These are defined in POSIX.1:1996.
570 These functions are possible cancellation points and therefore not
571 marked with __THROW. */
572 extern int putc_unlocked (int __c, FILE *__stream);
573 extern int putchar_unlocked (int __c);
574 #endif /* Use POSIX. */
577 #if defined __USE_MISC \
578 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
579 /* Get a word (int) from STREAM. */
580 extern int getw (FILE *__stream);
582 /* Write a word (int) to STREAM. */
583 extern int putw (int __w, FILE *__stream);
584 #endif
587 /* Get a newline-terminated string of finite length from STREAM.
589 This function is a possible cancellation point and therefore not
590 marked with __THROW. */
591 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
592 __wur;
594 #if __GLIBC_USE (DEPRECATED_GETS)
595 /* Get a newline-terminated string from stdin, removing the newline.
597 This function is impossible to use safely. It has been officially
598 removed from ISO C11 and ISO C++14, and we have also removed it
599 from the _GNU_SOURCE feature list. It remains available when
600 explicitly using an old ISO C, Unix, or POSIX standard.
602 This function is a possible cancellation point and therefore not
603 marked with __THROW. */
604 extern char *gets (char *__s) __wur __attribute_deprecated__;
605 #endif
607 #ifdef __USE_GNU
608 /* This function does the same as `fgets' but does not lock the stream.
610 This function is not part of POSIX and therefore no official
611 cancellation point. But due to similarity with an POSIX interface
612 or due to the implementation it is a cancellation point and
613 therefore not marked with __THROW. */
614 extern char *fgets_unlocked (char *__restrict __s, int __n,
615 FILE *__restrict __stream) __wur;
616 #endif
619 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
620 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
621 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
622 NULL), pointing to *N characters of space. It is realloc'd as
623 necessary. Returns the number of characters read (not including the
624 null terminator), or -1 on error or EOF.
626 These functions are not part of POSIX and therefore no official
627 cancellation point. But due to similarity with an POSIX interface
628 or due to the implementation they are cancellation points and
629 therefore not marked with __THROW. */
630 extern _IO_ssize_t __getdelim (char **__restrict __lineptr,
631 size_t *__restrict __n, int __delimiter,
632 FILE *__restrict __stream) __wur;
633 extern _IO_ssize_t getdelim (char **__restrict __lineptr,
634 size_t *__restrict __n, int __delimiter,
635 FILE *__restrict __stream) __wur;
637 /* Like `getdelim', but reads up to a newline.
639 This function is not part of POSIX and therefore no official
640 cancellation point. But due to similarity with an POSIX interface
641 or due to the implementation it is a cancellation point and
642 therefore not marked with __THROW. */
643 extern _IO_ssize_t getline (char **__restrict __lineptr,
644 size_t *__restrict __n,
645 FILE *__restrict __stream) __wur;
646 #endif
649 /* Write a string to STREAM.
651 This function is a possible cancellation point and therefore not
652 marked with __THROW. */
653 extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
655 /* Write a string, followed by a newline, to stdout.
657 This function is a possible cancellation point and therefore not
658 marked with __THROW. */
659 extern int puts (const char *__s);
662 /* Push a character back onto the input buffer of STREAM.
664 This function is a possible cancellation point and therefore not
665 marked with __THROW. */
666 extern int ungetc (int __c, FILE *__stream);
669 /* Read chunks of generic data from STREAM.
671 This function is a possible cancellation point and therefore not
672 marked with __THROW. */
673 extern size_t fread (void *__restrict __ptr, size_t __size,
674 size_t __n, FILE *__restrict __stream) __wur;
675 /* Write chunks of generic data to STREAM.
677 This function is a possible cancellation point and therefore not
678 marked with __THROW. */
679 extern size_t fwrite (const void *__restrict __ptr, size_t __size,
680 size_t __n, FILE *__restrict __s);
682 #ifdef __USE_GNU
683 /* This function does the same as `fputs' but does not lock the stream.
685 This function is not part of POSIX and therefore no official
686 cancellation point. But due to similarity with an POSIX interface
687 or due to the implementation it is a cancellation point and
688 therefore not marked with __THROW. */
689 extern int fputs_unlocked (const char *__restrict __s,
690 FILE *__restrict __stream);
691 #endif
693 #ifdef __USE_MISC
694 /* Faster versions when locking is not necessary.
696 These functions are not part of POSIX and therefore no official
697 cancellation point. But due to similarity with an POSIX interface
698 or due to the implementation they are cancellation points and
699 therefore not marked with __THROW. */
700 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
701 size_t __n, FILE *__restrict __stream) __wur;
702 extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
703 size_t __n, FILE *__restrict __stream);
704 #endif
707 /* Seek to a certain position on STREAM.
709 This function is a possible cancellation point and therefore not
710 marked with __THROW. */
711 extern int fseek (FILE *__stream, long int __off, int __whence);
712 /* Return the current position of STREAM.
714 This function is a possible cancellation point and therefore not
715 marked with __THROW. */
716 extern long int ftell (FILE *__stream) __wur;
717 /* Rewind to the beginning of STREAM.
719 This function is a possible cancellation point and therefore not
720 marked with __THROW. */
721 extern void rewind (FILE *__stream);
723 /* The Single Unix Specification, Version 2, specifies an alternative,
724 more adequate interface for the two functions above which deal with
725 file offset. `long int' is not the right type. These definitions
726 are originally defined in the Large File Support API. */
728 #if defined __USE_LARGEFILE || defined __USE_XOPEN2K
729 # ifndef __USE_FILE_OFFSET64
730 /* Seek to a certain position on STREAM.
732 This function is a possible cancellation point and therefore not
733 marked with __THROW. */
734 extern int fseeko (FILE *__stream, __off_t __off, int __whence);
735 /* Return the current position of STREAM.
737 This function is a possible cancellation point and therefore not
738 marked with __THROW. */
739 extern __off_t ftello (FILE *__stream) __wur;
740 # else
741 # ifdef __REDIRECT
742 extern int __REDIRECT (fseeko,
743 (FILE *__stream, __off64_t __off, int __whence),
744 fseeko64);
745 extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64);
746 # else
747 # define fseeko fseeko64
748 # define ftello ftello64
749 # endif
750 # endif
751 #endif
753 #ifndef __USE_FILE_OFFSET64
754 /* Get STREAM's position.
756 This function is a possible cancellation point and therefore not
757 marked with __THROW. */
758 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
759 /* Set STREAM's position.
761 This function is a possible cancellation point and therefore not
762 marked with __THROW. */
763 extern int fsetpos (FILE *__stream, const fpos_t *__pos);
764 #else
765 # ifdef __REDIRECT
766 extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
767 fpos_t *__restrict __pos), fgetpos64);
768 extern int __REDIRECT (fsetpos,
769 (FILE *__stream, const fpos_t *__pos), fsetpos64);
770 # else
771 # define fgetpos fgetpos64
772 # define fsetpos fsetpos64
773 # endif
774 #endif
776 #ifdef __USE_LARGEFILE64
777 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
778 extern __off64_t ftello64 (FILE *__stream) __wur;
779 extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
780 extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
781 #endif
783 /* Clear the error and EOF indicators for STREAM. */
784 extern void clearerr (FILE *__stream) __THROW;
785 /* Return the EOF indicator for STREAM. */
786 extern int feof (FILE *__stream) __THROW __wur;
787 /* Return the error indicator for STREAM. */
788 extern int ferror (FILE *__stream) __THROW __wur;
790 #ifdef __USE_MISC
791 /* Faster versions when locking is not required. */
792 extern void clearerr_unlocked (FILE *__stream) __THROW;
793 extern int feof_unlocked (FILE *__stream) __THROW __wur;
794 extern int ferror_unlocked (FILE *__stream) __THROW __wur;
795 #endif
798 /* Print a message describing the meaning of the value of errno.
800 This function is a possible cancellation point and therefore not
801 marked with __THROW. */
802 extern void perror (const char *__s);
804 /* Provide the declarations for `sys_errlist' and `sys_nerr' if they
805 are available on this system. Even if available, these variables
806 should not be used directly. The `strerror' function provides
807 all the necessary functionality. */
808 #include <bits/sys_errlist.h>
811 #ifdef __USE_POSIX
812 /* Return the system file descriptor for STREAM. */
813 extern int fileno (FILE *__stream) __THROW __wur;
814 #endif /* Use POSIX. */
816 #ifdef __USE_MISC
817 /* Faster version when locking is not required. */
818 extern int fileno_unlocked (FILE *__stream) __THROW __wur;
819 #endif
822 #ifdef __USE_POSIX2
823 /* Create a new stream connected to a pipe running the given command.
825 This function is a possible cancellation point and therefore not
826 marked with __THROW. */
827 extern FILE *popen (const char *__command, const char *__modes) __wur;
829 /* Close a stream opened by popen and return the status of its child.
831 This function is a possible cancellation point and therefore not
832 marked with __THROW. */
833 extern int pclose (FILE *__stream);
834 #endif
837 #ifdef __USE_POSIX
838 /* Return the name of the controlling terminal. */
839 extern char *ctermid (char *__s) __THROW;
840 #endif /* Use POSIX. */
843 #if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
844 /* Return the name of the current user. */
845 extern char *cuserid (char *__s);
846 #endif /* Use X/Open, but not issue 6. */
849 #ifdef __USE_GNU
850 struct obstack; /* See <obstack.h>. */
852 /* Write formatted output to an obstack. */
853 extern int obstack_printf (struct obstack *__restrict __obstack,
854 const char *__restrict __format, ...)
855 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
856 extern int obstack_vprintf (struct obstack *__restrict __obstack,
857 const char *__restrict __format,
858 _G_va_list __args)
859 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
860 #endif /* Use GNU. */
863 #ifdef __USE_POSIX199506
864 /* These are defined in POSIX.1:1996. */
866 /* Acquire ownership of STREAM. */
867 extern void flockfile (FILE *__stream) __THROW;
869 /* Try to acquire ownership of STREAM but do not block if it is not
870 possible. */
871 extern int ftrylockfile (FILE *__stream) __THROW __wur;
873 /* Relinquish the ownership granted for STREAM. */
874 extern void funlockfile (FILE *__stream) __THROW;
875 #endif /* POSIX */
877 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
878 /* The X/Open standard requires some functions and variables to be
879 declared here which do not belong into this header. But we have to
880 follow. In GNU mode we don't do this nonsense. */
881 # define __need_getopt
882 # include <getopt.h>
883 #endif /* X/Open, but not issue 6 and not for GNU. */
885 /* If we are compiling with optimizing read this file. It contains
886 several optimizing inline functions and macros. */
887 #ifdef __USE_EXTERN_INLINES
888 # include <bits/stdio.h>
889 #endif
890 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
891 # include <bits/stdio2.h>
892 #endif
893 #ifdef __LDBL_COMPAT
894 # include <bits/stdio-ldbl.h>
895 #endif
897 __END_DECLS
899 #endif /* <stdio.h> included. */
901 #endif /* !_STDIO_H */