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