1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2024 Free Software Foundation, Inc.
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
21 * ISO C99 Standard: 7.19 Input/output <stdio.h>
27 #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
28 #include <bits/libc-header-start.h>
36 #define __need___va_list
39 #include <bits/types.h>
40 #include <bits/types/__fpos_t.h>
41 #include <bits/types/__fpos64_t.h>
42 #include <bits/types/__FILE.h>
43 #include <bits/types/FILE.h>
44 #include <bits/types/struct_FILE.h>
47 # include <bits/types/cookie_io_functions_t.h>
50 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
52 # ifndef _VA_LIST_DEFINED
53 typedef __gnuc_va_list
va_list;
54 # define _VA_LIST_DEFINED
61 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
62 # ifndef __off_t_defined
63 # ifndef __USE_FILE_OFFSET64
64 typedef __off_t off_t
;
66 typedef __off64_t off_t
;
68 # define __off_t_defined
70 # if defined __USE_LARGEFILE64 && !defined __off64_t_defined
71 typedef __off64_t off64_t
;
72 # define __off64_t_defined
77 # ifndef __ssize_t_defined
78 typedef __ssize_t ssize_t
;
79 # define __ssize_t_defined
83 /* The type of the second argument to `fgetpos' and `fsetpos'. */
84 #ifndef __USE_FILE_OFFSET64
85 typedef __fpos_t
fpos_t;
87 typedef __fpos64_t
fpos_t;
89 #ifdef __USE_LARGEFILE64
90 typedef __fpos64_t fpos64_t
;
93 /* The possibilities for the third argument to `setvbuf'. */
94 #define _IOFBF 0 /* Fully buffered. */
95 #define _IOLBF 1 /* Line buffered. */
96 #define _IONBF 2 /* No buffering. */
99 /* Default buffer size. */
103 /* The value returned by fgetc and similar functions to indicate the
108 /* The possibilities for the third argument to `fseek'.
109 These values should not be changed. */
110 #define SEEK_SET 0 /* Seek from beginning of file. */
111 #define SEEK_CUR 1 /* Seek from current position. */
112 #define SEEK_END 2 /* Seek from end of file. */
114 # define SEEK_DATA 3 /* Seek to next data. */
115 # define SEEK_HOLE 4 /* Seek to next hole. */
119 #if defined __USE_MISC || defined __USE_XOPEN
120 /* Default path prefix for `tempnam' and `tmpnam'. */
121 # define P_tmpdir "/tmp"
125 #define TMP_MAX 238328
128 FILENAME_MAX Maximum length of a filename. */
129 #include <bits/stdio_lim.h>
133 # if !defined __USE_XOPEN2K || defined __USE_GNU
142 #if __GLIBC_USE (ISOC23)
143 /* Maximum length of printf output for a NaN. */
144 # define _PRINTF_NAN_LEN_MAX 4
148 /* Standard streams. */
149 extern FILE *stdin
; /* Standard input stream. */
150 extern FILE *stdout
; /* Standard output stream. */
151 extern FILE *stderr
; /* Standard error output stream. */
152 /* C89/C99 say they're macros. Make them happy. */
154 #define stdout stdout
155 #define stderr stderr
157 /* Remove file FILENAME. */
158 extern int remove (const char *__filename
) __THROW
;
159 /* Rename file OLD to NEW. */
160 extern int rename (const char *__old
, const char *__new
) __THROW
;
163 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
164 extern int renameat (int __oldfd
, const char *__old
, int __newfd
,
165 const char *__new
) __THROW
;
169 /* Flags for renameat2. */
170 # define RENAME_NOREPLACE (1 << 0)
171 # define RENAME_EXCHANGE (1 << 1)
172 # define RENAME_WHITEOUT (1 << 2)
174 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD, with
176 extern int renameat2 (int __oldfd
, const char *__old
, int __newfd
,
177 const char *__new
, unsigned int __flags
) __THROW
;
182 This function is a possible cancellation point and therefore not
183 marked with __THROW. */
184 extern int fclose (FILE *__stream
) __nonnull ((1));
186 #undef __attr_dealloc_fclose
187 #define __attr_dealloc_fclose __attr_dealloc (fclose, 1)
189 /* Create a temporary file and open it read/write.
191 This function is a possible cancellation point and therefore not
192 marked with __THROW. */
193 #ifndef __USE_FILE_OFFSET64
194 extern FILE *tmpfile (void)
195 __attribute_malloc__ __attr_dealloc_fclose __wur
;
198 extern FILE *__REDIRECT (tmpfile
, (void), tmpfile64
)
199 __attribute_malloc__ __attr_dealloc_fclose __wur
;
201 # define tmpfile tmpfile64
205 #ifdef __USE_LARGEFILE64
206 extern FILE *tmpfile64 (void)
207 __attribute_malloc__ __attr_dealloc_fclose __wur
;
210 /* Generate a temporary filename. */
211 extern char *tmpnam (char[L_tmpnam
]) __THROW __wur
;
214 /* This is the reentrant variant of `tmpnam'. The only difference is
215 that it does not allow S to be NULL. */
216 extern char *tmpnam_r (char __s
[L_tmpnam
]) __THROW __wur
;
220 #if defined __USE_MISC || defined __USE_XOPEN
221 /* Generate a unique temporary filename using up to five characters of PFX
222 if it is not NULL. The directory to put this file in is searched for
223 as follows: First the environment variable "TMPDIR" is checked.
224 If it contains the name of a writable directory, that directory is used.
225 If not and if DIR is not NULL, that value is checked. If that fails,
226 P_tmpdir is tried and finally "/tmp". The storage for the filename
227 is allocated by `malloc'. */
228 extern char *tempnam (const char *__dir
, const char *__pfx
)
229 __THROW __attribute_malloc__ __wur __attr_dealloc_free
;
232 /* Flush STREAM, or all streams if STREAM is NULL.
234 This function is a possible cancellation point and therefore not
235 marked with __THROW. */
236 extern int fflush (FILE *__stream
);
239 /* Faster versions when locking is not required.
241 This function is not part of POSIX and therefore no official
242 cancellation point. But due to similarity with an POSIX interface
243 or due to the implementation it is a cancellation point and
244 therefore not marked with __THROW. */
245 extern int fflush_unlocked (FILE *__stream
);
249 /* Close all streams.
251 This function is not part of POSIX and therefore no official
252 cancellation point. But due to similarity with an POSIX interface
253 or due to the implementation it is a cancellation point and
254 therefore not marked with __THROW. */
255 extern int fcloseall (void);
259 #ifndef __USE_FILE_OFFSET64
260 /* Open a file and create a new stream for it.
262 This function is a possible cancellation point and therefore not
263 marked with __THROW. */
264 extern FILE *fopen (const char *__restrict __filename
,
265 const char *__restrict __modes
)
266 __attribute_malloc__ __attr_dealloc_fclose __wur
;
267 /* Open a file, replacing an existing stream with it.
269 This function is a possible cancellation point and therefore not
270 marked with __THROW. */
271 extern FILE *freopen (const char *__restrict __filename
,
272 const char *__restrict __modes
,
273 FILE *__restrict __stream
) __wur
__nonnull ((3));
276 extern FILE *__REDIRECT (fopen
, (const char *__restrict __filename
,
277 const char *__restrict __modes
), fopen64
)
278 __attribute_malloc__ __attr_dealloc_fclose __wur
;
279 extern FILE *__REDIRECT (freopen
, (const char *__restrict __filename
,
280 const char *__restrict __modes
,
281 FILE *__restrict __stream
), freopen64
)
282 __wur
__nonnull ((3));
284 # define fopen fopen64
285 # define freopen freopen64
288 #ifdef __USE_LARGEFILE64
289 extern FILE *fopen64 (const char *__restrict __filename
,
290 const char *__restrict __modes
)
291 __attribute_malloc__ __attr_dealloc_fclose __wur
;
292 extern FILE *freopen64 (const char *__restrict __filename
,
293 const char *__restrict __modes
,
294 FILE *__restrict __stream
) __wur
__nonnull ((3));
298 /* Create a new stream that refers to an existing system file descriptor. */
299 extern FILE *fdopen (int __fd
, const char *__modes
) __THROW
300 __attribute_malloc__ __attr_dealloc_fclose __wur
;
304 /* Create a new stream that refers to the given magic cookie,
305 and uses the given functions for input and output. */
306 extern FILE *fopencookie (void *__restrict __magic_cookie
,
307 const char *__restrict __modes
,
308 cookie_io_functions_t __io_funcs
) __THROW
309 __attribute_malloc__ __attr_dealloc_fclose __wur
;
312 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
313 /* Create a new stream that refers to a memory buffer. */
314 extern FILE *fmemopen (void *__s
, size_t __len
, const char *__modes
)
315 __THROW __attribute_malloc__ __attr_dealloc_fclose __wur
;
317 /* Open a stream that writes into a malloc'd buffer that is expanded as
318 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
319 and the number of characters written on fflush or fclose. */
320 extern FILE *open_memstream (char **__bufloc
, size_t *__sizeloc
) __THROW
321 __attribute_malloc__ __attr_dealloc_fclose __wur
;
324 /* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
325 a wide character string. Declared here only to add attribute malloc
326 and only if <wchar.h> has been previously #included. */
327 extern __FILE
*open_wmemstream (wchar_t **__bufloc
, size_t *__sizeloc
) __THROW
328 __attribute_malloc__ __attr_dealloc_fclose
;
332 /* If BUF is NULL, make STREAM unbuffered.
333 Else make it use buffer BUF, of size BUFSIZ. */
334 extern void setbuf (FILE *__restrict __stream
, char *__restrict __buf
) __THROW
336 /* Make STREAM use buffering mode MODE.
337 If BUF is not NULL, use N bytes of it for buffering;
338 else allocate an internal buffer N bytes long. */
339 extern int setvbuf (FILE *__restrict __stream
, char *__restrict __buf
,
340 int __modes
, size_t __n
) __THROW
__nonnull ((1));
343 /* If BUF is NULL, make STREAM unbuffered.
344 Else make it use SIZE bytes of BUF for buffering. */
345 extern void setbuffer (FILE *__restrict __stream
, char *__restrict __buf
,
346 size_t __size
) __THROW
__nonnull ((1));
348 /* Make STREAM line-buffered. */
349 extern void setlinebuf (FILE *__stream
) __THROW
__nonnull ((1));
353 /* Write formatted output to STREAM.
355 This function is a possible cancellation point and therefore not
356 marked with __THROW. */
357 extern int fprintf (FILE *__restrict __stream
,
358 const char *__restrict __format
, ...) __nonnull ((1));
359 /* Write formatted output to stdout.
361 This function is a possible cancellation point and therefore not
362 marked with __THROW. */
363 extern int printf (const char *__restrict __format
, ...);
364 /* Write formatted output to S. */
365 extern int sprintf (char *__restrict __s
,
366 const char *__restrict __format
, ...) __THROWNL
;
368 /* Write formatted output to S from argument list ARG.
370 This function is a possible cancellation point and therefore not
371 marked with __THROW. */
372 extern int vfprintf (FILE *__restrict __s
, const char *__restrict __format
,
373 __gnuc_va_list __arg
) __nonnull ((1));
374 /* Write formatted output to stdout from argument list ARG.
376 This function is a possible cancellation point and therefore not
377 marked with __THROW. */
378 extern int vprintf (const char *__restrict __format
, __gnuc_va_list __arg
);
379 /* Write formatted output to S from argument list ARG. */
380 extern int vsprintf (char *__restrict __s
, const char *__restrict __format
,
381 __gnuc_va_list __arg
) __THROWNL
;
383 #if defined __USE_ISOC99 || defined __USE_UNIX98
384 /* Maximum chars of output to write in MAXLEN. */
385 extern int snprintf (char *__restrict __s
, size_t __maxlen
,
386 const char *__restrict __format
, ...)
387 __THROWNL
__attribute__ ((__format__ (__printf__
, 3, 4)));
389 extern int vsnprintf (char *__restrict __s
, size_t __maxlen
,
390 const char *__restrict __format
, __gnuc_va_list __arg
)
391 __THROWNL
__attribute__ ((__format__ (__printf__
, 3, 0)));
394 #if defined (__USE_MISC) || __GLIBC_USE (LIB_EXT2)
395 /* Write formatted output to a string dynamically allocated with `malloc'.
396 Store the address of the string in *PTR. */
397 extern int vasprintf (char **__restrict __ptr
, const char *__restrict __f
,
398 __gnuc_va_list __arg
)
399 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 0))) __wur
;
400 extern int __asprintf (char **__restrict __ptr
,
401 const char *__restrict __fmt
, ...)
402 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 3))) __wur
;
403 extern int asprintf (char **__restrict __ptr
,
404 const char *__restrict __fmt
, ...)
405 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 3))) __wur
;
408 #ifdef __USE_XOPEN2K8
409 /* Write formatted output to a file descriptor. */
410 extern int vdprintf (int __fd
, const char *__restrict __fmt
,
411 __gnuc_va_list __arg
)
412 __attribute__ ((__format__ (__printf__
, 2, 0)));
413 extern int dprintf (int __fd
, const char *__restrict __fmt
, ...)
414 __attribute__ ((__format__ (__printf__
, 2, 3)));
418 /* Read formatted input from STREAM.
420 This function is a possible cancellation point and therefore not
421 marked with __THROW. */
422 extern int fscanf (FILE *__restrict __stream
,
423 const char *__restrict __format
, ...) __wur
__nonnull ((1));
424 /* Read formatted input from stdin.
426 This function is a possible cancellation point and therefore not
427 marked with __THROW. */
428 extern int scanf (const char *__restrict __format
, ...) __wur
;
429 /* Read formatted input from S. */
430 extern int sscanf (const char *__restrict __s
,
431 const char *__restrict __format
, ...) __THROW
;
433 /* For historical reasons, the C99-compliant versions of the scanf
434 functions are at alternative names. When __LDBL_COMPAT or
435 __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
436 bits/stdio-ldbl.h. */
437 #include <bits/floatn.h>
438 #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
439 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
440 # if __GLIBC_USE (C23_STRTOL)
442 extern int __REDIRECT (fscanf
, (FILE *__restrict __stream
,
443 const char *__restrict __format
, ...),
444 __isoc23_fscanf
) __wur
__nonnull ((1));
445 extern int __REDIRECT (scanf
, (const char *__restrict __format
, ...),
446 __isoc23_scanf
) __wur
;
447 extern int __REDIRECT_NTH (sscanf
, (const char *__restrict __s
,
448 const char *__restrict __format
, ...),
451 extern int __isoc23_fscanf (FILE *__restrict __stream
,
452 const char *__restrict __format
, ...) __wur
454 extern int __isoc23_scanf (const char *__restrict __format
, ...) __wur
;
455 extern int __isoc23_sscanf (const char *__restrict __s
,
456 const char *__restrict __format
, ...) __THROW
;
457 # define fscanf __isoc23_fscanf
458 # define scanf __isoc23_scanf
459 # define sscanf __isoc23_sscanf
463 extern int __REDIRECT (fscanf
, (FILE *__restrict __stream
,
464 const char *__restrict __format
, ...),
465 __isoc99_fscanf
) __wur
__nonnull ((1));
466 extern int __REDIRECT (scanf
, (const char *__restrict __format
, ...),
467 __isoc99_scanf
) __wur
;
468 extern int __REDIRECT_NTH (sscanf
, (const char *__restrict __s
,
469 const char *__restrict __format
, ...),
472 extern int __isoc99_fscanf (FILE *__restrict __stream
,
473 const char *__restrict __format
, ...) __wur
475 extern int __isoc99_scanf (const char *__restrict __format
, ...) __wur
;
476 extern int __isoc99_sscanf (const char *__restrict __s
,
477 const char *__restrict __format
, ...) __THROW
;
478 # define fscanf __isoc99_fscanf
479 # define scanf __isoc99_scanf
480 # define sscanf __isoc99_sscanf
486 /* Read formatted input from S into argument list ARG.
488 This function is a possible cancellation point and therefore not
489 marked with __THROW. */
490 extern int vfscanf (FILE *__restrict __s
, const char *__restrict __format
,
491 __gnuc_va_list __arg
)
492 __attribute__ ((__format__ (__scanf__
, 2, 0))) __wur
__nonnull ((1));
494 /* Read formatted input from stdin into argument list ARG.
496 This function is a possible cancellation point and therefore not
497 marked with __THROW. */
498 extern int vscanf (const char *__restrict __format
, __gnuc_va_list __arg
)
499 __attribute__ ((__format__ (__scanf__
, 1, 0))) __wur
;
501 /* Read formatted input from S into argument list ARG. */
502 extern int vsscanf (const char *__restrict __s
,
503 const char *__restrict __format
, __gnuc_va_list __arg
)
504 __THROW
__attribute__ ((__format__ (__scanf__
, 2, 0)));
506 /* Same redirection as above for the v*scanf family. */
507 # if !__GLIBC_USE (DEPRECATED_SCANF)
508 # if __GLIBC_USE (C23_STRTOL)
509 # if defined __REDIRECT && !defined __LDBL_COMPAT \
510 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
511 extern int __REDIRECT (vfscanf
,
512 (FILE *__restrict __s
,
513 const char *__restrict __format
, __gnuc_va_list __arg
),
515 __attribute__ ((__format__ (__scanf__
, 2, 0))) __wur
__nonnull ((1));
516 extern int __REDIRECT (vscanf
, (const char *__restrict __format
,
517 __gnuc_va_list __arg
), __isoc23_vscanf
)
518 __attribute__ ((__format__ (__scanf__
, 1, 0))) __wur
;
519 extern int __REDIRECT_NTH (vsscanf
,
520 (const char *__restrict __s
,
521 const char *__restrict __format
,
522 __gnuc_va_list __arg
), __isoc23_vsscanf
)
523 __attribute__ ((__format__ (__scanf__
, 2, 0)));
524 # elif !defined __REDIRECT
525 extern int __isoc23_vfscanf (FILE *__restrict __s
,
526 const char *__restrict __format
,
527 __gnuc_va_list __arg
) __wur
__nonnull ((1));
528 extern int __isoc23_vscanf (const char *__restrict __format
,
529 __gnuc_va_list __arg
) __wur
;
530 extern int __isoc23_vsscanf (const char *__restrict __s
,
531 const char *__restrict __format
,
532 __gnuc_va_list __arg
) __THROW
;
533 # define vfscanf __isoc23_vfscanf
534 # define vscanf __isoc23_vscanf
535 # define vsscanf __isoc23_vsscanf
538 # if defined __REDIRECT && !defined __LDBL_COMPAT \
539 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
540 extern int __REDIRECT (vfscanf
,
541 (FILE *__restrict __s
,
542 const char *__restrict __format
, __gnuc_va_list __arg
),
544 __attribute__ ((__format__ (__scanf__
, 2, 0))) __wur
__nonnull ((1));
545 extern int __REDIRECT (vscanf
, (const char *__restrict __format
,
546 __gnuc_va_list __arg
), __isoc99_vscanf
)
547 __attribute__ ((__format__ (__scanf__
, 1, 0))) __wur
;
548 extern int __REDIRECT_NTH (vsscanf
,
549 (const char *__restrict __s
,
550 const char *__restrict __format
,
551 __gnuc_va_list __arg
), __isoc99_vsscanf
)
552 __attribute__ ((__format__ (__scanf__
, 2, 0)));
553 # elif !defined __REDIRECT
554 extern int __isoc99_vfscanf (FILE *__restrict __s
,
555 const char *__restrict __format
,
556 __gnuc_va_list __arg
) __wur
__nonnull ((1));
557 extern int __isoc99_vscanf (const char *__restrict __format
,
558 __gnuc_va_list __arg
) __wur
;
559 extern int __isoc99_vsscanf (const char *__restrict __s
,
560 const char *__restrict __format
,
561 __gnuc_va_list __arg
) __THROW
;
562 # define vfscanf __isoc99_vfscanf
563 # define vscanf __isoc99_vscanf
564 # define vsscanf __isoc99_vsscanf
568 #endif /* Use ISO C9x. */
571 /* Read a character from STREAM.
573 These functions are possible cancellation points and therefore not
574 marked with __THROW. */
575 extern int fgetc (FILE *__stream
) __nonnull ((1));
576 extern int getc (FILE *__stream
) __nonnull ((1));
578 /* Read a character from stdin.
580 This function is a possible cancellation point and therefore not
581 marked with __THROW. */
582 extern int getchar (void);
584 #ifdef __USE_POSIX199506
585 /* These are defined in POSIX.1:1996.
587 These functions are possible cancellation points and therefore not
588 marked with __THROW. */
589 extern int getc_unlocked (FILE *__stream
) __nonnull ((1));
590 extern int getchar_unlocked (void);
591 #endif /* Use POSIX. */
594 /* Faster version when locking is not necessary.
596 This function is not part of POSIX and therefore no official
597 cancellation point. But due to similarity with an POSIX interface
598 or due to the implementation it is a cancellation point and
599 therefore not marked with __THROW. */
600 extern int fgetc_unlocked (FILE *__stream
) __nonnull ((1));
601 #endif /* Use MISC. */
604 /* Write a character to STREAM.
606 These functions are possible cancellation points and therefore not
609 These functions is a possible cancellation point and therefore not
610 marked with __THROW. */
611 extern int fputc (int __c
, FILE *__stream
) __nonnull ((2));
612 extern int putc (int __c
, FILE *__stream
) __nonnull ((2));
614 /* Write a character to stdout.
616 This function is a possible cancellation point and therefore not
617 marked with __THROW. */
618 extern int putchar (int __c
);
621 /* Faster version when locking is not necessary.
623 This function is not part of POSIX and therefore no official
624 cancellation point. But due to similarity with an POSIX interface
625 or due to the implementation it is a cancellation point and
626 therefore not marked with __THROW. */
627 extern int fputc_unlocked (int __c
, FILE *__stream
) __nonnull ((2));
628 #endif /* Use MISC. */
630 #ifdef __USE_POSIX199506
631 /* These are defined in POSIX.1:1996.
633 These functions are possible cancellation points and therefore not
634 marked with __THROW. */
635 extern int putc_unlocked (int __c
, FILE *__stream
) __nonnull ((2));
636 extern int putchar_unlocked (int __c
);
637 #endif /* Use POSIX. */
640 #if defined __USE_MISC \
641 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
642 /* Get a word (int) from STREAM. */
643 extern int getw (FILE *__stream
) __nonnull ((1));
645 /* Write a word (int) to STREAM. */
646 extern int putw (int __w
, FILE *__stream
) __nonnull ((2));
650 /* Get a newline-terminated string of finite length from STREAM.
652 This function is a possible cancellation point and therefore not
653 marked with __THROW. */
654 extern char *fgets (char *__restrict __s
, int __n
, FILE *__restrict __stream
)
655 __wur
__fortified_attr_access (__write_only__
, 1, 2) __nonnull ((3));
657 #if __GLIBC_USE (DEPRECATED_GETS)
658 /* Get a newline-terminated string from stdin, removing the newline.
660 This function is impossible to use safely. It has been officially
661 removed from ISO C11 and ISO C++14, and we have also removed it
662 from the _GNU_SOURCE feature list. It remains available when
663 explicitly using an old ISO C, Unix, or POSIX standard.
665 This function is a possible cancellation point and therefore not
666 marked with __THROW. */
667 extern char *gets (char *__s
) __wur __attribute_deprecated__
;
671 /* This function does the same as `fgets' but does not lock the stream.
673 This function is not part of POSIX and therefore no official
674 cancellation point. But due to similarity with an POSIX interface
675 or due to the implementation it is a cancellation point and
676 therefore not marked with __THROW. */
677 extern char *fgets_unlocked (char *__restrict __s
, int __n
,
678 FILE *__restrict __stream
) __wur
679 __fortified_attr_access (__write_only__
, 1, 2) __nonnull ((3));
683 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
684 /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
685 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
686 NULL), pointing to *N characters of space. It is realloc'd as
687 necessary. Returns the number of characters read (not including the
688 null terminator), or -1 on error or EOF. */
689 extern __ssize_t
__getdelim (char **__restrict __lineptr
,
690 size_t *__restrict __n
, int __delimiter
,
691 FILE *__restrict __stream
) __wur
__nonnull ((4));
692 extern __ssize_t
getdelim (char **__restrict __lineptr
,
693 size_t *__restrict __n
, int __delimiter
,
694 FILE *__restrict __stream
) __wur
__nonnull ((4));
696 /* Like `getdelim', but reads up to a newline. */
697 extern __ssize_t
getline (char **__restrict __lineptr
,
698 size_t *__restrict __n
,
699 FILE *__restrict __stream
) __wur
__nonnull ((3));
703 /* Write a string to STREAM.
705 This function is a possible cancellation point and therefore not
706 marked with __THROW. */
707 extern int fputs (const char *__restrict __s
, FILE *__restrict __stream
)
710 /* Write a string, followed by a newline, to stdout.
712 This function is a possible cancellation point and therefore not
713 marked with __THROW. */
714 extern int puts (const char *__s
);
717 /* Push a character back onto the input buffer of STREAM.
719 This function is a possible cancellation point and therefore not
720 marked with __THROW. */
721 extern int ungetc (int __c
, FILE *__stream
) __nonnull ((2));
724 /* Read chunks of generic data from STREAM.
726 This function is a possible cancellation point and therefore not
727 marked with __THROW. */
728 extern size_t fread (void *__restrict __ptr
, size_t __size
,
729 size_t __n
, FILE *__restrict __stream
) __wur
731 /* Write chunks of generic data to STREAM.
733 This function is a possible cancellation point and therefore not
734 marked with __THROW. */
735 extern size_t fwrite (const void *__restrict __ptr
, size_t __size
,
736 size_t __n
, FILE *__restrict __s
) __nonnull((4));
739 /* This function does the same as `fputs' but does not lock the stream.
741 This function is not part of POSIX and therefore no official
742 cancellation point. But due to similarity with an POSIX interface
743 or due to the implementation it is a cancellation point and
744 therefore not marked with __THROW. */
745 extern int fputs_unlocked (const char *__restrict __s
,
746 FILE *__restrict __stream
) __nonnull ((2));
750 /* Faster versions when locking is not necessary.
752 These functions are not part of POSIX and therefore no official
753 cancellation point. But due to similarity with an POSIX interface
754 or due to the implementation they are cancellation points and
755 therefore not marked with __THROW. */
756 extern size_t fread_unlocked (void *__restrict __ptr
, size_t __size
,
757 size_t __n
, FILE *__restrict __stream
) __wur
759 extern size_t fwrite_unlocked (const void *__restrict __ptr
, size_t __size
,
760 size_t __n
, FILE *__restrict __stream
)
765 /* Seek to a certain position on STREAM.
767 This function is a possible cancellation point and therefore not
768 marked with __THROW. */
769 extern int fseek (FILE *__stream
, long int __off
, int __whence
)
771 /* Return the current position of STREAM.
773 This function is a possible cancellation point and therefore not
774 marked with __THROW. */
775 extern long int ftell (FILE *__stream
) __wur
__nonnull ((1));
776 /* Rewind to the beginning of STREAM.
778 This function is a possible cancellation point and therefore not
779 marked with __THROW. */
780 extern void rewind (FILE *__stream
) __nonnull ((1));
782 /* The Single Unix Specification, Version 2, specifies an alternative,
783 more adequate interface for the two functions above which deal with
784 file offset. `long int' is not the right type. These definitions
785 are originally defined in the Large File Support API. */
787 #if defined __USE_LARGEFILE || defined __USE_XOPEN2K
788 # ifndef __USE_FILE_OFFSET64
789 /* Seek to a certain position on STREAM.
791 This function is a possible cancellation point and therefore not
792 marked with __THROW. */
793 extern int fseeko (FILE *__stream
, __off_t __off
, int __whence
)
795 /* Return the current position of STREAM.
797 This function is a possible cancellation point and therefore not
798 marked with __THROW. */
799 extern __off_t
ftello (FILE *__stream
) __wur
__nonnull ((1));
802 extern int __REDIRECT (fseeko
,
803 (FILE *__stream
, __off64_t __off
, int __whence
),
804 fseeko64
) __nonnull ((1));
805 extern __off64_t
__REDIRECT (ftello
, (FILE *__stream
), ftello64
)
808 # define fseeko fseeko64
809 # define ftello ftello64
814 #ifndef __USE_FILE_OFFSET64
815 /* Get STREAM's position.
817 This function is a possible cancellation point and therefore not
818 marked with __THROW. */
819 extern int fgetpos (FILE *__restrict __stream
, fpos_t *__restrict __pos
)
821 /* Set STREAM's position.
823 This function is a possible cancellation point and therefore not
824 marked with __THROW. */
825 extern int fsetpos (FILE *__stream
, const fpos_t *__pos
) __nonnull ((1));
828 extern int __REDIRECT (fgetpos
, (FILE *__restrict __stream
,
829 fpos_t *__restrict __pos
), fgetpos64
)
831 extern int __REDIRECT (fsetpos
,
832 (FILE *__stream
, const fpos_t *__pos
), fsetpos64
)
835 # define fgetpos fgetpos64
836 # define fsetpos fsetpos64
840 #ifdef __USE_LARGEFILE64
841 extern int fseeko64 (FILE *__stream
, __off64_t __off
, int __whence
)
843 extern __off64_t
ftello64 (FILE *__stream
) __wur
__nonnull ((1));
844 extern int fgetpos64 (FILE *__restrict __stream
, fpos64_t
*__restrict __pos
)
846 extern int fsetpos64 (FILE *__stream
, const fpos64_t
*__pos
) __nonnull ((1));
849 /* Clear the error and EOF indicators for STREAM. */
850 extern void clearerr (FILE *__stream
) __THROW
__nonnull ((1));
851 /* Return the EOF indicator for STREAM. */
852 extern int feof (FILE *__stream
) __THROW __wur
__nonnull ((1));
853 /* Return the error indicator for STREAM. */
854 extern int ferror (FILE *__stream
) __THROW __wur
__nonnull ((1));
857 /* Faster versions when locking is not required. */
858 extern void clearerr_unlocked (FILE *__stream
) __THROW
__nonnull ((1));
859 extern int feof_unlocked (FILE *__stream
) __THROW __wur
__nonnull ((1));
860 extern int ferror_unlocked (FILE *__stream
) __THROW __wur
__nonnull ((1));
864 /* Print a message describing the meaning of the value of errno.
866 This function is a possible cancellation point and therefore not
867 marked with __THROW. */
868 extern void perror (const char *__s
) __COLD
;
872 /* Return the system file descriptor for STREAM. */
873 extern int fileno (FILE *__stream
) __THROW __wur
__nonnull ((1));
874 #endif /* Use POSIX. */
877 /* Faster version when locking is not required. */
878 extern int fileno_unlocked (FILE *__stream
) __THROW __wur
__nonnull ((1));
883 /* Close a stream opened by popen and return the status of its child.
885 This function is a possible cancellation point and therefore not
886 marked with __THROW. */
887 extern int pclose (FILE *__stream
) __nonnull ((1));
889 /* Create a new stream connected to a pipe running the given command.
891 This function is a possible cancellation point and therefore not
892 marked with __THROW. */
893 extern FILE *popen (const char *__command
, const char *__modes
)
894 __attribute_malloc__
__attr_dealloc (pclose
, 1) __wur
;
900 /* Return the name of the controlling terminal. */
901 extern char *ctermid (char *__s
) __THROW
902 __attr_access ((__write_only__
, 1));
903 #endif /* Use POSIX. */
906 #if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
907 /* Return the name of the current user. */
908 extern char *cuserid (char *__s
)
909 __attr_access ((__write_only__
, 1));
910 #endif /* Use X/Open, but not issue 6. */
914 struct obstack
; /* See <obstack.h>. */
916 /* Write formatted output to an obstack. */
917 extern int obstack_printf (struct obstack
*__restrict __obstack
,
918 const char *__restrict __format
, ...)
919 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 3)));
920 extern int obstack_vprintf (struct obstack
*__restrict __obstack
,
921 const char *__restrict __format
,
922 __gnuc_va_list __args
)
923 __THROWNL
__attribute__ ((__format__ (__printf__
, 2, 0)));
924 #endif /* Use GNU. */
927 #ifdef __USE_POSIX199506
928 /* These are defined in POSIX.1:1996. */
930 /* Acquire ownership of STREAM. */
931 extern void flockfile (FILE *__stream
) __THROW
__nonnull ((1));
933 /* Try to acquire ownership of STREAM but do not block if it is not
935 extern int ftrylockfile (FILE *__stream
) __THROW __wur
__nonnull ((1));
937 /* Relinquish the ownership granted for STREAM. */
938 extern void funlockfile (FILE *__stream
) __THROW
__nonnull ((1));
941 #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
942 /* X/Open Issues 1-5 required getopt to be declared in this
943 header. It was removed in Issue 6. GNU follows Issue 6. */
944 # include <bits/getopt_posix.h>
947 /* Slow-path routines used by the optimized inline functions in
949 extern int __uflow (FILE *);
950 extern int __overflow (FILE *, int);
952 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
953 /* Declare all functions from bits/stdio2-decl.h first. */
954 # include <bits/stdio2-decl.h>
957 /* The following headers provide asm redirections. These redirections must
958 appear before the first usage of these functions, e.g. in bits/stdio.h. */
959 #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
960 # include <bits/stdio-ldbl.h>
963 /* If we are compiling with optimizing read this file. It contains
964 several optimizing inline functions and macros. */
965 #ifdef __USE_EXTERN_INLINES
966 # include <bits/stdio.h>
968 #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
969 /* Now include the function definitions and redirects too. */
970 # include <bits/stdio2.h>
975 #endif /* <stdio.h> included. */