]> git.ipfire.org Git - thirdparty/glibc.git/blame - libio/stdio.h
Prefer https to http for gnu.org and fsf.org URLs
[thirdparty/glibc.git] / libio / stdio.h
CommitLineData
2f6d1f1b 1/* Define ISO C stdio on top of C++ iostreams.
04277e02 2 Copyright (C) 1991-2019 Free Software Foundation, Inc.
41bdb6e2 3 This file is part of the GNU C Library.
96aa2d94 4
2f6d1f1b 5 The GNU C Library is free software; you can redistribute it and/or
41bdb6e2
AJ
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.
96aa2d94 9
2f6d1f1b
UD
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
41bdb6e2 13 Lesser General Public License for more details.
96aa2d94 14
41bdb6e2 15 You should have received a copy of the GNU Lesser General Public
59ba27a6 16 License along with the GNU C Library; if not, see
5a82c748 17 <https://www.gnu.org/licenses/>. */
96aa2d94
RM
18
19/*
d1646309 20 * ISO C99 Standard: 7.19 Input/output <stdio.h>
96aa2d94
RM
21 */
22
23#ifndef _STDIO_H
199fc19d 24#define _STDIO_H 1
2f6d1f1b 25
199fc19d
ZW
26#define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
27#include <bits/libc-header-start.h>
2f6d1f1b
UD
28
29__BEGIN_DECLS
30
199fc19d
ZW
31#define __need_size_t
32#define __need_NULL
33#include <stddef.h>
2f6d1f1b 34
a4fea3f2
ZW
35#define __need___va_list
36#include <stdarg.h>
37
199fc19d 38#include <bits/types.h>
a4fea3f2
ZW
39#include <bits/types/__fpos_t.h>
40#include <bits/types/__fpos64_t.h>
199fc19d
ZW
41#include <bits/types/__FILE.h>
42#include <bits/types/FILE.h>
a4fea3f2 43#include <bits/types/struct_FILE.h>
2f6d1f1b 44
a4fea3f2
ZW
45#ifdef __USE_GNU
46# include <bits/types/cookie_io_functions_t.h>
47#endif
96aa2d94 48
cd2f000c 49#if defined __USE_XOPEN || defined __USE_XOPEN2K8
3bf3d361
UD
50# ifdef __GNUC__
51# ifndef _VA_LIST_DEFINED
a4fea3f2 52typedef __gnuc_va_list va_list;
3bf3d361
UD
53# define _VA_LIST_DEFINED
54# endif
55# else
56# include <stdarg.h>
57# endif
58#endif
59
10b8108a 60#if defined __USE_UNIX98 || defined __USE_XOPEN2K
cd2f000c
UD
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
bf074726 73#endif
cd2f000c 74
bf074726 75#ifdef __USE_XOPEN2K8
cd2f000c
UD
76# ifndef __ssize_t_defined
77typedef __ssize_t ssize_t;
78# define __ssize_t_defined
79# endif
80#endif
81
2f6d1f1b 82/* The type of the second argument to `fgetpos' and `fsetpos'. */
dfd2257a 83#ifndef __USE_FILE_OFFSET64
a4fea3f2 84typedef __fpos_t fpos_t;
dfd2257a 85#else
a4fea3f2 86typedef __fpos64_t fpos_t;
dfd2257a
UD
87#endif
88#ifdef __USE_LARGEFILE64
a4fea3f2 89typedef __fpos64_t fpos64_t;
dfd2257a 90#endif
2f6d1f1b 91
2f6d1f1b 92/* The possibilities for the third argument to `setvbuf'. */
798be72d 93#define _IOFBF 0 /* Fully buffered. */
2f6d1f1b
UD
94#define _IOLBF 1 /* Line buffered. */
95#define _IONBF 2 /* No buffering. */
96
97
98/* Default buffer size. */
a4fea3f2 99#define BUFSIZ 8192
96aa2d94 100
2f6d1f1b 101
a4fea3f2
ZW
102/* The value returned by fgetc and similar functions to indicate the
103 end of the file. */
104#define EOF (-1)
96aa2d94 105
96aa2d94 106
2f6d1f1b
UD
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. */
798be72d
UD
112#ifdef __USE_GNU
113# define SEEK_DATA 3 /* Seek to next data. */
114# define SEEK_HOLE 4 /* Seek to next hole. */
115#endif
2f6d1f1b 116
96aa2d94 117
498afc54 118#if defined __USE_MISC || defined __USE_XOPEN
f65fd747 119/* Default path prefix for `tempnam' and `tmpnam'. */
dfd2257a 120# define P_tmpdir "/tmp"
f65fd747 121#endif
96aa2d94 122
96aa2d94 123
2f6d1f1b
UD
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
798be72d 127 (and tempnam when it uses tmpnam's name space),
2f6d1f1b
UD
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. */
5107cf1d 133#include <bits/stdio_lim.h>
2f6d1f1b
UD
134
135
136/* Standard streams. */
a4fea3f2
ZW
137extern FILE *stdin; /* Standard input stream. */
138extern FILE *stdout; /* Standard output stream. */
139extern FILE *stderr; /* Standard error output stream. */
63ae7b63 140/* C89/C99 say they're macros. Make them happy. */
7df789e0
UD
141#define stdin stdin
142#define stdout stdout
143#define stderr stderr
96aa2d94 144
2f6d1f1b 145/* Remove file FILENAME. */
a784e502 146extern int remove (const char *__filename) __THROW;
2f6d1f1b 147/* Rename file OLD to NEW. */
a784e502 148extern int rename (const char *__old, const char *__new) __THROW;
2f6d1f1b 149
0b8f25bb 150#ifdef __USE_ATFILE
26cec518 151/* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
a784e502
UD
152extern int renameat (int __oldfd, const char *__old, int __newfd,
153 const char *__new) __THROW;
26cec518 154#endif
2f6d1f1b 155
d6da5cb6
FW
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
2c008571
UD
168/* Create a temporary file and open it read/write.
169
4c1423ed 170 This function is a possible cancellation point and therefore not
2c008571 171 marked with __THROW. */
dfd2257a 172#ifndef __USE_FILE_OFFSET64
11bf311e 173extern FILE *tmpfile (void) __wur;
dfd2257a 174#else
01cad722 175# ifdef __REDIRECT
11bf311e 176extern FILE *__REDIRECT (tmpfile, (void), tmpfile64) __wur;
01cad722
UD
177# else
178# define tmpfile tmpfile64
179# endif
dfd2257a 180#endif
7a5affeb 181
2c008571 182#ifdef __USE_LARGEFILE64
11bf311e 183extern FILE *tmpfile64 (void) __wur;
2c008571
UD
184#endif
185
7a5affeb 186/* Generate a temporary filename. */
11bf311e 187extern char *tmpnam (char *__s) __THROW __wur;
7a5affeb 188
2f6d1f1b
UD
189#ifdef __USE_MISC
190/* This is the reentrant variant of `tmpnam'. The only difference is
191 that it does not allow S to be NULL. */
11bf311e 192extern char *tmpnam_r (char *__s) __THROW __wur;
d68171ed 193#endif
2f6d1f1b
UD
194
195
498afc54 196#if defined __USE_MISC || defined __USE_XOPEN
2f6d1f1b
UD
197/* Generate a unique temporary filename using up to five characters of PFX
198 if it is not NULL. The directory to put this file in is searched for
199 as follows: First the environment variable "TMPDIR" is checked.
200 If it contains the name of a writable directory, that directory is used.
201 If not and if DIR is not NULL, that value is checked. If that fails,
202 P_tmpdir is tried and finally "/tmp". The storage for the filename
203 is allocated by `malloc'. */
a784e502 204extern char *tempnam (const char *__dir, const char *__pfx)
11bf311e 205 __THROW __attribute_malloc__ __wur;
2cc7dc4d 206#endif
96aa2d94 207
2f6d1f1b 208
2c008571
UD
209/* Close STREAM.
210
211 This function is a possible cancellation point and therefore not
212 marked with __THROW. */
213extern int fclose (FILE *__stream);
214/* Flush STREAM, or all streams if STREAM is NULL.
215
216 This function is a possible cancellation point and therefore not
217 marked with __THROW. */
218extern int fflush (FILE *__stream);
2f6d1f1b
UD
219
220#ifdef __USE_MISC
2c008571
UD
221/* Faster versions when locking is not required.
222
223 This function is not part of POSIX and therefore no official
224 cancellation point. But due to similarity with an POSIX interface
225 or due to the implementation it is a cancellation point and
226 therefore not marked with __THROW. */
227extern int fflush_unlocked (FILE *__stream);
96aa2d94
RM
228#endif
229
2c6fe0bd 230#ifdef __USE_GNU
2c008571
UD
231/* Close all streams.
232
233 This function is not part of POSIX and therefore no official
234 cancellation point. But due to similarity with an POSIX interface
235 or due to the implementation it is a cancellation point and
236 therefore not marked with __THROW. */
237extern int fcloseall (void);
2c6fe0bd
UD
238#endif
239
76060ec0 240
dfd2257a 241#ifndef __USE_FILE_OFFSET64
2c008571
UD
242/* Open a file and create a new stream for it.
243
244 This function is a possible cancellation point and therefore not
245 marked with __THROW. */
a784e502
UD
246extern FILE *fopen (const char *__restrict __filename,
247 const char *__restrict __modes) __wur;
2c008571
UD
248/* Open a file, replacing an existing stream with it.
249
250 This function is a possible cancellation point and therefore not
251 marked with __THROW. */
a784e502
UD
252extern FILE *freopen (const char *__restrict __filename,
253 const char *__restrict __modes,
11bf311e 254 FILE *__restrict __stream) __wur;
dfd2257a 255#else
01cad722 256# ifdef __REDIRECT
a784e502
UD
257extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
258 const char *__restrict __modes), fopen64)
11bf311e 259 __wur;
a784e502
UD
260extern FILE *__REDIRECT (freopen, (const char *__restrict __filename,
261 const char *__restrict __modes,
11bf311e
UD
262 FILE *__restrict __stream), freopen64)
263 __wur;
01cad722
UD
264# else
265# define fopen fopen64
266# define freopen freopen64
267# endif
dfd2257a
UD
268#endif
269#ifdef __USE_LARGEFILE64
a784e502
UD
270extern FILE *fopen64 (const char *__restrict __filename,
271 const char *__restrict __modes) __wur;
272extern FILE *freopen64 (const char *__restrict __filename,
273 const char *__restrict __modes,
11bf311e 274 FILE *__restrict __stream) __wur;
dfd2257a 275#endif
76060ec0 276
2f6d1f1b
UD
277#ifdef __USE_POSIX
278/* Create a new stream that refers to an existing system file descriptor. */
a784e502 279extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
96aa2d94
RM
280#endif
281
2f6d1f1b
UD
282#ifdef __USE_GNU
283/* Create a new stream that refers to the given magic cookie,
284 and uses the given functions for input and output. */
c1422e5b 285extern FILE *fopencookie (void *__restrict __magic_cookie,
a784e502 286 const char *__restrict __modes,
a4fea3f2 287 cookie_io_functions_t __io_funcs) __THROW __wur;
f503060b 288#endif
7a12c6bb 289
48789000 290#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
46e4bd3b 291/* Create a new stream that refers to a memory buffer. */
a784e502 292extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
11bf311e 293 __THROW __wur;
46e4bd3b 294
96aa2d94
RM
295/* Open a stream that writes into a malloc'd buffer that is expanded as
296 necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
297 and the number of characters written on fflush or fclose. */
11bf311e 298extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
96aa2d94
RM
299#endif
300
96aa2d94 301
2f6d1f1b
UD
302/* If BUF is NULL, make STREAM unbuffered.
303 Else make it use buffer BUF, of size BUFSIZ. */
c1422e5b 304extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
2f6d1f1b
UD
305/* Make STREAM use buffering mode MODE.
306 If BUF is not NULL, use N bytes of it for buffering;
307 else allocate an internal buffer N bytes long. */
c1422e5b
UD
308extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
309 int __modes, size_t __n) __THROW;
2f6d1f1b 310
498afc54 311#ifdef __USE_MISC
2f6d1f1b
UD
312/* If BUF is NULL, make STREAM unbuffered.
313 Else make it use SIZE bytes of BUF for buffering. */
c1422e5b
UD
314extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
315 size_t __size) __THROW;
2f6d1f1b
UD
316
317/* Make STREAM line-buffered. */
c1422e5b 318extern void setlinebuf (FILE *__stream) __THROW;
96aa2d94
RM
319#endif
320
2f6d1f1b 321
2c008571
UD
322/* Write formatted output to STREAM.
323
324 This function is a possible cancellation point and therefore not
325 marked with __THROW. */
c1422e5b 326extern int fprintf (FILE *__restrict __stream,
a784e502 327 const char *__restrict __format, ...);
2c008571
UD
328/* Write formatted output to stdout.
329
330 This function is a possible cancellation point and therefore not
331 marked with __THROW. */
a784e502 332extern int printf (const char *__restrict __format, ...);
2f6d1f1b 333/* Write formatted output to S. */
c1422e5b 334extern int sprintf (char *__restrict __s,
a784e502 335 const char *__restrict __format, ...) __THROWNL;
2f6d1f1b 336
2c008571
UD
337/* Write formatted output to S from argument list ARG.
338
339 This function is a possible cancellation point and therefore not
340 marked with __THROW. */
a784e502 341extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
a4fea3f2 342 __gnuc_va_list __arg);
2c008571
UD
343/* Write formatted output to stdout from argument list ARG.
344
345 This function is a possible cancellation point and therefore not
346 marked with __THROW. */
a4fea3f2 347extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
2f6d1f1b 348/* Write formatted output to S from argument list ARG. */
a784e502 349extern int vsprintf (char *__restrict __s, const char *__restrict __format,
a4fea3f2 350 __gnuc_va_list __arg) __THROWNL;
2f6d1f1b 351
acd7f096 352#if defined __USE_ISOC99 || defined __USE_UNIX98
2f6d1f1b 353/* Maximum chars of output to write in MAXLEN. */
c1422e5b 354extern int snprintf (char *__restrict __s, size_t __maxlen,
a784e502 355 const char *__restrict __format, ...)
9beb2334 356 __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
f41c8091 357
c1422e5b 358extern int vsnprintf (char *__restrict __s, size_t __maxlen,
a4fea3f2 359 const char *__restrict __format, __gnuc_va_list __arg)
9beb2334 360 __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
907a1bac 361#endif
2f6d1f1b 362
48789000 363#if __GLIBC_USE (LIB_EXT2)
2f6d1f1b
UD
364/* Write formatted output to a string dynamically allocated with `malloc'.
365 Store the address of the string in *PTR. */
a784e502 366extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
a4fea3f2 367 __gnuc_va_list __arg)
9beb2334 368 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
c1422e5b 369extern int __asprintf (char **__restrict __ptr,
a784e502 370 const char *__restrict __fmt, ...)
9beb2334 371 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
c1422e5b 372extern int asprintf (char **__restrict __ptr,
a784e502 373 const char *__restrict __fmt, ...)
9beb2334 374 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
f503060b 375#endif
2f6d1f1b 376
f503060b 377#ifdef __USE_XOPEN2K8
36c8acb4 378/* Write formatted output to a file descriptor. */
a784e502 379extern int vdprintf (int __fd, const char *__restrict __fmt,
a4fea3f2 380 __gnuc_va_list __arg)
2c008571 381 __attribute__ ((__format__ (__printf__, 2, 0)));
a784e502 382extern int dprintf (int __fd, const char *__restrict __fmt, ...)
2c008571 383 __attribute__ ((__format__ (__printf__, 2, 3)));
19361cb7 384#endif
7c713e28 385
2f6d1f1b 386
2c008571
UD
387/* Read formatted input from STREAM.
388
389 This function is a possible cancellation point and therefore not
390 marked with __THROW. */
c1422e5b 391extern int fscanf (FILE *__restrict __stream,
a784e502 392 const char *__restrict __format, ...) __wur;
2c008571
UD
393/* Read formatted input from stdin.
394
395 This function is a possible cancellation point and therefore not
396 marked with __THROW. */
a784e502 397extern int scanf (const char *__restrict __format, ...) __wur;
2f6d1f1b 398/* Read formatted input from S. */
a784e502
UD
399extern int sscanf (const char *__restrict __s,
400 const char *__restrict __format, ...) __THROW;
874aa523 401
03992356
ZW
402/* For historical reasons, the C99-compliant versions of the scanf
403 functions are at alternative names. When __LDBL_COMPAT is in
404 effect, this is handled in bits/stdio-ldbl.h. */
405#if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT
874aa523 406# ifdef __REDIRECT
874aa523 407extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
a784e502 408 const char *__restrict __format, ...),
874aa523 409 __isoc99_fscanf) __wur;
a784e502 410extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
874aa523 411 __isoc99_scanf) __wur;
a784e502
UD
412extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
413 const char *__restrict __format, ...),
f32f2869 414 __isoc99_sscanf);
874aa523
UD
415# else
416extern int __isoc99_fscanf (FILE *__restrict __stream,
a784e502
UD
417 const char *__restrict __format, ...) __wur;
418extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
419extern int __isoc99_sscanf (const char *__restrict __s,
420 const char *__restrict __format, ...) __THROW;
874aa523
UD
421# define fscanf __isoc99_fscanf
422# define scanf __isoc99_scanf
423# define sscanf __isoc99_sscanf
424# endif
425#endif
426
ec751a23 427#ifdef __USE_ISOC99
2c008571
UD
428/* Read formatted input from S into argument list ARG.
429
430 This function is a possible cancellation point and therefore not
431 marked with __THROW. */
a784e502 432extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
a4fea3f2 433 __gnuc_va_list __arg)
0476597b 434 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
2c008571
UD
435
436/* Read formatted input from stdin into argument list ARG.
2f6d1f1b 437
2c008571
UD
438 This function is a possible cancellation point and therefore not
439 marked with __THROW. */
a4fea3f2 440extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
0476597b 441 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
2f6d1f1b
UD
442
443/* Read formatted input from S into argument list ARG. */
a784e502 444extern int vsscanf (const char *__restrict __s,
a4fea3f2 445 const char *__restrict __format, __gnuc_va_list __arg)
7d506e8e 446 __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
874aa523 447
03992356
ZW
448/* Same redirection as above for the v*scanf family. */
449# if !__GLIBC_USE (DEPRECATED_SCANF)
450# if defined __REDIRECT && !defined __LDBL_COMPAT
874aa523
UD
451extern int __REDIRECT (vfscanf,
452 (FILE *__restrict __s,
a4fea3f2 453 const char *__restrict __format, __gnuc_va_list __arg),
874aa523
UD
454 __isoc99_vfscanf)
455 __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
a784e502 456extern int __REDIRECT (vscanf, (const char *__restrict __format,
a4fea3f2 457 __gnuc_va_list __arg), __isoc99_vscanf)
874aa523 458 __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
f32f2869 459extern int __REDIRECT_NTH (vsscanf,
a784e502
UD
460 (const char *__restrict __s,
461 const char *__restrict __format,
a4fea3f2 462 __gnuc_va_list __arg), __isoc99_vsscanf)
f32f2869 463 __attribute__ ((__format__ (__scanf__, 2, 0)));
03992356 464# elif !defined __REDIRECT
874aa523 465extern int __isoc99_vfscanf (FILE *__restrict __s,
a784e502 466 const char *__restrict __format,
a4fea3f2 467 __gnuc_va_list __arg) __wur;
a784e502 468extern int __isoc99_vscanf (const char *__restrict __format,
a4fea3f2 469 __gnuc_va_list __arg) __wur;
a784e502
UD
470extern int __isoc99_vsscanf (const char *__restrict __s,
471 const char *__restrict __format,
a4fea3f2 472 __gnuc_va_list __arg) __THROW;
874aa523 473# define vfscanf __isoc99_vfscanf
4e3be9d6 474# define vscanf __isoc99_vscanf
874aa523
UD
475# define vsscanf __isoc99_vsscanf
476# endif
477# endif
2b33e5b0 478#endif /* Use ISO C9x. */
2f6d1f1b
UD
479
480
2c008571 481/* Read a character from STREAM.
2f6d1f1b 482
2c008571
UD
483 These functions are possible cancellation points and therefore not
484 marked with __THROW. */
485extern int fgetc (FILE *__stream);
486extern int getc (FILE *__stream);
487
488/* Read a character from stdin.
489
490 This function is a possible cancellation point and therefore not
491 marked with __THROW. */
492extern int getchar (void);
2f6d1f1b 493
a7657f30 494#ifdef __USE_POSIX199506
2c008571
UD
495/* These are defined in POSIX.1:1996.
496
497 These functions are possible cancellation points and therefore not
498 marked with __THROW. */
499extern int getc_unlocked (FILE *__stream);
500extern int getchar_unlocked (void);
acd7f096 501#endif /* Use POSIX. */
2f6d1f1b 502
209caedf 503#ifdef __USE_MISC
2c008571
UD
504/* Faster version when locking is not necessary.
505
506 This function is not part of POSIX and therefore no official
507 cancellation point. But due to similarity with an POSIX interface
508 or due to the implementation it is a cancellation point and
509 therefore not marked with __THROW. */
510extern int fgetc_unlocked (FILE *__stream);
209caedf
UD
511#endif /* Use MISC. */
512
2f6d1f1b 513
2c008571
UD
514/* Write a character to STREAM.
515
516 These functions are possible cancellation points and therefore not
bc2e3689
UD
517 marked with __THROW.
518
519 These functions is a possible cancellation point and therefore not
2c008571 520 marked with __THROW. */
bc2e3689
UD
521extern int fputc (int __c, FILE *__stream);
522extern int putc (int __c, FILE *__stream);
2f6d1f1b 523
2c008571
UD
524/* Write a character to stdout.
525
526 This function is a possible cancellation point and therefore not
527 marked with __THROW. */
528extern int putchar (int __c);
2f6d1f1b 529
2f6d1f1b 530#ifdef __USE_MISC
2c008571
UD
531/* Faster version when locking is not necessary.
532
533 This function is not part of POSIX and therefore no official
534 cancellation point. But due to similarity with an POSIX interface
535 or due to the implementation it is a cancellation point and
536 therefore not marked with __THROW. */
537extern int fputc_unlocked (int __c, FILE *__stream);
2f6d1f1b
UD
538#endif /* Use MISC. */
539
a7657f30 540#ifdef __USE_POSIX199506
2c008571
UD
541/* These are defined in POSIX.1:1996.
542
543 These functions are possible cancellation points and therefore not
544 marked with __THROW. */
545extern int putc_unlocked (int __c, FILE *__stream);
546extern int putchar_unlocked (int __c);
acd7f096 547#endif /* Use POSIX. */
2f6d1f1b
UD
548
549
ed9a38e2 550#if defined __USE_MISC \
2c008571 551 || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
2f6d1f1b 552/* Get a word (int) from STREAM. */
bc2e3689 553extern int getw (FILE *__stream);
2f6d1f1b
UD
554
555/* Write a word (int) to STREAM. */
bc2e3689 556extern int putw (int __w, FILE *__stream);
96aa2d94
RM
557#endif
558
7c713e28 559
2c008571
UD
560/* Get a newline-terminated string of finite length from STREAM.
561
562 This function is a possible cancellation point and therefore not
563 marked with __THROW. */
0476597b
UD
564extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
565 __wur;
2f6d1f1b 566
7caa5054 567#if __GLIBC_USE (DEPRECATED_GETS)
7a5affeb 568/* Get a newline-terminated string from stdin, removing the newline.
2c008571 569
7caa5054
ZW
570 This function is impossible to use safely. It has been officially
571 removed from ISO C11 and ISO C++14, and we have also removed it
572 from the _GNU_SOURCE feature list. It remains available when
573 explicitly using an old ISO C, Unix, or POSIX standard.
03a71829 574
2c008571
UD
575 This function is a possible cancellation point and therefore not
576 marked with __THROW. */
16578fa7 577extern char *gets (char *__s) __wur __attribute_deprecated__;
03a71829 578#endif
7a5affeb 579
77ccaba1 580#ifdef __USE_GNU
2c008571
UD
581/* This function does the same as `fgets' but does not lock the stream.
582
583 This function is not part of POSIX and therefore no official
584 cancellation point. But due to similarity with an POSIX interface
585 or due to the implementation it is a cancellation point and
586 therefore not marked with __THROW. */
c1422e5b 587extern char *fgets_unlocked (char *__restrict __s, int __n,
0476597b 588 FILE *__restrict __stream) __wur;
77ccaba1
UD
589#endif
590
2f6d1f1b 591
48789000 592#if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
2f6d1f1b
UD
593/* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
594 (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
595 NULL), pointing to *N characters of space. It is realloc'd as
596 necessary. Returns the number of characters read (not including the
2c008571
UD
597 null terminator), or -1 on error or EOF.
598
599 These functions are not part of POSIX and therefore no official
600 cancellation point. But due to similarity with an POSIX interface
601 or due to the implementation they are cancellation points and
602 therefore not marked with __THROW. */
a4fea3f2
ZW
603extern __ssize_t __getdelim (char **__restrict __lineptr,
604 size_t *__restrict __n, int __delimiter,
605 FILE *__restrict __stream) __wur;
606extern __ssize_t getdelim (char **__restrict __lineptr,
607 size_t *__restrict __n, int __delimiter,
608 FILE *__restrict __stream) __wur;
2f6d1f1b 609
2c008571
UD
610/* Like `getdelim', but reads up to a newline.
611
612 This function is not part of POSIX and therefore no official
613 cancellation point. But due to similarity with an POSIX interface
614 or due to the implementation it is a cancellation point and
615 therefore not marked with __THROW. */
a4fea3f2
ZW
616extern __ssize_t getline (char **__restrict __lineptr,
617 size_t *__restrict __n,
618 FILE *__restrict __stream) __wur;
2f6d1f1b
UD
619#endif
620
621
2c008571
UD
622/* Write a string to STREAM.
623
4c1423ed 624 This function is a possible cancellation point and therefore not
2c008571 625 marked with __THROW. */
a784e502 626extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
2c008571
UD
627
628/* Write a string, followed by a newline, to stdout.
50304ef0 629
4c1423ed 630 This function is a possible cancellation point and therefore not
2c008571 631 marked with __THROW. */
a784e502 632extern int puts (const char *__s);
2f6d1f1b
UD
633
634
2c008571 635/* Push a character back onto the input buffer of STREAM.
2f6d1f1b 636
4c1423ed 637 This function is a possible cancellation point and therefore not
2c008571 638 marked with __THROW. */
7d506e8e 639extern int ungetc (int __c, FILE *__stream);
2f6d1f1b 640
2c008571
UD
641
642/* Read chunks of generic data from STREAM.
643
4c1423ed 644 This function is a possible cancellation point and therefore not
2c008571 645 marked with __THROW. */
c1422e5b 646extern size_t fread (void *__restrict __ptr, size_t __size,
0476597b 647 size_t __n, FILE *__restrict __stream) __wur;
2c008571
UD
648/* Write chunks of generic data to STREAM.
649
4c1423ed 650 This function is a possible cancellation point and therefore not
2c008571 651 marked with __THROW. */
a784e502 652extern size_t fwrite (const void *__restrict __ptr, size_t __size,
288f9098 653 size_t __n, FILE *__restrict __s);
7a5affeb
UD
654
655#ifdef __USE_GNU
2c008571
UD
656/* This function does the same as `fputs' but does not lock the stream.
657
658 This function is not part of POSIX and therefore no official
659 cancellation point. But due to similarity with an POSIX interface
660 or due to the implementation it is a cancellation point and
661 therefore not marked with __THROW. */
a784e502 662extern int fputs_unlocked (const char *__restrict __s,
2c008571 663 FILE *__restrict __stream);
7a5affeb 664#endif
2f6d1f1b
UD
665
666#ifdef __USE_MISC
2c008571
UD
667/* Faster versions when locking is not necessary.
668
669 These functions are not part of POSIX and therefore no official
670 cancellation point. But due to similarity with an POSIX interface
671 or due to the implementation they are cancellation points and
672 therefore not marked with __THROW. */
c1422e5b 673extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
0476597b 674 size_t __n, FILE *__restrict __stream) __wur;
a784e502 675extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
288f9098 676 size_t __n, FILE *__restrict __stream);
2f6d1f1b
UD
677#endif
678
679
2c008571
UD
680/* Seek to a certain position on STREAM.
681
682 This function is a possible cancellation point and therefore not
683 marked with __THROW. */
684extern int fseek (FILE *__stream, long int __off, int __whence);
685/* Return the current position of STREAM.
686
687 This function is a possible cancellation point and therefore not
688 marked with __THROW. */
0476597b 689extern long int ftell (FILE *__stream) __wur;
2c008571
UD
690/* Rewind to the beginning of STREAM.
691
692 This function is a possible cancellation point and therefore not
693 marked with __THROW. */
694extern void rewind (FILE *__stream);
2f6d1f1b 695
a5a0310d
UD
696/* The Single Unix Specification, Version 2, specifies an alternative,
697 more adequate interface for the two functions above which deal with
dfd2257a
UD
698 file offset. `long int' is not the right type. These definitions
699 are originally defined in the Large File Support API. */
700
7a80496f 701#if defined __USE_LARGEFILE || defined __USE_XOPEN2K
7a5affeb 702# ifndef __USE_FILE_OFFSET64
2c008571
UD
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 fseeko (FILE *__stream, __off_t __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. */
0476597b 712extern __off_t ftello (FILE *__stream) __wur;
7a5affeb
UD
713# else
714# ifdef __REDIRECT
715extern int __REDIRECT (fseeko,
2c008571 716 (FILE *__stream, __off64_t __off, int __whence),
7a5affeb 717 fseeko64);
2c008571 718extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64);
7a5affeb
UD
719# else
720# define fseeko fseeko64
721# define ftello ftello64
722# endif
6796bc80 723# endif
7a5affeb 724#endif
bfce746a 725
7a5affeb 726#ifndef __USE_FILE_OFFSET64
2c008571
UD
727/* Get STREAM's position.
728
729 This function is a possible cancellation point and therefore not
730 marked with __THROW. */
731extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
732/* Set STREAM's position.
733
734 This function is a possible cancellation point and therefore not
735 marked with __THROW. */
a784e502 736extern int fsetpos (FILE *__stream, const fpos_t *__pos);
bfce746a 737#else
01cad722 738# ifdef __REDIRECT
c1422e5b 739extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
2c008571 740 fpos_t *__restrict __pos), fgetpos64);
c1422e5b 741extern int __REDIRECT (fsetpos,
a784e502 742 (FILE *__stream, const fpos_t *__pos), fsetpos64);
bfce746a 743# else
bfce746a
UD
744# define fgetpos fgetpos64
745# define fsetpos fsetpos64
dfd2257a 746# endif
bfce746a 747#endif
01cad722 748
bfce746a 749#ifdef __USE_LARGEFILE64
2c008571 750extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
0476597b 751extern __off64_t ftello64 (FILE *__stream) __wur;
2c008571 752extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
a784e502 753extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
dfd2257a 754#endif
2f6d1f1b 755
2f6d1f1b 756/* Clear the error and EOF indicators for STREAM. */
c1422e5b 757extern void clearerr (FILE *__stream) __THROW;
2f6d1f1b 758/* Return the EOF indicator for STREAM. */
7d506e8e 759extern int feof (FILE *__stream) __THROW __wur;
2f6d1f1b 760/* Return the error indicator for STREAM. */
7d506e8e 761extern int ferror (FILE *__stream) __THROW __wur;
2f6d1f1b
UD
762
763#ifdef __USE_MISC
764/* Faster versions when locking is not required. */
c1422e5b 765extern void clearerr_unlocked (FILE *__stream) __THROW;
7d506e8e
UD
766extern int feof_unlocked (FILE *__stream) __THROW __wur;
767extern int ferror_unlocked (FILE *__stream) __THROW __wur;
2f6d1f1b
UD
768#endif
769
770
2c008571
UD
771/* Print a message describing the meaning of the value of errno.
772
773 This function is a possible cancellation point and therefore not
774 marked with __THROW. */
a784e502 775extern void perror (const char *__s);
2f6d1f1b 776
b264e1d1
RM
777/* Provide the declarations for `sys_errlist' and `sys_nerr' if they
778 are available on this system. Even if available, these variables
779 should not be used directly. The `strerror' function provides
780 all the necessary functionality. */
781#include <bits/sys_errlist.h>
2f6d1f1b
UD
782
783
784#ifdef __USE_POSIX
785/* Return the system file descriptor for STREAM. */
7d506e8e 786extern int fileno (FILE *__stream) __THROW __wur;
2f6d1f1b
UD
787#endif /* Use POSIX. */
788
789#ifdef __USE_MISC
790/* Faster version when locking is not required. */
7d506e8e 791extern int fileno_unlocked (FILE *__stream) __THROW __wur;
2f6d1f1b
UD
792#endif
793
794
acd7f096 795#ifdef __USE_POSIX2
bc2e3689
UD
796/* Create a new stream connected to a pipe running the given command.
797
798 This function is a possible cancellation point and therefore not
799 marked with __THROW. */
a784e502 800extern FILE *popen (const char *__command, const char *__modes) __wur;
2c008571 801
bc2e3689
UD
802/* Close a stream opened by popen and return the status of its child.
803
804 This function is a possible cancellation point and therefore not
805 marked with __THROW. */
806extern int pclose (FILE *__stream);
2f6d1f1b
UD
807#endif
808
809
810#ifdef __USE_POSIX
811/* Return the name of the controlling terminal. */
c1422e5b 812extern char *ctermid (char *__s) __THROW;
2f6d1f1b
UD
813#endif /* Use POSIX. */
814
815
12404bb0 816#if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
2f6d1f1b 817/* Return the name of the current user. */
8dab36a1 818extern char *cuserid (char *__s);
219aa9e9 819#endif /* Use X/Open, but not issue 6. */
2f6d1f1b
UD
820
821
822#ifdef __USE_GNU
823struct obstack; /* See <obstack.h>. */
824
825/* Write formatted output to an obstack. */
c1422e5b 826extern int obstack_printf (struct obstack *__restrict __obstack,
a784e502 827 const char *__restrict __format, ...)
9beb2334 828 __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
c1422e5b 829extern int obstack_vprintf (struct obstack *__restrict __obstack,
a784e502 830 const char *__restrict __format,
a4fea3f2 831 __gnuc_va_list __args)
9beb2334 832 __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
2f6d1f1b
UD
833#endif /* Use GNU. */
834
835
a7657f30 836#ifdef __USE_POSIX199506
2f6d1f1b
UD
837/* These are defined in POSIX.1:1996. */
838
839/* Acquire ownership of STREAM. */
c1422e5b 840extern void flockfile (FILE *__stream) __THROW;
2f6d1f1b
UD
841
842/* Try to acquire ownership of STREAM but do not block if it is not
843 possible. */
0476597b 844extern int ftrylockfile (FILE *__stream) __THROW __wur;
2f6d1f1b
UD
845
846/* Relinquish the ownership granted for STREAM. */
c1422e5b 847extern void funlockfile (FILE *__stream) __THROW;
acd7f096 848#endif /* POSIX */
2f6d1f1b 849
219aa9e9 850#if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
10a33cf8
ZW
851/* X/Open Issues 1-5 required getopt to be declared in this
852 header. It was removed in Issue 6. GNU follows Issue 6. */
853# include <bits/getopt_posix.h>
854#endif
9756dfe1 855
a4fea3f2
ZW
856/* Slow-path routines used by the optimized inline functions in
857 bits/stdio.h. */
858extern int __uflow (FILE *);
859extern int __overflow (FILE *, int);
860
085320f5 861/* If we are compiling with optimizing read this file. It contains
9b2c7523 862 several optimizing inline functions and macros. */
085320f5
UD
863#ifdef __USE_EXTERN_INLINES
864# include <bits/stdio.h>
865#endif
884ddc50 866#if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
b5cc329c
UD
867# include <bits/stdio2.h>
868#endif
c6251f03
RM
869#ifdef __LDBL_COMPAT
870# include <bits/stdio-ldbl.h>
871#endif
2f6d1f1b 872
085320f5 873__END_DECLS
f41c8091 874
2f6d1f1b 875#endif /* <stdio.h> included. */