1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2022 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 <https://www.gnu.org/licenses/>. */
20 * ISO C99 Standard: 7.19 Input/output <stdio.h>
26 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27 #include <bits/libc-header-start.h>
35 #define __need___va_list
38 #include <bits/types.h>
39 #include <bits/types/__fpos_t.h>
40 #include <bits/types/__fpos64_t.h>
41 #include <bits/types/__FILE.h>
42 #include <bits/types/FILE.h>
43 #include <bits/types/struct_FILE.h>
46 # include <bits/types/cookie_io_functions_t.h>
49 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
51 # ifndef _VA_LIST_DEFINED
52 typedef __gnuc_va_list
va_list;
53 # define _VA_LIST_DEFINED
60 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
61 # ifndef __off_t_defined
62 # ifndef __USE_FILE_OFFSET64
63 typedef __off_t off_t
;
65 typedef __off64_t off_t
;
67 # define __off_t_defined
69 # if defined __USE_LARGEFILE64 && !defined __off64_t_defined
70 typedef __off64_t off64_t
;
71 # define __off64_t_defined
76 # ifndef __ssize_t_defined
77 typedef __ssize_t ssize_t
;
78 # define __ssize_t_defined
82 /* The type of the second argument to `fgetpos' and `fsetpos'. */
83 #ifndef __USE_FILE_OFFSET64
84 typedef __fpos_t
fpos_t;
86 typedef __fpos64_t
fpos_t;
88 #ifdef __USE_LARGEFILE64
89 typedef __fpos64_t fpos64_t
;
92 /* The possibilities for the third argument to `setvbuf'. */
93 #define _IOFBF 0 /* Fully buffered. */
94 #define _IOLBF 1 /* Line buffered. */
95 #define _IONBF 2 /* No buffering. */
98 /* Default buffer size. */
102 /* The value returned by fgetc and similar functions to indicate the
107 /* The possibilities for the third argument to `fseek'.
108 These values should not be changed. */
109 #define SEEK_SET 0 /* Seek from beginning of file. */
110 #define SEEK_CUR 1 /* Seek from current position. */
111 #define SEEK_END 2 /* Seek from end of file. */
113 # define SEEK_DATA 3 /* Seek to next data. */
114 # define SEEK_HOLE 4 /* Seek to next hole. */
118 #if defined __USE_MISC || defined __USE_XOPEN
119 /* Default path prefix for `tempnam' and `tmpnam'. */
120 # define P_tmpdir "/tmp"
125 L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
126 TMP_MAX The minimum number of unique filenames generated by tmpnam
127 (and tempnam when it uses tmpnam's name space),
128 or tempnam (the two are separate).
129 L_ctermid How long an array to pass to `ctermid'.
130 L_cuserid How long an array to pass to `cuserid'.
131 FOPEN_MAX Minimum number of files that can be open at once.
132 FILENAME_MAX Maximum length of a filename. */
133 #include <bits/stdio_lim.h>
136 #if __GLIBC_USE (ISOC2X)
137 /* Maximum length of printf output for a NaN. */
138 # define _PRINTF_NAN_LEN_MAX 4
142 /* Standard streams. */
143 extern FILE *stdin
; /* Standard input stream. */
144 extern FILE *stdout
; /* Standard output stream. */
145 extern FILE *stderr
; /* Standard error output stream. */
146 /* C89/C99 say they're macros. Make them happy. */
148 #define stdout stdout
149 #define stderr stderr
151 /* Remove file FILENAME. */
152 extern int remove (const char *__filename
) __THROW
;
153 /* Rename file OLD to NEW. */
154 extern int rename (const char *__old
, const char *__new
) __THROW
;
157 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
158 extern int renameat (int __oldfd
, const char *__old
, int __newfd
,
159 const char *__new
) __THROW
;
163 /* Flags for renameat2. */
164 # define RENAME_NOREPLACE (1 << 0)
165 # define RENAME_EXCHANGE (1 << 1)
166 # define RENAME_WHITEOUT (1 << 2)
168 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD, with
170 extern int renameat2 (int __oldfd
, const char *__old
, int __newfd
,
171 const char *__new
, unsigned int __flags
) __THROW
;
176 This function is a possible cancellation point and therefore not
177 marked with __THROW. */
178 extern int fclose (FILE *__stream
);
180 #undef __attr_dealloc_fclose
181 #define __attr_dealloc_fclose __attr_dealloc (fclose, 1)
183 /* Create a temporary file and open it read/write.
185 This function is a possible cancellation point and therefore not
186 marked with __THROW. */
187 #ifndef __USE_FILE_OFFSET64
188 extern FILE *tmpfile (void)
189 __attribute_malloc__ __attr_dealloc_fclose __wur
;
192 extern FILE *__REDIRECT (tmpfile
, (void), tmpfile64
)
193 __attribute_malloc__ __attr_dealloc_fclose __wur
;
195 # define tmpfile tmpfile64
199 #ifdef __USE_LARGEFILE64
200 extern FILE *tmpfile64 (void)
201 __attribute_malloc__ __attr_dealloc_fclose __wur
;
204 /* Generate a temporary filename. */
205 extern char *tmpnam (char[L_tmpnam
]) __THROW __wur
;
208 /* This is the reentrant variant of `tmpnam'. The only difference is
209 that it does not allow S to be NULL. */
210 extern char *tmpnam_r (char __s
[L_tmpnam
]) __THROW __wur
;
214 #if defined __USE_MISC || defined __USE_XOPEN
215 /* Generate a unique temporary filename using up to five characters of PFX
216 if it is not NULL. The directory to put this file in is searched for
217 as follows: First the environment variable "TMPDIR" is checked.
218 If it contains the name of a writable directory, that directory is used.
219 If not and if DIR is not NULL, that value is checked. If that fails,
220 P_tmpdir is tried and finally "/tmp". The storage for the filename
221 is allocated by `malloc'. */
222 extern char *tempnam (const char *__dir
, const char *__pfx
)
223 __THROW __attribute_malloc__ __wur __attr_dealloc_free
;
226 /* Flush STREAM, or all streams if STREAM is NULL.
228 This function is a possible cancellation point and therefore not
229 marked with __THROW. */
230 extern int fflush (FILE *__stream
);
233 /* Faster versions when locking is not required.
235 This function is not part of POSIX and therefore no official
236 cancellation point. But due to similarity with an POSIX interface
237 or due to the implementation it is a cancellation point and
238 therefore not marked with __THROW. */
239 extern int fflush_unlocked (FILE *__stream
);
243 /* Close all streams.
245 This function is not part of POSIX and therefore no official
246 cancellation point. But due to similarity with an POSIX interface
247 or due to the implementation it is a cancellation point and
248 therefore not marked with __THROW. */
249 extern int fcloseall (void);
253 #ifndef __USE_FILE_OFFSET64
254 /* Open a file and create a new stream for it.
256 This function is a possible cancellation point and therefore not
257 marked with __THROW. */
258 extern FILE *fopen (const char *__restrict __filename
,
259 const char *__restrict __modes
)
260 __attribute_malloc__ __attr_dealloc_fclose __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
;
270 extern FILE *__REDIRECT (fopen
, (const char *__restrict __filename
,
271 const char *__restrict __modes
), fopen64
)
272 __attribute_malloc__ __attr_dealloc_fclose __wur
;
273 extern FILE *__REDIRECT (freopen
, (const char *__restrict __filename
,
274 const char *__restrict __modes
,
275 FILE *__restrict __stream
), freopen64
)
278 # define fopen fopen64
279 # define freopen freopen64
282 #ifdef __USE_LARGEFILE64
283 extern FILE *fopen64 (const char *__restrict __filename
,
284 const char *__restrict __modes
)
285 __attribute_malloc__ __attr_dealloc_fclose __wur
;
286 extern FILE *freopen64 (const char *__restrict __filename
,
287 const char *__restrict __modes
,
288 FILE *__restrict __stream
) __wur
;
292 /* Create a new stream that refers to an existing system file descriptor. */
293 extern FILE *fdopen (int __fd
, const char *__modes
) __THROW
294 __attribute_malloc__ __attr_dealloc_fclose __wur
;
298 /* Create a new stream that refers to the given magic cookie,
299 and uses the given functions for input and output. */
300 extern FILE *fopencookie (void *__restrict __magic_cookie
,
301 const char *__restrict __modes
,
302 cookie_io_functions_t __io_funcs
) __THROW
303 __attribute_malloc__ __attr_dealloc_fclose __wur
;
306 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
307 /* Create a new stream that refers to a memory buffer. */
308 extern FILE *fmemopen (void *__s
, size_t __len
, const char *__modes
)
309 __THROW __attribute_malloc__ __attr_dealloc_fclose __wur
;
311 /* Open a stream that writes into a malloc'd buffer that is expanded as
312 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
313 and the number of characters written on fflush or fclose. */
314 extern FILE *open_memstream (char **__bufloc
, size_t *__sizeloc
) __THROW
315 __attribute_malloc__ __attr_dealloc_fclose __wur
;
318 /* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
319 a wide character string. Declared here only to add attribute malloc
320 and only if <wchar.h> has been previously #included. */
321 extern __FILE
*open_wmemstream (wchar_t **__bufloc
, size_t *__sizeloc
) __THROW
322 __attribute_malloc__ __attr_dealloc_fclose
;
326 /* If BUF is NULL, make STREAM unbuffered.
327 Else make it use buffer BUF, of size BUFSIZ. */
328 extern void setbuf (FILE *__restrict __stream
, char *__restrict __buf
) __THROW
;
329 /* Make STREAM use buffering mode MODE.
330 If BUF is not NULL, use N bytes of it for buffering;
331 else allocate an internal buffer N bytes long. */
332 extern int setvbuf (FILE *__restrict __stream
, char *__restrict __buf
,
333 int __modes
, size_t __n
) __THROW
;
336 /* If BUF is NULL, make STREAM unbuffered.
337 Else make it use SIZE bytes of BUF for buffering. */
338 extern void setbuffer (FILE *__restrict __stream
, char *__restrict __buf
,
339 size_t __size
) __THROW
;
341 /* Make STREAM line-buffered. */
342 extern void setlinebuf (FILE *__stream
) __THROW
;
346 /* Write formatted output to STREAM.
348 This function is a possible cancellation point and therefore not
349 marked with __THROW. */
350 extern int fprintf (FILE *__restrict __stream
,
351 const char *__restrict __format
, ...);
352 /* Write formatted output to stdout.
354 This function is a possible cancellation point and therefore not
355 marked with __THROW. */
356 extern int printf (const char *__restrict __format
, ...);
357 /* Write formatted output to S. */
358 extern int sprintf (char *__restrict __s
,
359 const char *__restrict __format
, ...) __THROWNL
;
361 /* Write formatted output to S from argument list ARG.
363 This function is a possible cancellation point and therefore not
364 marked with __THROW. */
365 extern int vfprintf (FILE *__restrict __s
, const char *__restrict __format
,
366 __gnuc_va_list __arg
);
367 /* Write formatted output to stdout from argument list ARG.
369 This function is a possible cancellation point and therefore not
370 marked with __THROW. */
371 extern int vprintf (const char *__restrict __format
, __gnuc_va_list __arg
);
372 /* Write formatted output to S from argument list ARG. */
373 extern int vsprintf (char *__restrict __s
, const char *__restrict __format
,
374 __gnuc_va_list __arg
) __THROWNL
;
376 #if defined __USE_ISOC99 || defined __USE_UNIX98
377 /* Maximum chars of output to write in MAXLEN. */
378 extern int snprintf (char *__restrict __s
, size_t __maxlen
,
379 const char *__restrict __format
, ...)
380 __THROWNL
__attribute__ ((__format__ (__printf__
, 3, 4)));
382 extern int vsnprintf (char *__restrict __s
, size_t __maxlen
,
383 const char *__restrict __format
, __gnuc_va_list __arg
)
384 __THROWNL
__attribute__ ((__format__ (__printf__
, 3, 0)));
387 #if __GLIBC_USE (LIB_EXT2)
388 /* Write formatted output to a string dynamically allocated with `malloc'.
389 Store the address of the string in *PTR. */
390 extern int vasprintf (char **__restrict __ptr
, const char *__restrict __f
,
391 __gnuc_va_list __arg
)
392 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 0))) __wur
;
393 extern int __asprintf (char **__restrict __ptr
,
394 const char *__restrict __fmt
, ...)
395 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 3))) __wur
;
396 extern int asprintf (char **__restrict __ptr
,
397 const char *__restrict __fmt
, ...)
398 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 3))) __wur
;
401 #ifdef __USE_XOPEN2K8
402 /* Write formatted output to a file descriptor. */
403 extern int vdprintf (int __fd
, const char *__restrict __fmt
,
404 __gnuc_va_list __arg
)
405 __attribute__ ((__format__ (__printf__
, 2, 0)));
406 extern int dprintf (int __fd
, const char *__restrict __fmt
, ...)
407 __attribute__ ((__format__ (__printf__
, 2, 3)));
411 /* Read formatted input from STREAM.
413 This function is a possible cancellation point and therefore not
414 marked with __THROW. */
415 extern int fscanf (FILE *__restrict __stream
,
416 const char *__restrict __format
, ...) __wur
;
417 /* Read formatted input from stdin.
419 This function is a possible cancellation point and therefore not
420 marked with __THROW. */
421 extern int scanf (const char *__restrict __format
, ...) __wur
;
422 /* Read formatted input from S. */
423 extern int sscanf (const char *__restrict __s
,
424 const char *__restrict __format
, ...) __THROW
;
426 /* For historical reasons, the C99-compliant versions of the scanf
427 functions are at alternative names. When __LDBL_COMPAT or
428 __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
429 bits/stdio-ldbl.h. */
430 #include <bits/floatn.h>
431 #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
432 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
434 extern int __REDIRECT (fscanf
, (FILE *__restrict __stream
,
435 const char *__restrict __format
, ...),
436 __isoc99_fscanf
) __wur
;
437 extern int __REDIRECT (scanf
, (const char *__restrict __format
, ...),
438 __isoc99_scanf
) __wur
;
439 extern int __REDIRECT_NTH (sscanf
, (const char *__restrict __s
,
440 const char *__restrict __format
, ...),
443 extern int __isoc99_fscanf (FILE *__restrict __stream
,
444 const char *__restrict __format
, ...) __wur
;
445 extern int __isoc99_scanf (const char *__restrict __format
, ...) __wur
;
446 extern int __isoc99_sscanf (const char *__restrict __s
,
447 const char *__restrict __format
, ...) __THROW
;
448 # define fscanf __isoc99_fscanf
449 # define scanf __isoc99_scanf
450 # define sscanf __isoc99_sscanf
455 /* Read formatted input from S into argument list ARG.
457 This function is a possible cancellation point and therefore not
458 marked with __THROW. */
459 extern int vfscanf (FILE *__restrict __s
, const char *__restrict __format
,
460 __gnuc_va_list __arg
)
461 __attribute__ ((__format__ (__scanf__
, 2, 0))) __wur
;
463 /* Read formatted input from stdin into argument list ARG.
465 This function is a possible cancellation point and therefore not
466 marked with __THROW. */
467 extern int vscanf (const char *__restrict __format
, __gnuc_va_list __arg
)
468 __attribute__ ((__format__ (__scanf__
, 1, 0))) __wur
;
470 /* Read formatted input from S into argument list ARG. */
471 extern int vsscanf (const char *__restrict __s
,
472 const char *__restrict __format
, __gnuc_va_list __arg
)
473 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
475 /* Same redirection as above for the v*scanf family. */
476 # if !__GLIBC_USE (DEPRECATED_SCANF)
477 # if defined __REDIRECT && !defined __LDBL_COMPAT \
478 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
479 extern int __REDIRECT (vfscanf
,
480 (FILE *__restrict __s
,
481 const char *__restrict __format
, __gnuc_va_list __arg
),
483 __attribute__ ((__format__ (__scanf__
, 2, 0))) __wur
;
484 extern int __REDIRECT (vscanf
, (const char *__restrict __format
,
485 __gnuc_va_list __arg
), __isoc99_vscanf
)
486 __attribute__ ((__format__ (__scanf__
, 1, 0))) __wur
;
487 extern int __REDIRECT_NTH (vsscanf
,
488 (const char *__restrict __s
,
489 const char *__restrict __format
,
490 __gnuc_va_list __arg
), __isoc99_vsscanf
)
491 __attribute__ ((__format__ (__scanf__
, 2, 0)));
492 # elif !defined __REDIRECT
493 extern int __isoc99_vfscanf (FILE *__restrict __s
,
494 const char *__restrict __format
,
495 __gnuc_va_list __arg
) __wur
;
496 extern int __isoc99_vscanf (const char *__restrict __format
,
497 __gnuc_va_list __arg
) __wur
;
498 extern int __isoc99_vsscanf (const char *__restrict __s
,
499 const char *__restrict __format
,
500 __gnuc_va_list __arg
) __THROW
;
501 # define vfscanf __isoc99_vfscanf
502 # define vscanf __isoc99_vscanf
503 # define vsscanf __isoc99_vsscanf
506 #endif /* Use ISO C9x. */
509 /* Read a character from STREAM.
511 These functions are possible cancellation points and therefore not
512 marked with __THROW. */
513 extern int fgetc (FILE *__stream
);
514 extern int getc (FILE *__stream
);
516 /* Read a character from stdin.
518 This function is a possible cancellation point and therefore not
519 marked with __THROW. */
520 extern int getchar (void);
522 #ifdef __USE_POSIX199506
523 /* These are defined in POSIX.1:1996.
525 These functions are possible cancellation points and therefore not
526 marked with __THROW. */
527 extern int getc_unlocked (FILE *__stream
);
528 extern int getchar_unlocked (void);
529 #endif /* Use POSIX. */
532 /* Faster version when locking is not necessary.
534 This function is not part of POSIX and therefore no official
535 cancellation point. But due to similarity with an POSIX interface
536 or due to the implementation it is a cancellation point and
537 therefore not marked with __THROW. */
538 extern int fgetc_unlocked (FILE *__stream
);
539 #endif /* Use MISC. */
542 /* Write a character to STREAM.
544 These functions are possible cancellation points and therefore not
547 These functions is a possible cancellation point and therefore not
548 marked with __THROW. */
549 extern int fputc (int __c
, FILE *__stream
);
550 extern int putc (int __c
, FILE *__stream
);
552 /* Write a character to stdout.
554 This function is a possible cancellation point and therefore not
555 marked with __THROW. */
556 extern int putchar (int __c
);
559 /* Faster version when locking is not necessary.
561 This function is not part of POSIX and therefore no official
562 cancellation point. But due to similarity with an POSIX interface
563 or due to the implementation it is a cancellation point and
564 therefore not marked with __THROW. */
565 extern int fputc_unlocked (int __c
, FILE *__stream
);
566 #endif /* Use MISC. */
568 #ifdef __USE_POSIX199506
569 /* These are defined in POSIX.1:1996.
571 These functions are possible cancellation points and therefore not
572 marked with __THROW. */
573 extern int putc_unlocked (int __c
, FILE *__stream
);
574 extern int putchar_unlocked (int __c
);
575 #endif /* Use POSIX. */
578 #if defined __USE_MISC \
579 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
580 /* Get a word (int) from STREAM. */
581 extern int getw (FILE *__stream
);
583 /* Write a word (int) to STREAM. */
584 extern int putw (int __w
, FILE *__stream
);
588 /* Get a newline-terminated string of finite length from STREAM.
590 This function is a possible cancellation point and therefore not
591 marked with __THROW. */
592 extern char *fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
593 __wur
__fortified_attr_access (__write_only__
, 1, 2);
595 #if __GLIBC_USE (DEPRECATED_GETS)
596 /* Get a newline-terminated string from stdin, removing the newline.
598 This function is impossible to use safely. It has been officially
599 removed from ISO C11 and ISO C++14, and we have also removed it
600 from the _GNU_SOURCE feature list. It remains available when
601 explicitly using an old ISO C, Unix, or POSIX standard.
603 This function is a possible cancellation point and therefore not
604 marked with __THROW. */
605 extern char *gets (char *__s
) __wur __attribute_deprecated__
;
609 /* This function does the same as `fgets' but does not lock the stream.
611 This function is not part of POSIX and therefore no official
612 cancellation point. But due to similarity with an POSIX interface
613 or due to the implementation it is a cancellation point and
614 therefore not marked with __THROW. */
615 extern char *fgets_unlocked (char *__restrict __s
, int __n
,
616 FILE *__restrict __stream
) __wur
617 __fortified_attr_access (__write_only__
, 1, 2);
621 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
622 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
623 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
624 NULL), pointing to *N characters of space. It is realloc'd as
625 necessary. Returns the number of characters read (not including the
626 null terminator), or -1 on error or EOF.
628 These functions are not part of POSIX and therefore no official
629 cancellation point. But due to similarity with an POSIX interface
630 or due to the implementation they are cancellation points and
631 therefore not marked with __THROW. */
632 extern __ssize_t
__getdelim (char **__restrict __lineptr
,
633 size_t *__restrict __n
, int __delimiter
,
634 FILE *__restrict __stream
) __wur
;
635 extern __ssize_t
getdelim (char **__restrict __lineptr
,
636 size_t *__restrict __n
, int __delimiter
,
637 FILE *__restrict __stream
) __wur
;
639 /* Like `getdelim', but reads up to a newline.
641 This function is not part of POSIX and therefore no official
642 cancellation point. But due to similarity with an POSIX interface
643 or due to the implementation it is a cancellation point and
644 therefore not marked with __THROW. */
645 extern __ssize_t
getline (char **__restrict __lineptr
,
646 size_t *__restrict __n
,
647 FILE *__restrict __stream
) __wur
;
651 /* Write a string to STREAM.
653 This function is a possible cancellation point and therefore not
654 marked with __THROW. */
655 extern int fputs (const char *__restrict __s
, FILE *__restrict __stream
);
657 /* Write a string, followed by a newline, to stdout.
659 This function is a possible cancellation point and therefore not
660 marked with __THROW. */
661 extern int puts (const char *__s
);
664 /* Push a character back onto the input buffer of STREAM.
666 This function is a possible cancellation point and therefore not
667 marked with __THROW. */
668 extern int ungetc (int __c
, FILE *__stream
);
671 /* Read chunks of generic data from STREAM.
673 This function is a possible cancellation point and therefore not
674 marked with __THROW. */
675 extern size_t fread (void *__restrict __ptr
, size_t __size
,
676 size_t __n
, FILE *__restrict __stream
) __wur
;
677 /* Write chunks of generic data to STREAM.
679 This function is a possible cancellation point and therefore not
680 marked with __THROW. */
681 extern size_t fwrite (const void *__restrict __ptr
, size_t __size
,
682 size_t __n
, FILE *__restrict __s
);
685 /* This function does the same as `fputs' but does not lock the stream.
687 This function is not part of POSIX and therefore no official
688 cancellation point. But due to similarity with an POSIX interface
689 or due to the implementation it is a cancellation point and
690 therefore not marked with __THROW. */
691 extern int fputs_unlocked (const char *__restrict __s
,
692 FILE *__restrict __stream
);
696 /* Faster versions when locking is not necessary.
698 These functions are not part of POSIX and therefore no official
699 cancellation point. But due to similarity with an POSIX interface
700 or due to the implementation they are cancellation points and
701 therefore not marked with __THROW. */
702 extern size_t fread_unlocked (void *__restrict __ptr
, size_t __size
,
703 size_t __n
, FILE *__restrict __stream
) __wur
;
704 extern size_t fwrite_unlocked (const void *__restrict __ptr
, size_t __size
,
705 size_t __n
, FILE *__restrict __stream
);
709 /* Seek to a certain position on STREAM.
711 This function is a possible cancellation point and therefore not
712 marked with __THROW. */
713 extern int fseek (FILE *__stream
, long int __off
, int __whence
);
714 /* Return the current position of STREAM.
716 This function is a possible cancellation point and therefore not
717 marked with __THROW. */
718 extern long int ftell (FILE *__stream
) __wur
;
719 /* Rewind to the beginning of STREAM.
721 This function is a possible cancellation point and therefore not
722 marked with __THROW. */
723 extern void rewind (FILE *__stream
);
725 /* The Single Unix Specification, Version 2, specifies an alternative,
726 more adequate interface for the two functions above which deal with
727 file offset. `long int' is not the right type. These definitions
728 are originally defined in the Large File Support API. */
730 #if defined __USE_LARGEFILE || defined __USE_XOPEN2K
731 # ifndef __USE_FILE_OFFSET64
732 /* Seek to a certain position on STREAM.
734 This function is a possible cancellation point and therefore not
735 marked with __THROW. */
736 extern int fseeko (FILE *__stream
, __off_t __off
, int __whence
);
737 /* Return the current position of STREAM.
739 This function is a possible cancellation point and therefore not
740 marked with __THROW. */
741 extern __off_t
ftello (FILE *__stream
) __wur
;
744 extern int __REDIRECT (fseeko
,
745 (FILE *__stream
, __off64_t __off
, int __whence
),
747 extern __off64_t
__REDIRECT (ftello
, (FILE *__stream
), ftello64
);
749 # define fseeko fseeko64
750 # define ftello ftello64
755 #ifndef __USE_FILE_OFFSET64
756 /* Get STREAM's position.
758 This function is a possible cancellation point and therefore not
759 marked with __THROW. */
760 extern int fgetpos (FILE *__restrict __stream
, fpos_t *__restrict __pos
);
761 /* Set STREAM's position.
763 This function is a possible cancellation point and therefore not
764 marked with __THROW. */
765 extern int fsetpos (FILE *__stream
, const fpos_t *__pos
);
768 extern int __REDIRECT (fgetpos
, (FILE *__restrict __stream
,
769 fpos_t *__restrict __pos
), fgetpos64
);
770 extern int __REDIRECT (fsetpos
,
771 (FILE *__stream
, const fpos_t *__pos
), fsetpos64
);
773 # define fgetpos fgetpos64
774 # define fsetpos fsetpos64
778 #ifdef __USE_LARGEFILE64
779 extern int fseeko64 (FILE *__stream
, __off64_t __off
, int __whence
);
780 extern __off64_t
ftello64 (FILE *__stream
) __wur
;
781 extern int fgetpos64 (FILE *__restrict __stream
, fpos64_t
*__restrict __pos
);
782 extern int fsetpos64 (FILE *__stream
, const fpos64_t
*__pos
);
785 /* Clear the error and EOF indicators for STREAM. */
786 extern void clearerr (FILE *__stream
) __THROW
;
787 /* Return the EOF indicator for STREAM. */
788 extern int feof (FILE *__stream
) __THROW __wur
;
789 /* Return the error indicator for STREAM. */
790 extern int ferror (FILE *__stream
) __THROW __wur
;
793 /* Faster versions when locking is not required. */
794 extern void clearerr_unlocked (FILE *__stream
) __THROW
;
795 extern int feof_unlocked (FILE *__stream
) __THROW __wur
;
796 extern int ferror_unlocked (FILE *__stream
) __THROW __wur
;
800 /* Print a message describing the meaning of the value of errno.
802 This function is a possible cancellation point and therefore not
803 marked with __THROW. */
804 extern void perror (const char *__s
);
808 /* Return the system file descriptor for STREAM. */
809 extern int fileno (FILE *__stream
) __THROW __wur
;
810 #endif /* Use POSIX. */
813 /* Faster version when locking is not required. */
814 extern int fileno_unlocked (FILE *__stream
) __THROW __wur
;
819 /* Close a stream opened by popen and return the status of its child.
821 This function is a possible cancellation point and therefore not
822 marked with __THROW. */
823 extern int pclose (FILE *__stream
);
825 /* Create a new stream connected to a pipe running the given command.
827 This function is a possible cancellation point and therefore not
828 marked with __THROW. */
829 extern FILE *popen (const char *__command
, const char *__modes
)
830 __attribute_malloc__
__attr_dealloc (pclose
, 1) __wur
;
836 /* Return the name of the controlling terminal. */
837 extern char *ctermid (char *__s
) __THROW
838 __attr_access ((__write_only__
, 1));
839 #endif /* Use POSIX. */
842 #if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
843 /* Return the name of the current user. */
844 extern char *cuserid (char *__s
)
845 __attr_access ((__write_only__
, 1));
846 #endif /* Use X/Open, but not issue 6. */
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 __gnuc_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
871 extern int ftrylockfile (FILE *__stream
) __THROW __wur
;
873 /* Relinquish the ownership granted for STREAM. */
874 extern void funlockfile (FILE *__stream
) __THROW
;
877 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
878 /* X/Open Issues 1-5 required getopt to be declared in this
879 header. It was removed in Issue 6. GNU follows Issue 6. */
880 # include <bits/getopt_posix.h>
883 /* Slow-path routines used by the optimized inline functions in
885 extern int __uflow (FILE *);
886 extern int __overflow (FILE *, int);
888 /* If we are compiling with optimizing read this file. It contains
889 several optimizing inline functions and macros. */
890 #ifdef __USE_EXTERN_INLINES
891 # include <bits/stdio.h>
893 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
894 # include <bits/stdio2.h>
897 #include <bits/floatn.h>
898 #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
899 # include <bits/stdio-ldbl.h>
904 #endif /* <stdio.h> included. */