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