1/* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2025 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 (ISOC23)
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 AT_RENAME_NOREPLACE 0x0001
172# define RENAME_EXCHANGE (1 << 1)
173# define AT_RENAME_EXCHANGE 0x0002
174# define RENAME_WHITEOUT (1 << 2)
175# define AT_RENAME_WHITEOUT 0x0004
176
177/* Rename file OLD relative to OLDFD to NEW relative to NEWFD, with
178 additional flags. */
179extern int renameat2 (int __oldfd, const char *__old, int __newfd,
180 const char *__new, unsigned int __flags) __THROW;
181#endif
182
183/* Close STREAM.
184
185 This function is a possible cancellation point and therefore not
186 marked with __THROW. */
187extern int fclose (FILE *__stream) __nonnull ((1));
188
189#undef __attr_dealloc_fclose
190#define __attr_dealloc_fclose __attr_dealloc (fclose, 1)
191
192/* Create a temporary file and open it read/write.
193
194 This function is a possible cancellation point and therefore not
195 marked with __THROW. */
196#ifndef __USE_FILE_OFFSET64
197extern FILE *tmpfile (void)
198 __attribute_malloc__ __attr_dealloc_fclose __wur;
199#else
200# ifdef __REDIRECT
201extern FILE *__REDIRECT (tmpfile, (void), tmpfile64)
202 __attribute_malloc__ __attr_dealloc_fclose __wur;
203# else
204# define tmpfile tmpfile64
205# endif
206#endif
207
208#ifdef __USE_LARGEFILE64
209extern FILE *tmpfile64 (void)
210 __attribute_malloc__ __attr_dealloc_fclose __wur;
211#endif
212
213/* Generate a temporary filename. */
214extern char *tmpnam (char[L_tmpnam]) __THROW __wur;
215
216#ifdef __USE_MISC
217/* This is the reentrant variant of `tmpnam'. The only difference is
218 that it does not allow S to be NULL. */
219extern char *tmpnam_r (char __s[L_tmpnam]) __THROW __wur;
220#endif
221
222
223#if defined __USE_MISC || defined __USE_XOPEN
224/* Generate a unique temporary filename using up to five characters of PFX
225 if it is not NULL. The directory to put this file in is searched for
226 as follows: First the environment variable "TMPDIR" is checked.
227 If it contains the name of a writable directory, that directory is used.
228 If not and if DIR is not NULL, that value is checked. If that fails,
229 P_tmpdir is tried and finally "/tmp". The storage for the filename
230 is allocated by `malloc'. */
231extern char *tempnam (const char *__dir, const char *__pfx)
232 __THROW __attribute_malloc__ __wur __attr_dealloc_free;
233#endif
234
235/* Flush STREAM, or all streams if STREAM is NULL.
236
237 This function is a possible cancellation point and therefore not
238 marked with __THROW. */
239extern int fflush (FILE *__stream);
240
241#ifdef __USE_MISC
242/* Faster versions when locking is not required.
243
244 This function is not part of POSIX and therefore no official
245 cancellation point. But due to similarity with an POSIX interface
246 or due to the implementation it is a cancellation point and
247 therefore not marked with __THROW. */
248extern int fflush_unlocked (FILE *__stream);
249#endif
250
251#ifdef __USE_GNU
252/* Close all streams.
253
254 This function is not part of POSIX and therefore no official
255 cancellation point. But due to similarity with an POSIX interface
256 or due to the implementation it is a cancellation point and
257 therefore not marked with __THROW. */
258extern int fcloseall (void);
259#endif
260
261
262#ifndef __USE_FILE_OFFSET64
263/* Open a file and create a new stream for it.
264
265 This function is a possible cancellation point and therefore not
266 marked with __THROW. */
267extern FILE *fopen (const char *__restrict __filename,
268 const char *__restrict __modes)
269 __attribute_malloc__ __attr_dealloc_fclose __wur;
270/* Open a file, replacing an existing stream with it.
271
272 This function is a possible cancellation point and therefore not
273 marked with __THROW. */
274extern FILE *freopen (const char *__restrict __filename,
275 const char *__restrict __modes,
276 FILE *__restrict __stream) __wur __nonnull ((3));
277#else
278# ifdef __REDIRECT
279extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
280 const char *__restrict __modes), fopen64)
281 __attribute_malloc__ __attr_dealloc_fclose __wur;
282extern FILE *__REDIRECT (freopen, (const char *__restrict __filename,
283 const char *__restrict __modes,
284 FILE *__restrict __stream), freopen64)
285 __wur __nonnull ((3));
286# else
287# define fopen fopen64
288# define freopen freopen64
289# endif
290#endif
291#ifdef __USE_LARGEFILE64
292extern FILE *fopen64 (const char *__restrict __filename,
293 const char *__restrict __modes)
294 __attribute_malloc__ __attr_dealloc_fclose __wur;
295extern FILE *freopen64 (const char *__restrict __filename,
296 const char *__restrict __modes,
297 FILE *__restrict __stream) __wur __nonnull ((3));
298#endif
299
300#ifdef __USE_POSIX
301/* Create a new stream that refers to an existing system file descriptor. */
302extern FILE *fdopen (int __fd, const char *__modes) __THROW
303 __attribute_malloc__ __attr_dealloc_fclose __wur;
304#endif
305
306#ifdef __USE_MISC
307/* Create a new stream that refers to the given magic cookie,
308 and uses the given functions for input and output. */
309extern FILE *fopencookie (void *__restrict __magic_cookie,
310 const char *__restrict __modes,
311 cookie_io_functions_t __io_funcs) __THROW
312 __attribute_malloc__ __attr_dealloc_fclose __wur;
313#endif
314
315#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
316/* Create a new stream that refers to a memory buffer. */
317extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
318 __THROW __attribute_malloc__ __attr_dealloc_fclose __wur;
319
320/* Open a stream that writes into a malloc'd buffer that is expanded as
321 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
322 and the number of characters written on fflush or fclose. */
323extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW
324 __attribute_malloc__ __attr_dealloc_fclose __wur;
325
326#ifdef _WCHAR_H
327/* Like OPEN_MEMSTREAM, but the stream is wide oriented and produces
328 a wide character string. Declared here only to add attribute malloc
329 and only if <wchar.h> has been previously #included. */
330extern __FILE *open_wmemstream (wchar_t **__bufloc, size_t *__sizeloc) __THROW
331 __attribute_malloc__ __attr_dealloc_fclose;
332# endif
333#endif
334
335/* If BUF is NULL, make STREAM unbuffered.
336 Else make it use buffer BUF, of size BUFSIZ. */
337extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW
338 __nonnull ((1));
339/* Make STREAM use buffering mode MODE.
340 If BUF is not NULL, use N bytes of it for buffering;
341 else allocate an internal buffer N bytes long. */
342extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
343 int __modes, size_t __n) __THROW __nonnull ((1));
344
345#ifdef __USE_MISC
346/* If BUF is NULL, make STREAM unbuffered.
347 Else make it use SIZE bytes of BUF for buffering. */
348extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
349 size_t __size) __THROW __nonnull ((1));
350
351/* Make STREAM line-buffered. */
352extern void setlinebuf (FILE *__stream) __THROW __nonnull ((1));
353#endif
354
355
356/* Write formatted output to STREAM.
357
358 This function is a possible cancellation point and therefore not
359 marked with __THROW. */
360extern int fprintf (FILE *__restrict __stream,
361 const char *__restrict __format, ...) __nonnull ((1));
362/* Write formatted output to stdout.
363
364 This function is a possible cancellation point and therefore not
365 marked with __THROW. */
366extern int printf (const char *__restrict __format, ...);
367/* Write formatted output to S. */
368extern int sprintf (char *__restrict __s,
369 const char *__restrict __format, ...) __THROWNL;
370
371/* Write formatted output to S from argument list ARG.
372
373 This function is a possible cancellation point and therefore not
374 marked with __THROW. */
375extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
376 __gnuc_va_list __arg) __nonnull ((1));
377/* Write formatted output to stdout from argument list ARG.
378
379 This function is a possible cancellation point and therefore not
380 marked with __THROW. */
381extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
382/* Write formatted output to S from argument list ARG. */
383extern int vsprintf (char *__restrict __s, const char *__restrict __format,
384 __gnuc_va_list __arg) __THROWNL;
385
386#if defined __USE_ISOC99 || defined __USE_UNIX98
387/* Maximum chars of output to write in MAXLEN. */
388extern int snprintf (char *__restrict __s, size_t __maxlen,
389 const char *__restrict __format, ...)
390 __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
391
392extern int vsnprintf (char *__restrict __s, size_t __maxlen,
393 const char *__restrict __format, __gnuc_va_list __arg)
394 __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
395#endif
396
397#if defined (__USE_MISC) || __GLIBC_USE (LIB_EXT2)
398/* Write formatted output to a string dynamically allocated with `malloc'.
399 Store the address of the string in *PTR. */
400extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
401 __gnuc_va_list __arg)
402 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
403extern int __asprintf (char **__restrict __ptr,
404 const char *__restrict __fmt, ...)
405 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
406extern int asprintf (char **__restrict __ptr,
407 const char *__restrict __fmt, ...)
408 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
409#endif
410
411#ifdef __USE_XOPEN2K8
412/* Write formatted output to a file descriptor. */
413extern int vdprintf (int __fd, const char *__restrict __fmt,
414 __gnuc_va_list __arg)
415 __attribute__ ((__format__ (__printf__, 2, 0)));
416extern int dprintf (int __fd, const char *__restrict __fmt, ...)
417 __attribute__ ((__format__ (__printf__, 2, 3)));
418#endif
419
420
421/* Read formatted input from STREAM.
422
423 This function is a possible cancellation point and therefore not
424 marked with __THROW. */
425extern int fscanf (FILE *__restrict __stream,
426 const char *__restrict __format, ...) __wur __nonnull ((1));
427/* Read formatted input from stdin.
428
429 This function is a possible cancellation point and therefore not
430 marked with __THROW. */
431extern int scanf (const char *__restrict __format, ...) __wur;
432/* Read formatted input from S. */
433extern int sscanf (const char *__restrict __s,
434 const char *__restrict __format, ...) __THROW;
435
436/* For historical reasons, the C99-compliant versions of the scanf
437 functions are at alternative names. When __LDBL_COMPAT or
438 __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
439 bits/stdio-ldbl.h. */
440#include <bits/floatn.h>
441#if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
442 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
443# if __GLIBC_USE (C23_STRTOL)
444# ifdef __REDIRECT
445extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
446 const char *__restrict __format, ...),
447 __isoc23_fscanf) __wur __nonnull ((1));
448extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
449 __isoc23_scanf) __wur;
450extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
451 const char *__restrict __format, ...),
452 __isoc23_sscanf);
453# else
454extern int __isoc23_fscanf (FILE *__restrict __stream,
455 const char *__restrict __format, ...) __wur
456 __nonnull ((1));
457extern int __isoc23_scanf (const char *__restrict __format, ...) __wur;
458extern int __isoc23_sscanf (const char *__restrict __s,
459 const char *__restrict __format, ...) __THROW;
460# define fscanf __isoc23_fscanf
461# define scanf __isoc23_scanf
462# define sscanf __isoc23_sscanf
463# endif
464# else
465# ifdef __REDIRECT
466extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
467 const char *__restrict __format, ...),
468 __isoc99_fscanf) __wur __nonnull ((1));
469extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
470 __isoc99_scanf) __wur;
471extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
472 const char *__restrict __format, ...),
473 __isoc99_sscanf);
474# else
475extern int __isoc99_fscanf (FILE *__restrict __stream,
476 const char *__restrict __format, ...) __wur
477 __nonnull ((1));
478extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
479extern int __isoc99_sscanf (const char *__restrict __s,
480 const char *__restrict __format, ...) __THROW;
481# define fscanf __isoc99_fscanf
482# define scanf __isoc99_scanf
483# define sscanf __isoc99_sscanf
484# endif
485# endif
486#endif
487
488#ifdef __USE_ISOC99
489/* Read formatted input from S into argument list ARG.
490
491 This function is a possible cancellation point and therefore not
492 marked with __THROW. */
493extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
494 __gnuc_va_list __arg)
495 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur __nonnull ((1));
496
497/* Read formatted input from stdin into argument list ARG.
498
499 This function is a possible cancellation point and therefore not
500 marked with __THROW. */
501extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
502 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
503
504/* Read formatted input from S into argument list ARG. */
505extern int vsscanf (const char *__restrict __s,
506 const char *__restrict __format, __gnuc_va_list __arg)
507 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
508
509/* Same redirection as above for the v*scanf family. */
510# if !__GLIBC_USE (DEPRECATED_SCANF)
511# if __GLIBC_USE (C23_STRTOL)
512# if defined __REDIRECT && !defined __LDBL_COMPAT \
513 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
514extern int __REDIRECT (vfscanf,
515 (FILE *__restrict __s,
516 const char *__restrict __format, __gnuc_va_list __arg),
517 __isoc23_vfscanf)
518 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur __nonnull ((1));
519extern int __REDIRECT (vscanf, (const char *__restrict __format,
520 __gnuc_va_list __arg), __isoc23_vscanf)
521 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
522extern int __REDIRECT_NTH (vsscanf,
523 (const char *__restrict __s,
524 const char *__restrict __format,
525 __gnuc_va_list __arg), __isoc23_vsscanf)
526 __attribute__ ((__format__ (__scanf__, 2, 0)));
527# elif !defined __REDIRECT
528extern int __isoc23_vfscanf (FILE *__restrict __s,
529 const char *__restrict __format,
530 __gnuc_va_list __arg) __wur __nonnull ((1));
531extern int __isoc23_vscanf (const char *__restrict __format,
532 __gnuc_va_list __arg) __wur;
533extern int __isoc23_vsscanf (const char *__restrict __s,
534 const char *__restrict __format,
535 __gnuc_va_list __arg) __THROW;
536# define vfscanf __isoc23_vfscanf
537# define vscanf __isoc23_vscanf
538# define vsscanf __isoc23_vsscanf
539# endif
540# else
541# if defined __REDIRECT && !defined __LDBL_COMPAT \
542 && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
543extern int __REDIRECT (vfscanf,
544 (FILE *__restrict __s,
545 const char *__restrict __format, __gnuc_va_list __arg),
546 __isoc99_vfscanf)
547 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur __nonnull ((1));
548extern int __REDIRECT (vscanf, (const char *__restrict __format,
549 __gnuc_va_list __arg), __isoc99_vscanf)
550 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
551extern int __REDIRECT_NTH (vsscanf,
552 (const char *__restrict __s,
553 const char *__restrict __format,
554 __gnuc_va_list __arg), __isoc99_vsscanf)
555 __attribute__ ((__format__ (__scanf__, 2, 0)));
556# elif !defined __REDIRECT
557extern int __isoc99_vfscanf (FILE *__restrict __s,
558 const char *__restrict __format,
559 __gnuc_va_list __arg) __wur __nonnull ((1));
560extern int __isoc99_vscanf (const char *__restrict __format,
561 __gnuc_va_list __arg) __wur;
562extern int __isoc99_vsscanf (const char *__restrict __s,
563 const char *__restrict __format,
564 __gnuc_va_list __arg) __THROW;
565# define vfscanf __isoc99_vfscanf
566# define vscanf __isoc99_vscanf
567# define vsscanf __isoc99_vsscanf
568# endif
569# endif
570# endif
571#endif /* Use ISO C9x. */
572
573
574/* Read a character from STREAM.
575
576 These functions are possible cancellation points and therefore not
577 marked with __THROW. */
578extern int fgetc (FILE *__stream) __nonnull ((1));
579extern int getc (FILE *__stream) __nonnull ((1));
580
581/* Read a character from stdin.
582
583 This function is a possible cancellation point and therefore not
584 marked with __THROW. */
585extern int getchar (void);
586
587#ifdef __USE_POSIX199506
588/* These are defined in POSIX.1:1996.
589
590 These functions are possible cancellation points and therefore not
591 marked with __THROW. */
592extern int getc_unlocked (FILE *__stream) __nonnull ((1));
593extern int getchar_unlocked (void);
594#endif /* Use POSIX. */
595
596#ifdef __USE_MISC
597/* Faster version when locking is not necessary.
598
599 This function is not part of POSIX and therefore no official
600 cancellation point. But due to similarity with an POSIX interface
601 or due to the implementation it is a cancellation point and
602 therefore not marked with __THROW. */
603extern int fgetc_unlocked (FILE *__stream) __nonnull ((1));
604#endif /* Use MISC. */
605
606
607/* Write a character to STREAM.
608
609 These functions are possible cancellation points 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. */
689extern __ssize_t __getdelim (char **__restrict __lineptr,
690 size_t *__restrict __n, int __delimiter,
691 FILE *__restrict __stream) __wur __nonnull ((4));
692extern __ssize_t getdelim (char **__restrict __lineptr,
693 size_t *__restrict __n, int __delimiter,
694 FILE *__restrict __stream) __wur __nonnull ((4));
695
696/* Like `getdelim', but reads up to a newline. */
697extern __ssize_t getline (char **__restrict __lineptr,
698 size_t *__restrict __n,
699 FILE *__restrict __stream) __wur __nonnull ((3));
700#endif
701
702
703/* Write a string to STREAM.
704
705 This function is a possible cancellation point and therefore not
706 marked with __THROW. */
707extern int fputs (const char *__restrict __s, FILE *__restrict __stream)
708 __nonnull ((2));
709
710/* Write a string, followed by a newline, to stdout.
711
712 This function is a possible cancellation point and therefore not
713 marked with __THROW. */
714extern int puts (const char *__s);
715
716
717/* Push a character back onto the input buffer of STREAM.
718
719 This function is a possible cancellation point and therefore not
720 marked with __THROW. */
721extern int ungetc (int __c, FILE *__stream) __nonnull ((2));
722
723
724/* Read chunks of generic data from STREAM.
725
726 This function is a possible cancellation point and therefore not
727 marked with __THROW. */
728extern size_t fread (void *__restrict __ptr, size_t __size,
729 size_t __n, FILE *__restrict __stream) __wur
730 __nonnull((4));
731/* Write chunks of generic data to STREAM.
732
733 This function is a possible cancellation point and therefore not
734 marked with __THROW. */
735extern size_t fwrite (const void *__restrict __ptr, size_t __size,
736 size_t __n, FILE *__restrict __s) __nonnull((4));
737
738#ifdef __USE_GNU
739/* This function does the same as `fputs' but does not lock the stream.
740
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. */
745extern int fputs_unlocked (const char *__restrict __s,
746 FILE *__restrict __stream) __nonnull ((2));
747#endif
748
749#ifdef __USE_MISC
750/* Faster versions when locking is not necessary.
751
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. */
756extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
757 size_t __n, FILE *__restrict __stream) __wur
758 __nonnull ((4));
759extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
760 size_t __n, FILE *__restrict __stream)
761 __nonnull ((4));
762#endif
763
764
765/* Seek to a certain position on STREAM.
766
767 This function is a possible cancellation point and therefore not
768 marked with __THROW. */
769extern int fseek (FILE *__stream, long int __off, int __whence)
770 __nonnull ((1));
771/* Return the current position of STREAM.
772
773 This function is a possible cancellation point and therefore not
774 marked with __THROW. */
775extern long int ftell (FILE *__stream) __wur __nonnull ((1));
776/* Rewind to the beginning of STREAM.
777
778 This function is a possible cancellation point and therefore not
779 marked with __THROW. */
780extern void rewind (FILE *__stream) __nonnull ((1));
781
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. */
786
787#if defined __USE_LARGEFILE || defined __USE_XOPEN2K
788# ifndef __USE_FILE_OFFSET64
789/* Seek to a certain position on STREAM.
790
791 This function is a possible cancellation point and therefore not
792 marked with __THROW. */
793extern int fseeko (FILE *__stream, __off_t __off, int __whence)
794 __nonnull ((1));
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 __nonnull ((1));
800# else
801# ifdef __REDIRECT
802extern int __REDIRECT (fseeko,
803 (FILE *__stream, __off64_t __off, int __whence),
804 fseeko64) __nonnull ((1));
805extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64)
806 __nonnull ((1));
807# else
808# define fseeko fseeko64
809# define ftello ftello64
810# endif
811# endif
812#endif
813
814#ifndef __USE_FILE_OFFSET64
815/* Get STREAM's position.
816
817 This function is a possible cancellation point and therefore not
818 marked with __THROW. */
819extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos)
820 __nonnull ((1));
821/* Set STREAM's position.
822
823 This function is a possible cancellation point and therefore not
824 marked with __THROW. */
825extern int fsetpos (FILE *__stream, const fpos_t *__pos) __nonnull ((1));
826#else
827# ifdef __REDIRECT
828extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
829 fpos_t *__restrict __pos), fgetpos64)
830 __nonnull ((1));
831extern int __REDIRECT (fsetpos,
832 (FILE *__stream, const fpos_t *__pos), fsetpos64)
833 __nonnull ((1));
834# else
835# define fgetpos fgetpos64
836# define fsetpos fsetpos64
837# endif
838#endif
839
840#ifdef __USE_LARGEFILE64
841extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence)
842 __nonnull ((1));
843extern __off64_t ftello64 (FILE *__stream) __wur __nonnull ((1));
844extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos)
845 __nonnull ((1));
846extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos) __nonnull ((1));
847#endif
848
849/* Clear the error and EOF indicators for STREAM. */
850extern void clearerr (FILE *__stream) __THROW __nonnull ((1));
851/* Return the EOF indicator for STREAM. */
852extern int feof (FILE *__stream) __THROW __wur __nonnull ((1));
853/* Return the error indicator for STREAM. */
854extern int ferror (FILE *__stream) __THROW __wur __nonnull ((1));
855
856#ifdef __USE_MISC
857/* Faster versions when locking is not required. */
858extern void clearerr_unlocked (FILE *__stream) __THROW __nonnull ((1));
859extern int feof_unlocked (FILE *__stream) __THROW __wur __nonnull ((1));
860extern int ferror_unlocked (FILE *__stream) __THROW __wur __nonnull ((1));
861#endif
862
863
864/* Print a message describing the meaning of the value of errno.
865
866 This function is a possible cancellation point and therefore not
867 marked with __THROW. */
868extern void perror (const char *__s) __COLD;
869
870
871#ifdef __USE_POSIX
872/* Return the system file descriptor for STREAM. */
873extern int fileno (FILE *__stream) __THROW __wur __nonnull ((1));
874#endif /* Use POSIX. */
875
876#ifdef __USE_MISC
877/* Faster version when locking is not required. */
878extern int fileno_unlocked (FILE *__stream) __THROW __wur __nonnull ((1));
879#endif
880
881
882#ifdef __USE_POSIX2
883/* Close a stream opened by popen and return the status of its child.
884
885 This function is a possible cancellation point and therefore not
886 marked with __THROW. */
887extern int pclose (FILE *__stream) __nonnull ((1));
888
889/* Create a new stream connected to a pipe running the given command.
890
891 This function is a possible cancellation point and therefore not
892 marked with __THROW. */
893extern FILE *popen (const char *__command, const char *__modes)
894 __attribute_malloc__ __attr_dealloc (pclose, 1) __wur;
895
896#endif
897
898
899#ifdef __USE_POSIX
900/* Return the name of the controlling terminal. */
901extern char *ctermid (char *__s) __THROW
902 __attr_access ((__write_only__, 1));
903#endif /* Use POSIX. */
904
905
906#if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
907/* Return the name of the current user. */
908extern char *cuserid (char *__s)
909 __attr_access ((__write_only__, 1));
910#endif /* Use X/Open, but not issue 6. */
911
912
913#ifdef __USE_GNU
914struct obstack; /* See <obstack.h>. */
915
916/* Write formatted output to an obstack. */
917extern int obstack_printf (struct obstack *__restrict __obstack,
918 const char *__restrict __format, ...)
919 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
920extern 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. */
925
926
927#ifdef __USE_POSIX199506
928/* These are defined in POSIX.1:1996. */
929
930/* Acquire ownership of STREAM. */
931extern void flockfile (FILE *__stream) __THROW __nonnull ((1));
932
933/* Try to acquire ownership of STREAM but do not block if it is not
934 possible. */
935extern int ftrylockfile (FILE *__stream) __THROW __wur __nonnull ((1));
936
937/* Relinquish the ownership granted for STREAM. */
938extern void funlockfile (FILE *__stream) __THROW __nonnull ((1));
939#endif /* POSIX */
940
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>
945#endif
946
947/* Slow-path routines used by the optimized inline functions in
948 bits/stdio.h. */
949extern int __uflow (FILE *);
950extern int __overflow (FILE *, int);
951
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>
955#endif
956
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>
961#endif
962
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>
967#endif
968#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
969/* Now include the function definitions and redirects too. */
970# include <bits/stdio2.h>
971#endif
972
973__END_DECLS
974
975#endif /* <stdio.h> included. */
976