1/* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
4
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.
9
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.
14
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/>. */
18
19/*
20 * ISO C99 Standard: 7.19 Input/output <stdio.h>
21 */
22
23#ifndef _STDIO_H
24#define _STDIO_H 1
25
26#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27#include <bits/libc-header-start.h>
28
29__BEGIN_DECLS
30
31#define __need_size_t
32#define __need_NULL
33#include <stddef.h>
34
35#define __need___va_list
36#include <stdarg.h>
37
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>
44
45#ifdef __USE_MISC
46# include <bits/types/cookie_io_functions_t.h>
47#endif
48
49#if defined __USE_XOPEN || defined __USE_XOPEN2K8
50# ifdef __GNUC__
51# ifndef _VA_LIST_DEFINED
52typedef __gnuc_va_list va_list;
53# define _VA_LIST_DEFINED
54# endif
55# else
56# include <stdarg.h>
57# endif
58#endif
59
60#if defined __USE_UNIX98 || defined __USE_XOPEN2K
61# ifndef __off_t_defined
62# ifndef __USE_FILE_OFFSET64
63typedef __off_t off_t;
64# else
65typedef __off64_t off_t;
66# endif
67# define __off_t_defined
68# endif
69# if defined __USE_LARGEFILE64 && !defined __off64_t_defined
70typedef __off64_t off64_t;
71# define __off64_t_defined
72# endif
73#endif
74
75#ifdef __USE_XOPEN2K8
76# ifndef __ssize_t_defined
77typedef __ssize_t ssize_t;
78# define __ssize_t_defined
79# endif
80#endif
81
82/* The type of the second argument to `fgetpos' and `fsetpos'. */
83#ifndef __USE_FILE_OFFSET64
84typedef __fpos_t fpos_t;
85#else
86typedef __fpos64_t fpos_t;
87#endif
88#ifdef __USE_LARGEFILE64
89typedef __fpos64_t fpos64_t;
90#endif
91
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. */
96
97
98/* Default buffer size. */
99#define BUFSIZ 8192
100
101
102/* The value returned by fgetc and similar functions to indicate the
103 end of the file. */
104#define EOF (-1)
105
106
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. */
112#ifdef __USE_GNU
113# define SEEK_DATA 3 /* Seek to next data. */
114# define SEEK_HOLE 4 /* Seek to next hole. */
115#endif
116
117
118#if defined __USE_MISC || defined __USE_XOPEN
119/* Default path prefix for `tempnam' and `tmpnam'. */
120# define P_tmpdir "/tmp"
121#endif
122
123#define L_tmpnam 20
124#define TMP_MAX 238328
125
126/* Get the values:
127 FILENAME_MAX Maximum length of a filename. */
128#include <bits/stdio_lim.h>
129
130#ifdef __USE_POSIX
131# define L_ctermid 9
132# if !defined __USE_XOPEN2K || defined __USE_GNU
133# define L_cuserid 9
134# endif
135#endif
136
137#undef FOPEN_MAX
138#define FOPEN_MAX 16
139
140
141#if __GLIBC_USE (ISOC2X)
142/* Maximum length of printf output for a NaN. */
143# define _PRINTF_NAN_LEN_MAX 4
144#endif
145
146
147/* Standard streams. */
148extern FILE *stdin; /* Standard input stream. */
149extern FILE *stdout; /* Standard output stream. */
150extern FILE *stderr; /* Standard error output stream. */
151/* C89/C99 say they're macros. Make them happy. */
152#define stdin stdin
153#define stdout stdout
154#define stderr stderr
155
156/* Remove file FILENAME. */
157extern int remove (const char *__filename) __THROW;
158/* Rename file OLD to NEW. */
159extern int rename (const char *__old, const char *__new) __THROW;
160
161#ifdef __USE_ATFILE
162/* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
163extern int renameat (int __oldfd, const char *__old, int __newfd,
164 const char *__new) __THROW;
165#endif
166
167#ifdef __USE_GNU
168/* Flags for renameat2. */
169# define RENAME_NOREPLACE (1 << 0)
170# define RENAME_EXCHANGE (1 << 1)
171# define RENAME_WHITEOUT (1 << 2)
172
173/* Rename file OLD relative to OLDFD to NEW relative to NEWFD, with
174 additional flags. */
175extern int renameat2 (int __oldfd, const char *__old, int __newfd,
176 const char *__new, unsigned int __flags) __THROW;
177#endif
178
179/* Close STREAM.
180
181 This function is a possible cancellation point and therefore not
182 marked with __THROW. */
183extern int fclose (FILE *__stream) __nonnull ((1));
184
185#undef __attr_dealloc_fclose
186#define __attr_dealloc_fclose __attr_dealloc (fclose, 1)
187
188/* Create a temporary file and open it read/write.
189
190 This function is a possible cancellation point and therefore not
191 marked with __THROW. */
192#ifndef __USE_FILE_OFFSET64
193extern FILE *tmpfile (void)
194 __attribute_malloc__ __attr_dealloc_fclose __wur;
195#else
196# ifdef __REDIRECT
197extern FILE *__REDIRECT (tmpfile, (void), tmpfile64)
198 __attribute_malloc__ __attr_dealloc_fclose __wur;
199# else
200# define tmpfile tmpfile64
201# endif
202#endif
203
204#ifdef __USE_LARGEFILE64
205extern FILE *tmpfile64 (void)
206 __attribute_malloc__ __attr_dealloc_fclose __wur;
207#endif
208
209/* Generate a temporary filename. */
210extern char *tmpnam (char[L_tmpnam]) __THROW __wur;
211
212#ifdef __USE_MISC
213/* This is the reentrant variant of `tmpnam'. The only difference is
214 that it does not allow S to be NULL. */
215extern char *tmpnam_r (char __s[L_tmpnam]) __THROW __wur;
216#endif
217
218
219#if defined __USE_MISC || defined __USE_XOPEN
220/* Generate a unique temporary filename using up to five characters of PFX
221 if it is not NULL. The directory to put this file in is searched for
222 as follows: First the environment variable "TMPDIR" is checked.
223 If it contains the name of a writable directory, that directory is used.
224 If not and if DIR is not NULL, that value is checked. If that fails,
225 P_tmpdir is tried and finally "/tmp". The storage for the filename
226 is allocated by `malloc'. */
227extern char *tempnam (const char *__dir, const char *__pfx)
228 __THROW __attribute_malloc__ __wur __attr_dealloc_free;
229#endif
230
231/* Flush STREAM, or all streams if STREAM is NULL.
232
233 This function is a possible cancellation point and therefore not
234 marked with __THROW. */
235extern int fflush (FILE *__stream);
236
237#ifdef __USE_MISC
238/* Faster versions when locking is not required.
239
240 This function is not part of POSIX and therefore no official
241 cancellation point. But due to similarity with an POSIX interface
242 or due to the implementation it is a cancellation point and
243 therefore not marked with __THROW. */
244extern int fflush_unlocked (FILE *__stream);
245#endif
246
247#ifdef __USE_GNU
248/* Close all streams.
249
250 This function is not part of POSIX and therefore no official
251 cancellation point. But due to similarity with an POSIX interface
252 or due to the implementation it is a cancellation point and
253 therefore not marked with __THROW. */
254extern int fcloseall (void);
255#endif
256
257
258#ifndef __USE_FILE_OFFSET64
259/* Open a file and create a new stream for it.
260
261 This function is a possible cancellation point and therefore not
262 marked with __THROW. */
263extern FILE *fopen (const char *__restrict __filename,
264 const char *__restrict __modes)
265 __attribute_malloc__ __attr_dealloc_fclose __wur;
266/* Open a file, replacing an existing stream with it.
267
268 This function is a possible cancellation point and therefore not
269 marked with __THROW. */
270extern FILE *freopen (const char *__restrict __filename,
271 const char *__restrict __modes,
272 FILE *__restrict __stream) __wur __nonnull ((3));
273#else
274# ifdef __REDIRECT
275extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
276 const char *__restrict __modes), fopen64)
277 __attribute_malloc__ __attr_dealloc_fclose __wur;
278extern FILE *__REDIRECT (freopen, (const char *__restrict __filename,
279 const char *__restrict __modes,
280 FILE *__restrict __stream), freopen64)
281 __wur;
282# else
283# define fopen fopen64
284# define freopen freopen64
285# endif
286#endif
287#ifdef __USE_LARGEFILE64
288extern FILE *fopen64 (const char *__restrict __filename,
289 const char *__restrict __modes)
290 __attribute_malloc__ __attr_dealloc_fclose __wur;
291extern FILE *freopen64 (const char *__restrict __filename,
292 const char *__restrict __modes,
293 FILE *__restrict __stream) __wur __nonnull ((3));
294#endif
295
296#ifdef __USE_POSIX
297/* Create a new stream that refers to an existing system file descriptor. */
298extern FILE *fdopen (int __fd, const char *__modes) __THROW
299 __attribute_malloc__ __attr_dealloc_fclose __wur;
300#endif
301
302#ifdef __USE_MISC
303/* Create a new stream that refers to the given magic cookie,
304 and uses the given functions for input and output. */
305extern FILE *fopencookie (void *__restrict __magic_cookie,
306 const char *__restrict __modes,
307 cookie_io_functions_t __io_funcs) __THROW
308 __attribute_malloc__ __attr_dealloc_fclose __wur;
309#endif
310
311#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
312/* Create a new stream that refers to a memory buffer. */
313extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
314 __THROW __attribute_malloc__ __attr_dealloc_fclose __wur;
315
316/* Open a stream that writes into a malloc'd buffer that is expanded as
317 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
318 and the number of characters written on fflush or fclose. */
319extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW
320 __attribute_malloc__ __attr_dealloc_fclose __wur;
321
322#ifdef _WCHAR_H
323/* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
324 a wide character string. Declared here only to add attribute malloc
325 and only if <wchar.h> has been previously #included. */
326extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW
327 __attribute_malloc__ __attr_dealloc_fclose;
328# endif
329#endif
330
331/* If BUF is NULL, make STREAM unbuffered.
332 Else make it use buffer BUF, of size BUFSIZ. */
333extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
334/* Make STREAM use buffering mode MODE.
335 If BUF is not NULL, use N bytes of it for buffering;
336 else allocate an internal buffer N bytes long. */
337extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
338 int __modes, size_t __n) __THROW;
339
340#ifdef __USE_MISC
341/* If BUF is NULL, make STREAM unbuffered.
342 Else make it use SIZE bytes of BUF for buffering. */
343extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
344 size_t __size) __THROW;
345
346/* Make STREAM line-buffered. */
347extern void setlinebuf (FILE *__stream) __THROW;
348#endif
349
350
351/* Write formatted output to STREAM.
352
353 This function is a possible cancellation point and therefore not
354 marked with __THROW. */
355extern int fprintf (FILE *__restrict __stream,
356 const char *__restrict __format, ...);
357/* Write formatted output to stdout.
358
359 This function is a possible cancellation point and therefore not
360 marked with __THROW. */
361extern int printf (const char *__restrict __format, ...);
362/* Write formatted output to S. */
363extern int sprintf (char *__restrict __s,
364 const char *__restrict __format, ...) __THROWNL;
365
366/* Write formatted output to S from argument list ARG.
367
368 This function is a possible cancellation point and therefore not
369 marked with __THROW. */
370extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
371 __gnuc_va_list __arg);
372/* Write formatted output to stdout from argument list ARG.
373
374 This function is a possible cancellation point and therefore not
375 marked with __THROW. */
376extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
377/* Write formatted output to S from argument list ARG. */
378extern int vsprintf (char *__restrict __s, const char *__restrict __format,
379 __gnuc_va_list __arg) __THROWNL;
380
381#if defined __USE_ISOC99 || defined __USE_UNIX98
382/* Maximum chars of output to write in MAXLEN. */
383extern int snprintf (char *__restrict __s, size_t __maxlen,
384 const char *__restrict __format, ...)
385 __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
386
387extern int vsnprintf (char *__restrict __s, size_t __maxlen,
388 const char *__restrict __format, __gnuc_va_list __arg)
389 __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
390#endif
391
392#if defined (__USE_MISC) || __GLIBC_USE (LIB_EXT2)
393/* Write formatted output to a string dynamically allocated with `malloc'.
394 Store the address of the string in *PTR. */
395extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
396 __gnuc_va_list __arg)
397 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
398extern int __asprintf (char **__restrict __ptr,
399 const char *__restrict __fmt, ...)
400 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
401extern int asprintf (char **__restrict __ptr,
402 const char *__restrict __fmt, ...)
403 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
404#endif
405
406#ifdef __USE_XOPEN2K8
407/* Write formatted output to a file descriptor. */
408extern int vdprintf (int __fd, const char *__restrict __fmt,
409 __gnuc_va_list __arg)
410 __attribute__ ((__format__ (__printf__, 2, 0)));
411extern int dprintf (int __fd, const char *__restrict __fmt, ...)
412 __attribute__ ((__format__ (__printf__, 2, 3)));
413#endif
414
415
416/* Read formatted input from STREAM.
417
418 This function is a possible cancellation point and therefore not
419 marked with __THROW. */
420extern int fscanf (FILE *__restrict __stream,
421 const char *__restrict __format, ...) __wur;
422/* Read formatted input from stdin.
423
424 This function is a possible cancellation point and therefore not
425 marked with __THROW. */
426extern int scanf (const char *__restrict __format, ...) __wur;
427/* Read formatted input from S. */
428extern int sscanf (const char *__restrict __s,
429 const char *__restrict __format, ...) __THROW;
430
431/* For historical reasons, the C99-compliant versions of the scanf
432 functions are at alternative names. When __LDBL_COMPAT or
433 __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
434 bits/stdio-ldbl.h. */
435#include <bits/floatn.h>
436#if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
437 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
438# if __GLIBC_USE (C2X_STRTOL)
439# ifdef __REDIRECT
440extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
441 const char *__restrict __format, ...),
442 __isoc23_fscanf) __wur;
443extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
444 __isoc23_scanf) __wur;
445extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
446 const char *__restrict __format, ...),
447 __isoc23_sscanf);
448# else
449extern int __isoc23_fscanf (FILE *__restrict __stream,
450 const char *__restrict __format, ...) __wur;
451extern int __isoc23_scanf (const char *__restrict __format, ...) __wur;
452extern int __isoc23_sscanf (const char *__restrict __s,
453 const char *__restrict __format, ...) __THROW;
454# define fscanf __isoc23_fscanf
455# define scanf __isoc23_scanf
456# define sscanf __isoc23_sscanf
457# endif
458# else
459# ifdef __REDIRECT
460extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
461 const char *__restrict __format, ...),
462 __isoc99_fscanf) __wur;
463extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
464 __isoc99_scanf) __wur;
465extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
466 const char *__restrict __format, ...),
467 __isoc99_sscanf);
468# else
469extern int __isoc99_fscanf (FILE *__restrict __stream,
470 const char *__restrict __format, ...) __wur;
471extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
472extern int __isoc99_sscanf (const char *__restrict __s,
473 const char *__restrict __format, ...) __THROW;
474# define fscanf __isoc99_fscanf
475# define scanf __isoc99_scanf
476# define sscanf __isoc99_sscanf
477# endif
478# endif
479#endif
480
481#ifdef __USE_ISOC99
482/* Read formatted input from S into argument list ARG.
483
484 This function is a possible cancellation point and therefore not
485 marked with __THROW. */
486extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
487 __gnuc_va_list __arg)
488 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
489
490/* Read formatted input from stdin into argument list ARG.
491
492 This function is a possible cancellation point and therefore not
493 marked with __THROW. */
494extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
495 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
496
497/* Read formatted input from S into argument list ARG. */
498extern int vsscanf (const char *__restrict __s,
499 const char *__restrict __format, __gnuc_va_list __arg)
500 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
501
502/* Same redirection as above for the v*scanf family. */
503# if !__GLIBC_USE (DEPRECATED_SCANF)
504# if __GLIBC_USE (C2X_STRTOL)
505# if defined __REDIRECT && !defined __LDBL_COMPAT \
506 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
507extern int __REDIRECT (vfscanf,
508 (FILE *__restrict __s,
509 const char *__restrict __format, __gnuc_va_list __arg),
510 __isoc23_vfscanf)
511 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
512extern int __REDIRECT (vscanf, (const char *__restrict __format,
513 __gnuc_va_list __arg), __isoc23_vscanf)
514 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
515extern int __REDIRECT_NTH (vsscanf,
516 (const char *__restrict __s,
517 const char *__restrict __format,
518 __gnuc_va_list __arg), __isoc23_vsscanf)
519 __attribute__ ((__format__ (__scanf__, 2, 0)));
520# elif !defined __REDIRECT
521extern int __isoc23_vfscanf (FILE *__restrict __s,
522 const char *__restrict __format,
523 __gnuc_va_list __arg) __wur;
524extern int __isoc23_vscanf (const char *__restrict __format,
525 __gnuc_va_list __arg) __wur;
526extern int __isoc23_vsscanf (const char *__restrict __s,
527 const char *__restrict __format,
528 __gnuc_va_list __arg) __THROW;
529# define vfscanf __isoc23_vfscanf
530# define vscanf __isoc23_vscanf
531# define vsscanf __isoc23_vsscanf
532# endif
533# else
534# if defined __REDIRECT && !defined __LDBL_COMPAT \
535 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
536extern int __REDIRECT (vfscanf,
537 (FILE *__restrict __s,
538 const char *__restrict __format, __gnuc_va_list __arg),
539 __isoc99_vfscanf)
540 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
541extern int __REDIRECT (vscanf, (const char *__restrict __format,
542 __gnuc_va_list __arg), __isoc99_vscanf)
543 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
544extern int __REDIRECT_NTH (vsscanf,
545 (const char *__restrict __s,
546 const char *__restrict __format,
547 __gnuc_va_list __arg), __isoc99_vsscanf)
548 __attribute__ ((__format__ (__scanf__, 2, 0)));
549# elif !defined __REDIRECT
550extern int __isoc99_vfscanf (FILE *__restrict __s,
551 const char *__restrict __format,
552 __gnuc_va_list __arg) __wur;
553extern int __isoc99_vscanf (const char *__restrict __format,
554 __gnuc_va_list __arg) __wur;
555extern int __isoc99_vsscanf (const char *__restrict __s,
556 const char *__restrict __format,
557 __gnuc_va_list __arg) __THROW;
558# define vfscanf __isoc99_vfscanf
559# define vscanf __isoc99_vscanf
560# define vsscanf __isoc99_vsscanf
561# endif
562# endif
563# endif
564#endif /* Use ISO C9x. */
565
566
567/* Read a character from STREAM.
568
569 These functions are possible cancellation points and therefore not
570 marked with __THROW. */
571extern int fgetc (FILE *__stream);
572extern int getc (FILE *__stream);
573
574/* Read a character from stdin.
575
576 This function is a possible cancellation point and therefore not
577 marked with __THROW. */
578extern int getchar (void);
579
580#ifdef __USE_POSIX199506
581/* These are defined in POSIX.1:1996.
582
583 These functions are possible cancellation points and therefore not
584 marked with __THROW. */
585extern int getc_unlocked (FILE *__stream);
586extern int getchar_unlocked (void);
587#endif /* Use POSIX. */
588
589#ifdef __USE_MISC
590/* Faster version when locking is not necessary.
591
592 This function is not part of POSIX and therefore no official
593 cancellation point. But due to similarity with an POSIX interface
594 or due to the implementation it is a cancellation point and
595 therefore not marked with __THROW. */
596extern int fgetc_unlocked (FILE *__stream);
597#endif /* Use MISC. */
598
599
600/* Write a character to STREAM.
601
602 These functions are possible cancellation points and therefore not
603 marked with __THROW.
604
605 These functions is a possible cancellation point and therefore not
606 marked with __THROW. */
607extern int fputc (int __c, FILE *__stream);
608extern int putc (int __c, FILE *__stream);
609
610/* Write a character to stdout.
611
612 This function is a possible cancellation point and therefore not
613 marked with __THROW. */
614extern int putchar (int __c);
615
616#ifdef __USE_MISC
617/* Faster version when locking is not necessary.
618
619 This function is not part of POSIX and therefore no official
620 cancellation point. But due to similarity with an POSIX interface
621 or due to the implementation it is a cancellation point and
622 therefore not marked with __THROW. */
623extern int fputc_unlocked (int __c, FILE *__stream);
624#endif /* Use MISC. */
625
626#ifdef __USE_POSIX199506
627/* These are defined in POSIX.1:1996.
628
629 These functions are possible cancellation points and therefore not
630 marked with __THROW. */
631extern int putc_unlocked (int __c, FILE *__stream);
632extern int putchar_unlocked (int __c);
633#endif /* Use POSIX. */
634
635
636#if defined __USE_MISC \
637 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
638/* Get a word (int) from STREAM. */
639extern int getw (FILE *__stream);
640
641/* Write a word (int) to STREAM. */
642extern int putw (int __w, FILE *__stream);
643#endif
644
645
646/* Get a newline-terminated string of finite length from STREAM.
647
648 This function is a possible cancellation point and therefore not
649 marked with __THROW. */
650extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
651 __wur __fortified_attr_access (__write_only__, 1, 2);
652
653#if __GLIBC_USE (DEPRECATED_GETS)
654/* Get a newline-terminated string from stdin, removing the newline.
655
656 This function is impossible to use safely. It has been officially
657 removed from ISO C11 and ISO C++14, and we have also removed it
658 from the _GNU_SOURCE feature list. It remains available when
659 explicitly using an old ISO C, Unix, or POSIX standard.
660
661 This function is a possible cancellation point and therefore not
662 marked with __THROW. */
663extern char *gets (char *__s) __wur __attribute_deprecated__;
664#endif
665
666#ifdef __USE_GNU
667/* This function does the same as `fgets' but does not lock the stream.
668
669 This function is not part of POSIX and therefore no official
670 cancellation point. But due to similarity with an POSIX interface
671 or due to the implementation it is a cancellation point and
672 therefore not marked with __THROW. */
673extern char *fgets_unlocked (char *__restrict __s, int __n,
674 FILE *__restrict __stream) __wur
675 __fortified_attr_access (__write_only__, 1, 2);
676#endif
677
678
679#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
680/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
681 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
682 NULL), pointing to *N characters of space. It is realloc'd as
683 necessary. Returns the number of characters read (not including the
684 null terminator), or -1 on error or EOF.
685
686 These functions are not part of POSIX and therefore no official
687 cancellation point. But due to similarity with an POSIX interface
688 or due to the implementation they are cancellation points and
689 therefore not marked with __THROW. */
690extern __ssize_t __getdelim (char **__restrict __lineptr,
691 size_t *__restrict __n, int __delimiter,
692 FILE *__restrict __stream) __wur;
693extern __ssize_t getdelim (char **__restrict __lineptr,
694 size_t *__restrict __n, int __delimiter,
695 FILE *__restrict __stream) __wur;
696
697/* Like `getdelim', but reads up to a newline.
698
699 This function is not part of POSIX and therefore no official
700 cancellation point. But due to similarity with an POSIX interface
701 or due to the implementation it is a cancellation point and
702 therefore not marked with __THROW. */
703extern __ssize_t getline (char **__restrict __lineptr,
704 size_t *__restrict __n,
705 FILE *__restrict __stream) __wur;
706#endif
707
708
709/* Write a string to STREAM.
710
711 This function is a possible cancellation point and therefore not
712 marked with __THROW. */
713extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
714
715/* Write a string, followed by a newline, to stdout.
716
717 This function is a possible cancellation point and therefore not
718 marked with __THROW. */
719extern int puts (const char *__s);
720
721
722/* Push a character back onto the input buffer of STREAM.
723
724 This function is a possible cancellation point and therefore not
725 marked with __THROW. */
726extern int ungetc (int __c, FILE *__stream);
727
728
729/* Read chunks of generic data from STREAM.
730
731 This function is a possible cancellation point and therefore not
732 marked with __THROW. */
733extern size_t fread (void *__restrict __ptr, size_t __size,
734 size_t __n, FILE *__restrict __stream) __wur;
735/* Write chunks of generic data to STREAM.
736
737 This function is a possible cancellation point and therefore not
738 marked with __THROW. */
739extern size_t fwrite (const void *__restrict __ptr, size_t __size,
740 size_t __n, FILE *__restrict __s);
741
742#ifdef __USE_GNU
743/* This function does the same as `fputs' but does not lock the stream.
744
745 This function is not part of POSIX and therefore no official
746 cancellation point. But due to similarity with an POSIX interface
747 or due to the implementation it is a cancellation point and
748 therefore not marked with __THROW. */
749extern int fputs_unlocked (const char *__restrict __s,
750 FILE *__restrict __stream);
751#endif
752
753#ifdef __USE_MISC
754/* Faster versions when locking is not necessary.
755
756 These functions are not part of POSIX and therefore no official
757 cancellation point. But due to similarity with an POSIX interface
758 or due to the implementation they are cancellation points and
759 therefore not marked with __THROW. */
760extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
761 size_t __n, FILE *__restrict __stream) __wur;
762extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
763 size_t __n, FILE *__restrict __stream);
764#endif
765
766
767/* Seek to a certain position on STREAM.
768
769 This function is a possible cancellation point and therefore not
770 marked with __THROW. */
771extern int fseek (FILE *__stream, long int __off, int __whence);
772/* Return the current position of STREAM.
773
774 This function is a possible cancellation point and therefore not
775 marked with __THROW. */
776extern long int ftell (FILE *__stream) __wur;
777/* Rewind to the beginning of STREAM.
778
779 This function is a possible cancellation point and therefore not
780 marked with __THROW. */
781extern void rewind (FILE *__stream);
782
783/* The Single Unix Specification, Version 2, specifies an alternative,
784 more adequate interface for the two functions above which deal with
785 file offset. `long int' is not the right type. These definitions
786 are originally defined in the Large File Support API. */
787
788#if defined __USE_LARGEFILE || defined __USE_XOPEN2K
789# ifndef __USE_FILE_OFFSET64
790/* Seek to a certain position on STREAM.
791
792 This function is a possible cancellation point and therefore not
793 marked with __THROW. */
794extern int fseeko (FILE *__stream, __off_t __off, int __whence);
795/* Return the current position of STREAM.
796
797 This function is a possible cancellation point and therefore not
798 marked with __THROW. */
799extern __off_t ftello (FILE *__stream) __wur;
800# else
801# ifdef __REDIRECT
802extern int __REDIRECT (fseeko,
803 (FILE *__stream, __off64_t __off, int __whence),
804 fseeko64);
805extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64);
806# else
807# define fseeko fseeko64
808# define ftello ftello64
809# endif
810# endif
811#endif
812
813#ifndef __USE_FILE_OFFSET64
814/* Get STREAM's position.
815
816 This function is a possible cancellation point and therefore not
817 marked with __THROW. */
818extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
819/* Set STREAM's position.
820
821 This function is a possible cancellation point and therefore not
822 marked with __THROW. */
823extern int fsetpos (FILE *__stream, const fpos_t *__pos);
824#else
825# ifdef __REDIRECT
826extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
827 fpos_t *__restrict __pos), fgetpos64);
828extern int __REDIRECT (fsetpos,
829 (FILE *__stream, const fpos_t *__pos), fsetpos64);
830# else
831# define fgetpos fgetpos64
832# define fsetpos fsetpos64
833# endif
834#endif
835
836#ifdef __USE_LARGEFILE64
837extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
838extern __off64_t ftello64 (FILE *__stream) __wur;
839extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
840extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
841#endif
842
843/* Clear the error and EOF indicators for STREAM. */
844extern void clearerr (FILE *__stream) __THROW;
845/* Return the EOF indicator for STREAM. */
846extern int feof (FILE *__stream) __THROW __wur;
847/* Return the error indicator for STREAM. */
848extern int ferror (FILE *__stream) __THROW __wur;
849
850#ifdef __USE_MISC
851/* Faster versions when locking is not required. */
852extern void clearerr_unlocked (FILE *__stream) __THROW;
853extern int feof_unlocked (FILE *__stream) __THROW __wur;
854extern int ferror_unlocked (FILE *__stream) __THROW __wur;
855#endif
856
857
858/* Print a message describing the meaning of the value of errno.
859
860 This function is a possible cancellation point and therefore not
861 marked with __THROW. */
862extern void perror (const char *__s) __COLD;
863
864
865#ifdef __USE_POSIX
866/* Return the system file descriptor for STREAM. */
867extern int fileno (FILE *__stream) __THROW __wur;
868#endif /* Use POSIX. */
869
870#ifdef __USE_MISC
871/* Faster version when locking is not required. */
872extern int fileno_unlocked (FILE *__stream) __THROW __wur;
873#endif
874
875
876#ifdef __USE_POSIX2
877/* Close a stream opened by popen and return the status of its child.
878
879 This function is a possible cancellation point and therefore not
880 marked with __THROW. */
881extern int pclose (FILE *__stream);
882
883/* Create a new stream connected to a pipe running the given command.
884
885 This function is a possible cancellation point and therefore not
886 marked with __THROW. */
887extern FILE *popen (const char *__command, const char *__modes)
888 __attribute_malloc__ __attr_dealloc (pclose, 1) __wur;
889
890#endif
891
892
893#ifdef __USE_POSIX
894/* Return the name of the controlling terminal. */
895extern char *ctermid (char *__s) __THROW
896 __attr_access ((__write_only__, 1));
897#endif /* Use POSIX. */
898
899
900#if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
901/* Return the name of the current user. */
902extern char *cuserid (char *__s)
903 __attr_access ((__write_only__, 1));
904#endif /* Use X/Open, but not issue 6. */
905
906
907#ifdef __USE_GNU
908struct obstack; /* See <obstack.h>. */
909
910/* Write formatted output to an obstack. */
911extern int obstack_printf (struct obstack *__restrict __obstack,
912 const char *__restrict __format, ...)
913 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
914extern int obstack_vprintf (struct obstack *__restrict __obstack,
915 const char *__restrict __format,
916 __gnuc_va_list __args)
917 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
918#endif /* Use GNU. */
919
920
921#ifdef __USE_POSIX199506
922/* These are defined in POSIX.1:1996. */
923
924/* Acquire ownership of STREAM. */
925extern void flockfile (FILE *__stream) __THROW;
926
927/* Try to acquire ownership of STREAM but do not block if it is not
928 possible. */
929extern int ftrylockfile (FILE *__stream) __THROW __wur;
930
931/* Relinquish the ownership granted for STREAM. */
932extern void funlockfile (FILE *__stream) __THROW;
933#endif /* POSIX */
934
935#if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
936/* X/Open Issues 1-5 required getopt to be declared in this
937 header. It was removed in Issue 6. GNU follows Issue 6. */
938# include <bits/getopt_posix.h>
939#endif
940
941/* Slow-path routines used by the optimized inline functions in
942 bits/stdio.h. */
943extern int __uflow (FILE *);
944extern int __overflow (FILE *, int);
945
946#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
947/* Declare all functions from bits/stdio2-decl.h first. */
948# include <bits/stdio2-decl.h>
949#endif
950
951/* The following headers provide asm redirections. These redirections must
952 appear before the first usage of these functions, e.g. in bits/stdio.h. */
953#if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
954# include <bits/stdio-ldbl.h>
955#endif
956
957/* If we are compiling with optimizing read this file. It contains
958 several optimizing inline functions and macros. */
959#ifdef __USE_EXTERN_INLINES
960# include <bits/stdio.h>
961#endif
962#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
963/* Now include the function definitions and redirects too. */
964# include <bits/stdio2.h>
965#endif
966
967__END_DECLS
968
969#endif /* <stdio.h> included. */
970