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