stdio.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876
  1. /* Define ISO C stdio on top of C++ iostreams.
  2. Copyright (C) 1991-2021 Free Software Foundation, Inc.
  3. This file is part of the GNU C Library.
  4. The GNU C Library is free software; you can redistribute it and/or
  5. modify it under the terms of the GNU Lesser General Public
  6. License as published by the Free Software Foundation; either
  7. version 2.1 of the License, or (at your option) any later version.
  8. The GNU C Library is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  11. Lesser General Public License for more details.
  12. You should have received a copy of the GNU Lesser General Public
  13. License along with the GNU C Library; if not, see
  14. <https://www.gnu.org/licenses/>. */
  15. /*
  16. * ISO C99 Standard: 7.19 Input/output <stdio.h>
  17. */
  18. #ifndef _STDIO_H
  19. #define _STDIO_H 1
  20. #define __GLIBC_INTERNAL_STARTING_HEADER_IMPLEMENTATION
  21. #include <bits/libc-header-start.h>
  22. __BEGIN_DECLS
  23. #define __need_size_t
  24. #define __need_NULL
  25. #include <stddef.h>
  26. #define __need___va_list
  27. #include <stdarg.h>
  28. #include <bits/types.h>
  29. #include <bits/types/__fpos_t.h>
  30. #include <bits/types/__fpos64_t.h>
  31. #include <bits/types/__FILE.h>
  32. #include <bits/types/FILE.h>
  33. #include <bits/types/struct_FILE.h>
  34. #ifdef __USE_GNU
  35. # include <bits/types/cookie_io_functions_t.h>
  36. #endif
  37. #if defined __USE_XOPEN || defined __USE_XOPEN2K8
  38. # ifdef __GNUC__
  39. # ifndef _VA_LIST_DEFINED
  40. typedef __gnuc_va_list va_list;
  41. # define _VA_LIST_DEFINED
  42. # endif
  43. # else
  44. # include <stdarg.h>
  45. # endif
  46. #endif
  47. #if defined __USE_UNIX98 || defined __USE_XOPEN2K
  48. # ifndef __off_t_defined
  49. # ifndef __USE_FILE_OFFSET64
  50. typedef __off_t off_t;
  51. # else
  52. typedef __off64_t off_t;
  53. # endif
  54. # define __off_t_defined
  55. # endif
  56. # if defined __USE_LARGEFILE64 && !defined __off64_t_defined
  57. typedef __off64_t off64_t;
  58. # define __off64_t_defined
  59. # endif
  60. #endif
  61. #ifdef __USE_XOPEN2K8
  62. # ifndef __ssize_t_defined
  63. typedef __ssize_t ssize_t;
  64. # define __ssize_t_defined
  65. # endif
  66. #endif
  67. /* The type of the second argument to `fgetpos' and `fsetpos'. */
  68. #ifndef __USE_FILE_OFFSET64
  69. typedef __fpos_t fpos_t;
  70. #else
  71. typedef __fpos64_t fpos_t;
  72. #endif
  73. #ifdef __USE_LARGEFILE64
  74. typedef __fpos64_t fpos64_t;
  75. #endif
  76. /* The possibilities for the third argument to `setvbuf'. */
  77. #define _IOFBF 0 /* Fully buffered. */
  78. #define _IOLBF 1 /* Line buffered. */
  79. #define _IONBF 2 /* No buffering. */
  80. /* Default buffer size. */
  81. #define BUFSIZ 8192
  82. /* The value returned by fgetc and similar functions to indicate the
  83. end of the file. */
  84. #define EOF (-1)
  85. /* The possibilities for the third argument to `fseek'.
  86. These values should not be changed. */
  87. #define SEEK_SET 0 /* Seek from beginning of file. */
  88. #define SEEK_CUR 1 /* Seek from current position. */
  89. #define SEEK_END 2 /* Seek from end of file. */
  90. #ifdef __USE_GNU
  91. # define SEEK_DATA 3 /* Seek to next data. */
  92. # define SEEK_HOLE 4 /* Seek to next hole. */
  93. #endif
  94. #if defined __USE_MISC || defined __USE_XOPEN
  95. /* Default path prefix for `tempnam' and `tmpnam'. */
  96. # define P_tmpdir "/tmp"
  97. #endif
  98. /* Get the values:
  99. L_tmpnam How long an array of chars must be to be passed to `tmpnam'.
  100. TMP_MAX The minimum number of unique filenames generated by tmpnam
  101. (and tempnam when it uses tmpnam's name space),
  102. or tempnam (the two are separate).
  103. L_ctermid How long an array to pass to `ctermid'.
  104. L_cuserid How long an array to pass to `cuserid'.
  105. FOPEN_MAX Minimum number of files that can be open at once.
  106. FILENAME_MAX Maximum length of a filename. */
  107. #include <bits/stdio_lim.h>
  108. /* Standard streams. */
  109. extern FILE *stdin; /* Standard input stream. */
  110. extern FILE *stdout; /* Standard output stream. */
  111. extern FILE *stderr; /* Standard error output stream. */
  112. /* C89/C99 say they're macros. Make them happy. */
  113. #define stdin stdin
  114. #define stdout stdout
  115. #define stderr stderr
  116. /* Remove file FILENAME. */
  117. extern int remove (const char *__filename) __THROW;
  118. /* Rename file OLD to NEW. */
  119. extern int rename (const char *__old, const char *__new) __THROW;
  120. #ifdef __USE_ATFILE
  121. /* Rename file OLD relative to OLDFD to NEW relative to NEWFD. */
  122. extern int renameat (int __oldfd, const char *__old, int __newfd,
  123. const char *__new) __THROW;
  124. #endif
  125. #ifdef __USE_GNU
  126. /* Flags for renameat2. */
  127. # define RENAME_NOREPLACE (1 << 0)
  128. # define RENAME_EXCHANGE (1 << 1)
  129. # define RENAME_WHITEOUT (1 << 2)
  130. /* Rename file OLD relative to OLDFD to NEW relative to NEWFD, with
  131. additional flags. */
  132. extern int renameat2 (int __oldfd, const char *__old, int __newfd,
  133. const char *__new, unsigned int __flags) __THROW;
  134. #endif
  135. /* Create a temporary file and open it read/write.
  136. This function is a possible cancellation point and therefore not
  137. marked with __THROW. */
  138. #ifndef __USE_FILE_OFFSET64
  139. extern FILE *tmpfile (void) __wur;
  140. #else
  141. # ifdef __REDIRECT
  142. extern FILE *__REDIRECT (tmpfile, (void), tmpfile64) __wur;
  143. # else
  144. # define tmpfile tmpfile64
  145. # endif
  146. #endif
  147. #ifdef __USE_LARGEFILE64
  148. extern FILE *tmpfile64 (void) __wur;
  149. #endif
  150. /* Generate a temporary filename. */
  151. extern char *tmpnam (char *__s) __THROW __wur;
  152. #ifdef __USE_MISC
  153. /* This is the reentrant variant of `tmpnam'. The only difference is
  154. that it does not allow S to be NULL. */
  155. extern char *tmpnam_r (char *__s) __THROW __wur;
  156. #endif
  157. #if defined __USE_MISC || defined __USE_XOPEN
  158. /* Generate a unique temporary filename using up to five characters of PFX
  159. if it is not NULL. The directory to put this file in is searched for
  160. as follows: First the environment variable "TMPDIR" is checked.
  161. If it contains the name of a writable directory, that directory is used.
  162. If not and if DIR is not NULL, that value is checked. If that fails,
  163. P_tmpdir is tried and finally "/tmp". The storage for the filename
  164. is allocated by `malloc'. */
  165. extern char *tempnam (const char *__dir, const char *__pfx)
  166. __THROW __attribute_malloc__ __wur;
  167. #endif
  168. /* Close STREAM.
  169. This function is a possible cancellation point and therefore not
  170. marked with __THROW. */
  171. extern int fclose (FILE *__stream);
  172. /* Flush STREAM, or all streams if STREAM is NULL.
  173. This function is a possible cancellation point and therefore not
  174. marked with __THROW. */
  175. extern int fflush (FILE *__stream);
  176. #ifdef __USE_MISC
  177. /* Faster versions when locking is not required.
  178. This function is not part of POSIX and therefore no official
  179. cancellation point. But due to similarity with an POSIX interface
  180. or due to the implementation it is a cancellation point and
  181. therefore not marked with __THROW. */
  182. extern int fflush_unlocked (FILE *__stream);
  183. #endif
  184. #ifdef __USE_GNU
  185. /* Close all streams.
  186. This function is not part of POSIX and therefore no official
  187. cancellation point. But due to similarity with an POSIX interface
  188. or due to the implementation it is a cancellation point and
  189. therefore not marked with __THROW. */
  190. extern int fcloseall (void);
  191. #endif
  192. #ifndef __USE_FILE_OFFSET64
  193. /* Open a file and create a new stream for it.
  194. This function is a possible cancellation point and therefore not
  195. marked with __THROW. */
  196. extern FILE *fopen (const char *__restrict __filename,
  197. const char *__restrict __modes) __wur;
  198. /* Open a file, replacing an existing stream with it.
  199. This function is a possible cancellation point and therefore not
  200. marked with __THROW. */
  201. extern FILE *freopen (const char *__restrict __filename,
  202. const char *__restrict __modes,
  203. FILE *__restrict __stream) __wur;
  204. #else
  205. # ifdef __REDIRECT
  206. extern FILE *__REDIRECT (fopen, (const char *__restrict __filename,
  207. const char *__restrict __modes), fopen64)
  208. __wur;
  209. extern FILE *__REDIRECT (freopen, (const char *__restrict __filename,
  210. const char *__restrict __modes,
  211. FILE *__restrict __stream), freopen64)
  212. __wur;
  213. # else
  214. # define fopen fopen64
  215. # define freopen freopen64
  216. # endif
  217. #endif
  218. #ifdef __USE_LARGEFILE64
  219. extern FILE *fopen64 (const char *__restrict __filename,
  220. const char *__restrict __modes) __wur;
  221. extern FILE *freopen64 (const char *__restrict __filename,
  222. const char *__restrict __modes,
  223. FILE *__restrict __stream) __wur;
  224. #endif
  225. #ifdef __USE_POSIX
  226. /* Create a new stream that refers to an existing system file descriptor. */
  227. extern FILE *fdopen (int __fd, const char *__modes) __THROW __wur;
  228. #endif
  229. #ifdef __USE_GNU
  230. /* Create a new stream that refers to the given magic cookie,
  231. and uses the given functions for input and output. */
  232. extern FILE *fopencookie (void *__restrict __magic_cookie,
  233. const char *__restrict __modes,
  234. cookie_io_functions_t __io_funcs) __THROW __wur;
  235. #endif
  236. #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
  237. /* Create a new stream that refers to a memory buffer. */
  238. extern FILE *fmemopen (void *__s, size_t __len, const char *__modes)
  239. __THROW __wur;
  240. /* Open a stream that writes into a malloc'd buffer that is expanded as
  241. necessary. *BUFLOC and *SIZELOC are updated with the buffer's location
  242. and the number of characters written on fflush or fclose. */
  243. extern FILE *open_memstream (char **__bufloc, size_t *__sizeloc) __THROW __wur;
  244. #endif
  245. /* If BUF is NULL, make STREAM unbuffered.
  246. Else make it use buffer BUF, of size BUFSIZ. */
  247. extern void setbuf (FILE *__restrict __stream, char *__restrict __buf) __THROW;
  248. /* Make STREAM use buffering mode MODE.
  249. If BUF is not NULL, use N bytes of it for buffering;
  250. else allocate an internal buffer N bytes long. */
  251. extern int setvbuf (FILE *__restrict __stream, char *__restrict __buf,
  252. int __modes, size_t __n) __THROW;
  253. #ifdef __USE_MISC
  254. /* If BUF is NULL, make STREAM unbuffered.
  255. Else make it use SIZE bytes of BUF for buffering. */
  256. extern void setbuffer (FILE *__restrict __stream, char *__restrict __buf,
  257. size_t __size) __THROW;
  258. /* Make STREAM line-buffered. */
  259. extern void setlinebuf (FILE *__stream) __THROW;
  260. #endif
  261. /* Write formatted output to STREAM.
  262. This function is a possible cancellation point and therefore not
  263. marked with __THROW. */
  264. extern int fprintf (FILE *__restrict __stream,
  265. const char *__restrict __format, ...);
  266. /* Write formatted output to stdout.
  267. This function is a possible cancellation point and therefore not
  268. marked with __THROW. */
  269. extern int printf (const char *__restrict __format, ...);
  270. /* Write formatted output to S. */
  271. extern int sprintf (char *__restrict __s,
  272. const char *__restrict __format, ...) __THROWNL;
  273. /* Write formatted output to S from argument list ARG.
  274. This function is a possible cancellation point and therefore not
  275. marked with __THROW. */
  276. extern int vfprintf (FILE *__restrict __s, const char *__restrict __format,
  277. __gnuc_va_list __arg);
  278. /* Write formatted output to stdout from argument list ARG.
  279. This function is a possible cancellation point and therefore not
  280. marked with __THROW. */
  281. extern int vprintf (const char *__restrict __format, __gnuc_va_list __arg);
  282. /* Write formatted output to S from argument list ARG. */
  283. extern int vsprintf (char *__restrict __s, const char *__restrict __format,
  284. __gnuc_va_list __arg) __THROWNL;
  285. #if defined __USE_ISOC99 || defined __USE_UNIX98
  286. /* Maximum chars of output to write in MAXLEN. */
  287. extern int snprintf (char *__restrict __s, size_t __maxlen,
  288. const char *__restrict __format, ...)
  289. __THROWNL __attribute__ ((__format__ (__printf__, 3, 4)));
  290. extern int vsnprintf (char *__restrict __s, size_t __maxlen,
  291. const char *__restrict __format, __gnuc_va_list __arg)
  292. __THROWNL __attribute__ ((__format__ (__printf__, 3, 0)));
  293. #endif
  294. #if __GLIBC_USE (LIB_EXT2)
  295. /* Write formatted output to a string dynamically allocated with `malloc'.
  296. Store the address of the string in *PTR. */
  297. extern int vasprintf (char **__restrict __ptr, const char *__restrict __f,
  298. __gnuc_va_list __arg)
  299. __THROWNL __attribute__ ((__format__ (__printf__, 2, 0))) __wur;
  300. extern int __asprintf (char **__restrict __ptr,
  301. const char *__restrict __fmt, ...)
  302. __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
  303. extern int asprintf (char **__restrict __ptr,
  304. const char *__restrict __fmt, ...)
  305. __THROWNL __attribute__ ((__format__ (__printf__, 2, 3))) __wur;
  306. #endif
  307. #ifdef __USE_XOPEN2K8
  308. /* Write formatted output to a file descriptor. */
  309. extern int vdprintf (int __fd, const char *__restrict __fmt,
  310. __gnuc_va_list __arg)
  311. __attribute__ ((__format__ (__printf__, 2, 0)));
  312. extern int dprintf (int __fd, const char *__restrict __fmt, ...)
  313. __attribute__ ((__format__ (__printf__, 2, 3)));
  314. #endif
  315. /* Read formatted input from STREAM.
  316. This function is a possible cancellation point and therefore not
  317. marked with __THROW. */
  318. extern int fscanf (FILE *__restrict __stream,
  319. const char *__restrict __format, ...) __wur;
  320. /* Read formatted input from stdin.
  321. This function is a possible cancellation point and therefore not
  322. marked with __THROW. */
  323. extern int scanf (const char *__restrict __format, ...) __wur;
  324. /* Read formatted input from S. */
  325. extern int sscanf (const char *__restrict __s,
  326. const char *__restrict __format, ...) __THROW;
  327. /* For historical reasons, the C99-compliant versions of the scanf
  328. functions are at alternative names. When __LDBL_COMPAT or
  329. __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI are in effect, this is handled in
  330. bits/stdio-ldbl.h. */
  331. #include <bits/floatn.h>
  332. #if !__GLIBC_USE (DEPRECATED_SCANF) && !defined __LDBL_COMPAT \
  333. && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
  334. # ifdef __REDIRECT
  335. extern int __REDIRECT (fscanf, (FILE *__restrict __stream,
  336. const char *__restrict __format, ...),
  337. __isoc99_fscanf) __wur;
  338. extern int __REDIRECT (scanf, (const char *__restrict __format, ...),
  339. __isoc99_scanf) __wur;
  340. extern int __REDIRECT_NTH (sscanf, (const char *__restrict __s,
  341. const char *__restrict __format, ...),
  342. __isoc99_sscanf);
  343. # else
  344. extern int __isoc99_fscanf (FILE *__restrict __stream,
  345. const char *__restrict __format, ...) __wur;
  346. extern int __isoc99_scanf (const char *__restrict __format, ...) __wur;
  347. extern int __isoc99_sscanf (const char *__restrict __s,
  348. const char *__restrict __format, ...) __THROW;
  349. # define fscanf __isoc99_fscanf
  350. # define scanf __isoc99_scanf
  351. # define sscanf __isoc99_sscanf
  352. # endif
  353. #endif
  354. #ifdef __USE_ISOC99
  355. /* Read formatted input from S into argument list ARG.
  356. This function is a possible cancellation point and therefore not
  357. marked with __THROW. */
  358. extern int vfscanf (FILE *__restrict __s, const char *__restrict __format,
  359. __gnuc_va_list __arg)
  360. __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
  361. /* Read formatted input from stdin into argument list ARG.
  362. This function is a possible cancellation point and therefore not
  363. marked with __THROW. */
  364. extern int vscanf (const char *__restrict __format, __gnuc_va_list __arg)
  365. __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
  366. /* Read formatted input from S into argument list ARG. */
  367. extern int vsscanf (const char *__restrict __s,
  368. const char *__restrict __format, __gnuc_va_list __arg)
  369. __THROW __attribute__ ((__format__ (__scanf__, 2, 0)));
  370. /* Same redirection as above for the v*scanf family. */
  371. # if !__GLIBC_USE (DEPRECATED_SCANF)
  372. # if defined __REDIRECT && !defined __LDBL_COMPAT \
  373. && __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 0
  374. extern int __REDIRECT (vfscanf,
  375. (FILE *__restrict __s,
  376. const char *__restrict __format, __gnuc_va_list __arg),
  377. __isoc99_vfscanf)
  378. __attribute__ ((__format__ (__scanf__, 2, 0))) __wur;
  379. extern int __REDIRECT (vscanf, (const char *__restrict __format,
  380. __gnuc_va_list __arg), __isoc99_vscanf)
  381. __attribute__ ((__format__ (__scanf__, 1, 0))) __wur;
  382. extern int __REDIRECT_NTH (vsscanf,
  383. (const char *__restrict __s,
  384. const char *__restrict __format,
  385. __gnuc_va_list __arg), __isoc99_vsscanf)
  386. __attribute__ ((__format__ (__scanf__, 2, 0)));
  387. # elif !defined __REDIRECT
  388. extern int __isoc99_vfscanf (FILE *__restrict __s,
  389. const char *__restrict __format,
  390. __gnuc_va_list __arg) __wur;
  391. extern int __isoc99_vscanf (const char *__restrict __format,
  392. __gnuc_va_list __arg) __wur;
  393. extern int __isoc99_vsscanf (const char *__restrict __s,
  394. const char *__restrict __format,
  395. __gnuc_va_list __arg) __THROW;
  396. # define vfscanf __isoc99_vfscanf
  397. # define vscanf __isoc99_vscanf
  398. # define vsscanf __isoc99_vsscanf
  399. # endif
  400. # endif
  401. #endif /* Use ISO C9x. */
  402. /* Read a character from STREAM.
  403. These functions are possible cancellation points and therefore not
  404. marked with __THROW. */
  405. extern int fgetc (FILE *__stream);
  406. extern int getc (FILE *__stream);
  407. /* Read a character from stdin.
  408. This function is a possible cancellation point and therefore not
  409. marked with __THROW. */
  410. extern int getchar (void);
  411. #ifdef __USE_POSIX199506
  412. /* These are defined in POSIX.1:1996.
  413. These functions are possible cancellation points and therefore not
  414. marked with __THROW. */
  415. extern int getc_unlocked (FILE *__stream);
  416. extern int getchar_unlocked (void);
  417. #endif /* Use POSIX. */
  418. #ifdef __USE_MISC
  419. /* Faster version when locking is not necessary.
  420. This function is not part of POSIX and therefore no official
  421. cancellation point. But due to similarity with an POSIX interface
  422. or due to the implementation it is a cancellation point and
  423. therefore not marked with __THROW. */
  424. extern int fgetc_unlocked (FILE *__stream);
  425. #endif /* Use MISC. */
  426. /* Write a character to STREAM.
  427. These functions are possible cancellation points and therefore not
  428. marked with __THROW.
  429. These functions is a possible cancellation point and therefore not
  430. marked with __THROW. */
  431. extern int fputc (int __c, FILE *__stream);
  432. extern int putc (int __c, FILE *__stream);
  433. /* Write a character to stdout.
  434. This function is a possible cancellation point and therefore not
  435. marked with __THROW. */
  436. extern int putchar (int __c);
  437. #ifdef __USE_MISC
  438. /* Faster version when locking is not necessary.
  439. This function is not part of POSIX and therefore no official
  440. cancellation point. But due to similarity with an POSIX interface
  441. or due to the implementation it is a cancellation point and
  442. therefore not marked with __THROW. */
  443. extern int fputc_unlocked (int __c, FILE *__stream);
  444. #endif /* Use MISC. */
  445. #ifdef __USE_POSIX199506
  446. /* These are defined in POSIX.1:1996.
  447. These functions are possible cancellation points and therefore not
  448. marked with __THROW. */
  449. extern int putc_unlocked (int __c, FILE *__stream);
  450. extern int putchar_unlocked (int __c);
  451. #endif /* Use POSIX. */
  452. #if defined __USE_MISC \
  453. || (defined __USE_XOPEN && !defined __USE_XOPEN2K)
  454. /* Get a word (int) from STREAM. */
  455. extern int getw (FILE *__stream);
  456. /* Write a word (int) to STREAM. */
  457. extern int putw (int __w, FILE *__stream);
  458. #endif
  459. /* Get a newline-terminated string of finite length from STREAM.
  460. This function is a possible cancellation point and therefore not
  461. marked with __THROW. */
  462. extern char *fgets (char *__restrict __s, int __n, FILE *__restrict __stream)
  463. __wur __attr_access ((__write_only__, 1, 2));
  464. #if __GLIBC_USE (DEPRECATED_GETS)
  465. /* Get a newline-terminated string from stdin, removing the newline.
  466. This function is impossible to use safely. It has been officially
  467. removed from ISO C11 and ISO C++14, and we have also removed it
  468. from the _GNU_SOURCE feature list. It remains available when
  469. explicitly using an old ISO C, Unix, or POSIX standard.
  470. This function is a possible cancellation point and therefore not
  471. marked with __THROW. */
  472. extern char *gets (char *__s) __wur __attribute_deprecated__;
  473. #endif
  474. #ifdef __USE_GNU
  475. /* This function does the same as `fgets' but does not lock the stream.
  476. This function is not part of POSIX and therefore no official
  477. cancellation point. But due to similarity with an POSIX interface
  478. or due to the implementation it is a cancellation point and
  479. therefore not marked with __THROW. */
  480. extern char *fgets_unlocked (char *__restrict __s, int __n,
  481. FILE *__restrict __stream) __wur
  482. __attr_access ((__write_only__, 1, 2));
  483. #endif
  484. #if defined __USE_XOPEN2K8 || __GLIBC_USE (LIB_EXT2)
  485. /* Read up to (and including) a DELIMITER from STREAM into *LINEPTR
  486. (and null-terminate it). *LINEPTR is a pointer returned from malloc (or
  487. NULL), pointing to *N characters of space. It is realloc'd as
  488. necessary. Returns the number of characters read (not including the
  489. null terminator), or -1 on error or EOF.
  490. These functions are not part of POSIX and therefore no official
  491. cancellation point. But due to similarity with an POSIX interface
  492. or due to the implementation they are cancellation points and
  493. therefore not marked with __THROW. */
  494. extern __ssize_t __getdelim (char **__restrict __lineptr,
  495. size_t *__restrict __n, int __delimiter,
  496. FILE *__restrict __stream) __wur;
  497. extern __ssize_t getdelim (char **__restrict __lineptr,
  498. size_t *__restrict __n, int __delimiter,
  499. FILE *__restrict __stream) __wur;
  500. /* Like `getdelim', but reads up to a newline.
  501. This function is not part of POSIX and therefore no official
  502. cancellation point. But due to similarity with an POSIX interface
  503. or due to the implementation it is a cancellation point and
  504. therefore not marked with __THROW. */
  505. extern __ssize_t getline (char **__restrict __lineptr,
  506. size_t *__restrict __n,
  507. FILE *__restrict __stream) __wur;
  508. #endif
  509. /* Write a string to STREAM.
  510. This function is a possible cancellation point and therefore not
  511. marked with __THROW. */
  512. extern int fputs (const char *__restrict __s, FILE *__restrict __stream);
  513. /* Write a string, followed by a newline, to stdout.
  514. This function is a possible cancellation point and therefore not
  515. marked with __THROW. */
  516. extern int puts (const char *__s);
  517. /* Push a character back onto the input buffer of STREAM.
  518. This function is a possible cancellation point and therefore not
  519. marked with __THROW. */
  520. extern int ungetc (int __c, FILE *__stream);
  521. /* Read chunks of generic data from STREAM.
  522. This function is a possible cancellation point and therefore not
  523. marked with __THROW. */
  524. extern size_t fread (void *__restrict __ptr, size_t __size,
  525. size_t __n, FILE *__restrict __stream) __wur;
  526. /* Write chunks of generic data to STREAM.
  527. This function is a possible cancellation point and therefore not
  528. marked with __THROW. */
  529. extern size_t fwrite (const void *__restrict __ptr, size_t __size,
  530. size_t __n, FILE *__restrict __s);
  531. #ifdef __USE_GNU
  532. /* This function does the same as `fputs' but does not lock the stream.
  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. */
  537. extern int fputs_unlocked (const char *__restrict __s,
  538. FILE *__restrict __stream);
  539. #endif
  540. #ifdef __USE_MISC
  541. /* Faster versions when locking is not necessary.
  542. These functions are not part of POSIX and therefore no official
  543. cancellation point. But due to similarity with an POSIX interface
  544. or due to the implementation they are cancellation points and
  545. therefore not marked with __THROW. */
  546. extern size_t fread_unlocked (void *__restrict __ptr, size_t __size,
  547. size_t __n, FILE *__restrict __stream) __wur;
  548. extern size_t fwrite_unlocked (const void *__restrict __ptr, size_t __size,
  549. size_t __n, FILE *__restrict __stream);
  550. #endif
  551. /* Seek to a certain position on STREAM.
  552. This function is a possible cancellation point and therefore not
  553. marked with __THROW. */
  554. extern int fseek (FILE *__stream, long int __off, int __whence);
  555. /* Return the current position of STREAM.
  556. This function is a possible cancellation point and therefore not
  557. marked with __THROW. */
  558. extern long int ftell (FILE *__stream) __wur;
  559. /* Rewind to the beginning of STREAM.
  560. This function is a possible cancellation point and therefore not
  561. marked with __THROW. */
  562. extern void rewind (FILE *__stream);
  563. /* The Single Unix Specification, Version 2, specifies an alternative,
  564. more adequate interface for the two functions above which deal with
  565. file offset. `long int' is not the right type. These definitions
  566. are originally defined in the Large File Support API. */
  567. #if defined __USE_LARGEFILE || defined __USE_XOPEN2K
  568. # ifndef __USE_FILE_OFFSET64
  569. /* Seek to a certain position on STREAM.
  570. This function is a possible cancellation point and therefore not
  571. marked with __THROW. */
  572. extern int fseeko (FILE *__stream, __off_t __off, int __whence);
  573. /* Return the current position of STREAM.
  574. This function is a possible cancellation point and therefore not
  575. marked with __THROW. */
  576. extern __off_t ftello (FILE *__stream) __wur;
  577. # else
  578. # ifdef __REDIRECT
  579. extern int __REDIRECT (fseeko,
  580. (FILE *__stream, __off64_t __off, int __whence),
  581. fseeko64);
  582. extern __off64_t __REDIRECT (ftello, (FILE *__stream), ftello64);
  583. # else
  584. # define fseeko fseeko64
  585. # define ftello ftello64
  586. # endif
  587. # endif
  588. #endif
  589. #ifndef __USE_FILE_OFFSET64
  590. /* Get STREAM's position.
  591. This function is a possible cancellation point and therefore not
  592. marked with __THROW. */
  593. extern int fgetpos (FILE *__restrict __stream, fpos_t *__restrict __pos);
  594. /* Set STREAM's position.
  595. This function is a possible cancellation point and therefore not
  596. marked with __THROW. */
  597. extern int fsetpos (FILE *__stream, const fpos_t *__pos);
  598. #else
  599. # ifdef __REDIRECT
  600. extern int __REDIRECT (fgetpos, (FILE *__restrict __stream,
  601. fpos_t *__restrict __pos), fgetpos64);
  602. extern int __REDIRECT (fsetpos,
  603. (FILE *__stream, const fpos_t *__pos), fsetpos64);
  604. # else
  605. # define fgetpos fgetpos64
  606. # define fsetpos fsetpos64
  607. # endif
  608. #endif
  609. #ifdef __USE_LARGEFILE64
  610. extern int fseeko64 (FILE *__stream, __off64_t __off, int __whence);
  611. extern __off64_t ftello64 (FILE *__stream) __wur;
  612. extern int fgetpos64 (FILE *__restrict __stream, fpos64_t *__restrict __pos);
  613. extern int fsetpos64 (FILE *__stream, const fpos64_t *__pos);
  614. #endif
  615. /* Clear the error and EOF indicators for STREAM. */
  616. extern void clearerr (FILE *__stream) __THROW;
  617. /* Return the EOF indicator for STREAM. */
  618. extern int feof (FILE *__stream) __THROW __wur;
  619. /* Return the error indicator for STREAM. */
  620. extern int ferror (FILE *__stream) __THROW __wur;
  621. #ifdef __USE_MISC
  622. /* Faster versions when locking is not required. */
  623. extern void clearerr_unlocked (FILE *__stream) __THROW;
  624. extern int feof_unlocked (FILE *__stream) __THROW __wur;
  625. extern int ferror_unlocked (FILE *__stream) __THROW __wur;
  626. #endif
  627. /* Print a message describing the meaning of the value of errno.
  628. This function is a possible cancellation point and therefore not
  629. marked with __THROW. */
  630. extern void perror (const char *__s);
  631. #ifdef __USE_POSIX
  632. /* Return the system file descriptor for STREAM. */
  633. extern int fileno (FILE *__stream) __THROW __wur;
  634. #endif /* Use POSIX. */
  635. #ifdef __USE_MISC
  636. /* Faster version when locking is not required. */
  637. extern int fileno_unlocked (FILE *__stream) __THROW __wur;
  638. #endif
  639. #ifdef __USE_POSIX2
  640. /* Create a new stream connected to a pipe running the given command.
  641. This function is a possible cancellation point and therefore not
  642. marked with __THROW. */
  643. extern FILE *popen (const char *__command, const char *__modes) __wur;
  644. /* Close a stream opened by popen and return the status of its child.
  645. This function is a possible cancellation point and therefore not
  646. marked with __THROW. */
  647. extern int pclose (FILE *__stream);
  648. #endif
  649. #ifdef __USE_POSIX
  650. /* Return the name of the controlling terminal. */
  651. extern char *ctermid (char *__s) __THROW;
  652. #endif /* Use POSIX. */
  653. #if (defined __USE_XOPEN && !defined __USE_XOPEN2K) || defined __USE_GNU
  654. /* Return the name of the current user. */
  655. extern char *cuserid (char *__s);
  656. #endif /* Use X/Open, but not issue 6. */
  657. #ifdef __USE_GNU
  658. struct obstack; /* See <obstack.h>. */
  659. /* Write formatted output to an obstack. */
  660. extern int obstack_printf (struct obstack *__restrict __obstack,
  661. const char *__restrict __format, ...)
  662. __THROWNL __attribute__ ((__format__ (__printf__, 2, 3)));
  663. extern int obstack_vprintf (struct obstack *__restrict __obstack,
  664. const char *__restrict __format,
  665. __gnuc_va_list __args)
  666. __THROWNL __attribute__ ((__format__ (__printf__, 2, 0)));
  667. #endif /* Use GNU. */
  668. #ifdef __USE_POSIX199506
  669. /* These are defined in POSIX.1:1996. */
  670. /* Acquire ownership of STREAM. */
  671. extern void flockfile (FILE *__stream) __THROW;
  672. /* Try to acquire ownership of STREAM but do not block if it is not
  673. possible. */
  674. extern int ftrylockfile (FILE *__stream) __THROW __wur;
  675. /* Relinquish the ownership granted for STREAM. */
  676. extern void funlockfile (FILE *__stream) __THROW;
  677. #endif /* POSIX */
  678. #if defined __USE_XOPEN && !defined __USE_XOPEN2K && !defined __USE_GNU
  679. /* X/Open Issues 1-5 required getopt to be declared in this
  680. header. It was removed in Issue 6. GNU follows Issue 6. */
  681. # include <bits/getopt_posix.h>
  682. #endif
  683. /* Slow-path routines used by the optimized inline functions in
  684. bits/stdio.h. */
  685. extern int __uflow (FILE *);
  686. extern int __overflow (FILE *, int);
  687. /* If we are compiling with optimizing read this file. It contains
  688. several optimizing inline functions and macros. */
  689. #ifdef __USE_EXTERN_INLINES
  690. # include <bits/stdio.h>
  691. #endif
  692. #if __USE_FORTIFY_LEVEL > 0 && defined __fortify_function
  693. # include <bits/stdio2.h>
  694. #endif
  695. #include <bits/floatn.h>
  696. #if defined __LDBL_COMPAT || __LDOUBLE_REDIRECTS_TO_FLOAT128_ABI == 1
  697. # include <bits/stdio-ldbl.h>
  698. #endif
  699. __END_DECLS
  700. #endif /* <stdio.h> included. */