Support __STDC_WANT_LIB_EXT2__ feature test macro.
[glibc.git] / libio / stdio.h
blobe37f901e5fb026d3dd01e6d501313526d7de6b4c
1 /* Define ISO C stdio on top of C++ iostreams.
2 Copyright (C) 1991-2016 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
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.
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.
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/>. */
20 * ISO C99 Standard: 7.19 Input/output <stdio.h>
23 #ifndef _STDIO_H
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>
30 __BEGIN_DECLS
32 # define __need_size_t
33 # define __need_NULL
34 # include <stddef.h>
36 # include <bits/types.h>
37 # define __need_FILE
38 # define __need___FILE
39 #endif /* Don't need FILE. */
42 #if !defined __FILE_defined && defined __need_FILE
44 /* Define outside of namespace so the C++ is happy. */
45 struct _IO_FILE;
47 __BEGIN_NAMESPACE_STD
48 /* The opaque type of streams. This is the definition used elsewhere. */
49 typedef 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
57 # define __FILE_defined 1
58 #endif /* FILE not defined. */
59 #undef __need_FILE
62 #if !defined ____FILE_defined && defined __need___FILE
64 /* The opaque type of streams. This is the definition used elsewhere. */
65 typedef struct _IO_FILE __FILE;
67 # define ____FILE_defined 1
68 #endif /* __FILE not defined. */
69 #undef __need___FILE
72 #ifdef _STDIO_H
73 #define _STDIO_USES_IOSTREAM
75 #include <libio.h>
77 #if defined __USE_XOPEN || defined __USE_XOPEN2K8
78 # ifdef __GNUC__
79 # ifndef _VA_LIST_DEFINED
80 typedef _G_va_list va_list;
81 # define _VA_LIST_DEFINED
82 # endif
83 # else
84 # include <stdarg.h>
85 # endif
86 #endif
88 #if defined __USE_UNIX98 || defined __USE_XOPEN2K
89 # ifndef __off_t_defined
90 # ifndef __USE_FILE_OFFSET64
91 typedef __off_t off_t;
92 # else
93 typedef __off64_t off_t;
94 # endif
95 # define __off_t_defined
96 # endif
97 # if defined __USE_LARGEFILE64 && !defined __off64_t_defined
98 typedef __off64_t off64_t;
99 # define __off64_t_defined
100 # endif
101 #endif
103 #ifdef __USE_XOPEN2K8
104 # ifndef __ssize_t_defined
105 typedef __ssize_t ssize_t;
106 # define __ssize_t_defined
107 # endif
108 #endif
110 /* The type of the second argument to `fgetpos' and `fsetpos'. */
111 __BEGIN_NAMESPACE_STD
112 #ifndef __USE_FILE_OFFSET64
113 typedef _G_fpos_t fpos_t;
114 #else
115 typedef _G_fpos64_t fpos_t;
116 #endif
117 __END_NAMESPACE_STD
118 #ifdef __USE_LARGEFILE64
119 typedef _G_fpos64_t fpos64_t;
120 #endif
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. */
128 /* Default buffer size. */
129 #ifndef BUFSIZ
130 # define BUFSIZ _IO_BUFSIZ
131 #endif
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
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
152 #if defined __USE_MISC || defined __USE_XOPEN
153 /* Default path prefix for `tempnam' and `tmpnam'. */
154 # define P_tmpdir "/tmp"
155 #endif
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>
170 /* Standard streams. */
171 extern struct _IO_FILE *stdin; /* Standard input stream. */
172 extern struct _IO_FILE *stdout; /* Standard output stream. */
173 extern 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
179 __BEGIN_NAMESPACE_STD
180 /* Remove file FILENAME. */
181 extern int remove (const char *__filename) __THROW;
182 /* Rename file OLD to NEW. */
183 extern int rename (const char *__old, const char *__new) __THROW;
184 __END_NAMESPACE_STD
186 #ifdef __USE_ATFILE
187 /* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
188 extern int renameat (int __oldfd, const char *__old, int __newfd,
189 const char *__new) __THROW;
190 #endif
192 __BEGIN_NAMESPACE_STD
193 /* Create a temporary file and open it read/write.
195 This function is a possible cancellation point and therefore not
196 marked with __THROW. */
197 #ifndef __USE_FILE_OFFSET64
198 extern FILE *tmpfile (void) __wur;
199 #else
200 # ifdef __REDIRECT
201 extern FILE *__REDIRECT (tmpfile, (void), tmpfile64) __wur;
202 # else
203 # define tmpfile tmpfile64
204 # endif
205 #endif
207 #ifdef __USE_LARGEFILE64
208 extern FILE *tmpfile64 (void) __wur;
209 #endif
211 /* Generate a temporary filename. */
212 extern char *tmpnam (char *__s) __THROW __wur;
213 __END_NAMESPACE_STD
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. */
218 extern char *tmpnam_r (char *__s) __THROW __wur;
219 #endif
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'. */
230 extern char *tempnam (const char *__dir, const char *__pfx)
231 __THROW __attribute_malloc__ __wur;
232 #endif
235 __BEGIN_NAMESPACE_STD
236 /* Close STREAM.
238 This function is a possible cancellation point and therefore not
239 marked with __THROW. */
240 extern int fclose (FILE *__stream);
241 /* Flush STREAM, or all streams if STREAM is NULL.
243 This function is a possible cancellation point and therefore not
244 marked with __THROW. */
245 extern int fflush (FILE *__stream);
246 __END_NAMESPACE_STD
248 #ifdef __USE_MISC
249 /* Faster versions when locking is not required.
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. */
255 extern int fflush_unlocked (FILE *__stream);
256 #endif
258 #ifdef __USE_GNU
259 /* Close all streams.
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. */
265 extern int fcloseall (void);
266 #endif
269 __BEGIN_NAMESPACE_STD
270 #ifndef __USE_FILE_OFFSET64
271 /* Open a file and create a new stream for it.
273 This function is a possible cancellation point and therefore not
274 marked with __THROW. */
275 extern FILE *fopen (const char *__restrict __filename,
276 const char *__restrict __modes) __wur;
277 /* Open a file, replacing an existing stream with it.
279 This function is a possible cancellation point and therefore not
280 marked with __THROW. */
281 extern FILE *freopen (const char *__restrict __filename,
282 const char *__restrict __modes,
283 FILE *__restrict __stream) __wur;
284 #else
285 # ifdef __REDIRECT
286 extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
287 const char *__restrict __modes), fopen64)
288 __wur;
289 extern 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
300 extern FILE *fopen64 (const char *__restrict __filename,
301 const char *__restrict __modes) __wur;
302 extern FILE *freopen64 (const char *__restrict __filename,
303 const char *__restrict __modes,
304 FILE *__restrict __stream) __wur;
305 #endif
307 #ifdef __USE_POSIX
308 /* Create a new stream that refers to an existing system file descriptor. */
309 extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
310 #endif
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. */
315 extern FILE *fopencookie (void *__restrict __magic_cookie,
316 const char *__restrict __modes,
317 _IO_cookie_io_functions_t __io_funcs) __THROW __wur;
318 #endif
320 #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
321 /* Create a new stream that refers to a memory buffer. */
322 extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
323 __THROW __wur;
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. */
328 extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
329 #endif
332 __BEGIN_NAMESPACE_STD
333 /* If BUF is NULL, make STREAM unbuffered.
334 Else make it use buffer BUF, of size BUFSIZ. */
335 extern 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. */
339 extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
340 int __modes, size_t __n) __THROW;
341 __END_NAMESPACE_STD
343 #ifdef __USE_MISC
344 /* If BUF is NULL, make STREAM unbuffered.
345 Else make it use SIZE bytes of BUF for buffering. */
346 extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
347 size_t __size) __THROW;
349 /* Make STREAM line-buffered. */
350 extern void setlinebuf (FILE *__stream) __THROW;
351 #endif
354 __BEGIN_NAMESPACE_STD
355 /* Write formatted output to STREAM.
357 This function is a possible cancellation point and therefore not
358 marked with __THROW. */
359 extern int fprintf (FILE *__restrict __stream,
360 const char *__restrict __format, ...);
361 /* Write formatted output to stdout.
363 This function is a possible cancellation point and therefore not
364 marked with __THROW. */
365 extern int printf (const char *__restrict __format, ...);
366 /* Write formatted output to S. */
367 extern int sprintf (char *__restrict __s,
368 const char *__restrict __format, ...) __THROWNL;
370 /* Write formatted output to S from argument list ARG.
372 This function is a possible cancellation point and therefore not
373 marked with __THROW. */
374 extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
375 _G_va_list __arg);
376 /* Write formatted output to stdout from argument list ARG.
378 This function is a possible cancellation point and therefore not
379 marked with __THROW. */
380 extern int vprintf (const char *__restrict __format, _G_va_list __arg);
381 /* Write formatted output to S from argument list ARG. */
382 extern int vsprintf (char *__restrict __s, const char *__restrict __format,
383 _G_va_list __arg) __THROWNL;
384 __END_NAMESPACE_STD
386 #if defined __USE_ISOC99 || defined __USE_UNIX98
387 __BEGIN_NAMESPACE_C99
388 /* Maximum chars of output to write in MAXLEN. */
389 extern int snprintf (char *__restrict __s, size_t __maxlen,
390 const char *__restrict __format, ...)
391 __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
393 extern 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
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. */
402 extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
403 _G_va_list __arg)
404 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
405 extern int __asprintf (char **__restrict __ptr,
406 const char *__restrict __fmt, ...)
407 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
408 extern int asprintf (char **__restrict __ptr,
409 const char *__restrict __fmt, ...)
410 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
411 #endif
413 #ifdef __USE_XOPEN2K8
414 /* Write formatted output to a file descriptor. */
415 extern int vdprintf (int __fd, const char *__restrict __fmt,
416 _G_va_list __arg)
417 __attribute__ ((__format__ (__printf__, 2, 0)));
418 extern int dprintf (int __fd, const char *__restrict __fmt, ...)
419 __attribute__ ((__format__ (__printf__, 2, 3)));
420 #endif
423 __BEGIN_NAMESPACE_STD
424 /* Read formatted input from STREAM.
426 This function is a possible cancellation point and therefore not
427 marked with __THROW. */
428 extern int fscanf (FILE *__restrict __stream,
429 const char *__restrict __format, ...) __wur;
430 /* Read formatted input from stdin.
432 This function is a possible cancellation point and therefore not
433 marked with __THROW. */
434 extern int scanf (const char *__restrict __format, ...) __wur;
435 /* Read formatted input from S. */
436 extern int sscanf (const char *__restrict __s,
437 const char *__restrict __format, ...) __THROW;
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 [. */
446 extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
447 const char *__restrict __format, ...),
448 __isoc99_fscanf) __wur;
449 extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
450 __isoc99_scanf) __wur;
451 extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
452 const char *__restrict __format, ...),
453 __isoc99_sscanf);
454 # else
455 extern int __isoc99_fscanf (FILE *__restrict __stream,
456 const char *__restrict __format, ...) __wur;
457 extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
458 extern 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
466 __END_NAMESPACE_STD
468 #ifdef __USE_ISOC99
469 __BEGIN_NAMESPACE_C99
470 /* Read formatted input from S into argument list ARG.
472 This function is a possible cancellation point and therefore not
473 marked with __THROW. */
474 extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
475 _G_va_list __arg)
476 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
478 /* Read formatted input from stdin into argument list ARG.
480 This function is a possible cancellation point and therefore not
481 marked with __THROW. */
482 extern int vscanf (const char *__restrict __format, _G_va_list __arg)
483 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
485 /* Read formatted input from S into argument list ARG. */
486 extern int vsscanf (const char *__restrict __s,
487 const char *__restrict __format, _G_va_list __arg)
488 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
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 [. */
497 extern 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;
502 extern int __REDIRECT (vscanf, (const char *__restrict __format,
503 _G_va_list __arg), __isoc99_vscanf)
504 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
505 extern 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
511 extern int __isoc99_vfscanf (FILE *__restrict __s,
512 const char *__restrict __format,
513 _G_va_list __arg) __wur;
514 extern int __isoc99_vscanf (const char *__restrict __format,
515 _G_va_list __arg) __wur;
516 extern 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
525 __END_NAMESPACE_C99
526 #endif /* Use ISO C9x. */
529 __BEGIN_NAMESPACE_STD
530 /* Read a character from STREAM.
532 These functions are possible cancellation points and therefore not
533 marked with __THROW. */
534 extern int fgetc (FILE *__stream);
535 extern int getc (FILE *__stream);
537 /* Read a character from stdin.
539 This function is a possible cancellation point and therefore not
540 marked with __THROW. */
541 extern int getchar (void);
542 __END_NAMESPACE_STD
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)
548 #ifdef __USE_POSIX199506
549 /* These are defined in POSIX.1:1996.
551 These functions are possible cancellation points and therefore not
552 marked with __THROW. */
553 extern int getc_unlocked (FILE *__stream);
554 extern int getchar_unlocked (void);
555 #endif /* Use POSIX. */
557 #ifdef __USE_MISC
558 /* Faster version when locking is not necessary.
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. */
564 extern int fgetc_unlocked (FILE *__stream);
565 #endif /* Use MISC. */
568 __BEGIN_NAMESPACE_STD
569 /* Write a character to STREAM.
571 These functions are possible cancellation points and therefore not
572 marked with __THROW.
574 These functions is a possible cancellation point and therefore not
575 marked with __THROW. */
576 extern int fputc (int __c, FILE *__stream);
577 extern int putc (int __c, FILE *__stream);
579 /* Write a character to stdout.
581 This function is a possible cancellation point and therefore not
582 marked with __THROW. */
583 extern int putchar (int __c);
584 __END_NAMESPACE_STD
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)
590 #ifdef __USE_MISC
591 /* Faster version when locking is not necessary.
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. */
597 extern int fputc_unlocked (int __c, FILE *__stream);
598 #endif /* Use MISC. */
600 #ifdef __USE_POSIX199506
601 /* These are defined in POSIX.1:1996.
603 These functions are possible cancellation points and therefore not
604 marked with __THROW. */
605 extern int putc_unlocked (int __c, FILE *__stream);
606 extern int putchar_unlocked (int __c);
607 #endif /* Use POSIX. */
610 #if defined __USE_MISC \
611 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
612 /* Get a word (int) from STREAM. */
613 extern int getw (FILE *__stream);
615 /* Write a word (int) to STREAM. */
616 extern int putw (int __w, FILE *__stream);
617 #endif
620 __BEGIN_NAMESPACE_STD
621 /* Get a newline-terminated string of finite length from STREAM.
623 This function is a possible cancellation point and therefore not
624 marked with __THROW. */
625 extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
626 __wur;
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.
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++.
639 This function is a possible cancellation point and therefore not
640 marked with __THROW. */
641 extern char *gets (char *__s) __wur __attribute_deprecated__;
642 #endif
643 __END_NAMESPACE_STD
645 #ifdef __USE_GNU
646 /* This function does the same as `fgets' but does not lock the stream.
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. */
652 extern char *fgets_unlocked (char *__restrict __s, int __n,
653 FILE *__restrict __stream) __wur;
654 #endif
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.
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. */
668 extern _IO_ssize_t __getdelim (char **__restrict __lineptr,
669 size_t *__restrict __n, int __delimiter,
670 FILE *__restrict __stream) __wur;
671 extern _IO_ssize_t getdelim (char **__restrict __lineptr,
672 size_t *__restrict __n, int __delimiter,
673 FILE *__restrict __stream) __wur;
675 /* Like `getdelim', but reads up to a newline.
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. */
681 extern _IO_ssize_t getline (char **__restrict __lineptr,
682 size_t *__restrict __n,
683 FILE *__restrict __stream) __wur;
684 #endif
687 __BEGIN_NAMESPACE_STD
688 /* Write a string to STREAM.
690 This function is a possible cancellation point and therefore not
691 marked with __THROW. */
692 extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
694 /* Write a string, followed by a newline, to stdout.
696 This function is a possible cancellation point and therefore not
697 marked with __THROW. */
698 extern int puts (const char *__s);
701 /* Push a character back onto the input buffer of STREAM.
703 This function is a possible cancellation point and therefore not
704 marked with __THROW. */
705 extern int ungetc (int __c, FILE *__stream);
708 /* Read chunks of generic data from STREAM.
710 This function is a possible cancellation point and therefore not
711 marked with __THROW. */
712 extern 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.
716 This function is a possible cancellation point and therefore not
717 marked with __THROW. */
718 extern size_t fwrite (const void *__restrict __ptr, size_t __size,
719 size_t __n, FILE *__restrict __s);
720 __END_NAMESPACE_STD
722 #ifdef __USE_GNU
723 /* This function does the same as `fputs' but does not lock the stream.
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. */
729 extern int fputs_unlocked (const char *__restrict __s,
730 FILE *__restrict __stream);
731 #endif
733 #ifdef __USE_MISC
734 /* Faster versions when locking is not necessary.
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. */
740 extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
741 size_t __n, FILE *__restrict __stream) __wur;
742 extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
743 size_t __n, FILE *__restrict __stream);
744 #endif
747 __BEGIN_NAMESPACE_STD
748 /* Seek to a certain position on STREAM.
750 This function is a possible cancellation point and therefore not
751 marked with __THROW. */
752 extern int fseek (FILE *__stream, long int __off, int __whence);
753 /* Return the current position of STREAM.
755 This function is a possible cancellation point and therefore not
756 marked with __THROW. */
757 extern long int ftell (FILE *__stream) __wur;
758 /* Rewind to the beginning of STREAM.
760 This function is a possible cancellation point and therefore not
761 marked with __THROW. */
762 extern void rewind (FILE *__stream);
763 __END_NAMESPACE_STD
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. */
770 #if defined __USE_LARGEFILE || defined __USE_XOPEN2K
771 # ifndef __USE_FILE_OFFSET64
772 /* Seek to a certain position on STREAM.
774 This function is a possible cancellation point and therefore not
775 marked with __THROW. */
776 extern int fseeko (FILE *__stream, __off_t __off, int __whence);
777 /* Return the current position of STREAM.
779 This function is a possible cancellation point and therefore not
780 marked with __THROW. */
781 extern __off_t ftello (FILE *__stream) __wur;
782 # else
783 # ifdef __REDIRECT
784 extern int __REDIRECT (fseeko,
785 (FILE *__stream, __off64_t __off, int __whence),
786 fseeko64);
787 extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64);
788 # else
789 # define fseeko fseeko64
790 # define ftello ftello64
791 # endif
792 # endif
793 #endif
795 __BEGIN_NAMESPACE_STD
796 #ifndef __USE_FILE_OFFSET64
797 /* Get STREAM's position.
799 This function is a possible cancellation point and therefore not
800 marked with __THROW. */
801 extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
802 /* Set STREAM's position.
804 This function is a possible cancellation point and therefore not
805 marked with __THROW. */
806 extern int fsetpos (FILE *__stream, const fpos_t *__pos);
807 #else
808 # ifdef __REDIRECT
809 extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
810 fpos_t *__restrict __pos), fgetpos64);
811 extern 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
820 #ifdef __USE_LARGEFILE64
821 extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
822 extern __off64_t ftello64 (FILE *__stream) __wur;
823 extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
824 extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
825 #endif
827 __BEGIN_NAMESPACE_STD
828 /* Clear the error and EOF indicators for STREAM. */
829 extern void clearerr (FILE *__stream) __THROW;
830 /* Return the EOF indicator for STREAM. */
831 extern int feof (FILE *__stream) __THROW __wur;
832 /* Return the error indicator for STREAM. */
833 extern int ferror (FILE *__stream) __THROW __wur;
834 __END_NAMESPACE_STD
836 #ifdef __USE_MISC
837 /* Faster versions when locking is not required. */
838 extern void clearerr_unlocked (FILE *__stream) __THROW;
839 extern int feof_unlocked (FILE *__stream) __THROW __wur;
840 extern int ferror_unlocked (FILE *__stream) __THROW __wur;
841 #endif
844 __BEGIN_NAMESPACE_STD
845 /* Print a message describing the meaning of the value of errno.
847 This function is a possible cancellation point and therefore not
848 marked with __THROW. */
849 extern void perror (const char *__s);
850 __END_NAMESPACE_STD
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>
859 #ifdef __USE_POSIX
860 /* Return the system file descriptor for STREAM. */
861 extern int fileno (FILE *__stream) __THROW __wur;
862 #endif /* Use POSIX. */
864 #ifdef __USE_MISC
865 /* Faster version when locking is not required. */
866 extern int fileno_unlocked (FILE *__stream) __THROW __wur;
867 #endif
870 #ifdef __USE_POSIX2
871 /* Create a new stream connected to a pipe running the given command.
873 This function is a possible cancellation point and therefore not
874 marked with __THROW. */
875 extern FILE *popen (const char *__command, const char *__modes) __wur;
877 /* Close a stream opened by popen and return the status of its child.
879 This function is a possible cancellation point and therefore not
880 marked with __THROW. */
881 extern int pclose (FILE *__stream);
882 #endif
885 #ifdef __USE_POSIX
886 /* Return the name of the controlling terminal. */
887 extern char *ctermid (char *__s) __THROW;
888 #endif /* Use POSIX. */
891 #if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
892 /* Return the name of the current user. */
893 extern char *cuserid (char *__s);
894 #endif /* Use X/Open, but not issue 6. */
897 #ifdef __USE_GNU
898 struct obstack; /* See <obstack.h>. */
900 /* Write formatted output to an obstack. */
901 extern int obstack_printf (struct obstack *__restrict __obstack,
902 const char *__restrict __format, ...)
903 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
904 extern 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. */
911 #ifdef __USE_POSIX199506
912 /* These are defined in POSIX.1:1996. */
914 /* Acquire ownership of STREAM. */
915 extern void flockfile (FILE *__stream) __THROW;
917 /* Try to acquire ownership of STREAM but do not block if it is not
918 possible. */
919 extern int ftrylockfile (FILE *__stream) __THROW __wur;
921 /* Relinquish the ownership granted for STREAM. */
922 extern void funlockfile (FILE *__stream) __THROW;
923 #endif /* POSIX */
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. */
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
945 __END_DECLS
947 #endif /* <stdio.h> included. */
949 #endif /* !_STDIO_H */