stdio.h 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807
  1. /*
  2. * Copyright (c) 1990 The Regents of the University of California.
  3. * All rights reserved.
  4. *
  5. * Redistribution and use in source and binary forms are permitted
  6. * provided that the above copyright notice and this paragraph are
  7. * duplicated in all such forms and that any documentation,
  8. * and/or other materials related to such
  9. * distribution and use acknowledge that the software was developed
  10. * by the University of California, Berkeley. The name of the
  11. * University may not be used to endorse or promote products derived
  12. * from this software without specific prior written permission.
  13. * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
  14. * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
  15. * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
  16. *
  17. * @(#)stdio.h 5.3 (Berkeley) 3/15/86
  18. */
  19. /*
  20. * NB: to fit things in six character monocase externals, the
  21. * stdio code uses the prefix `__s' for stdio objects, typically
  22. * followed by a three-character attempt at a mnemonic.
  23. */
  24. #ifndef _STDIO_H_
  25. #define _STDIO_H_
  26. #include "_ansi.h"
  27. #define _FSTDIO /* ``function stdio'' */
  28. #define __need_size_t
  29. #define __need_NULL
  30. #include <sys/cdefs.h>
  31. #include <stddef.h>
  32. /* typedef only __gnuc_va_list, used throughout the header */
  33. #define __need___va_list
  34. #include <stdarg.h>
  35. /* typedef va_list only when required */
  36. #if __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE
  37. #ifdef __GNUC__
  38. #ifndef _VA_LIST_DEFINED
  39. typedef __gnuc_va_list va_list;
  40. #define _VA_LIST_DEFINED
  41. #endif
  42. #else /* !__GNUC__ */
  43. #include <stdarg.h>
  44. #endif
  45. #endif /* __POSIX_VISIBLE >= 200809 || __XSI_VISIBLE */
  46. /*
  47. * <sys/reent.h> defines __FILE, _fpos_t.
  48. * They must be defined there because struct _reent needs them (and we don't
  49. * want reent.h to include this file.
  50. */
  51. #include <sys/reent.h>
  52. #include <sys/_types.h>
  53. _BEGIN_STD_C
  54. #if !defined(__FILE_defined)
  55. typedef __FILE FILE;
  56. # define __FILE_defined
  57. #endif
  58. typedef _fpos_t fpos_t;
  59. #ifdef __LARGE64_FILES
  60. typedef _fpos64_t fpos64_t;
  61. #endif
  62. #ifndef _OFF_T_DECLARED
  63. typedef __off_t off_t;
  64. #define _OFF_T_DECLARED
  65. #endif
  66. #ifndef _SSIZE_T_DECLARED
  67. typedef _ssize_t ssize_t;
  68. #define _SSIZE_T_DECLARED
  69. #endif
  70. #include <sys/stdio.h>
  71. #define __SLBF 0x0001 /* line buffered */
  72. #define __SNBF 0x0002 /* unbuffered */
  73. #define __SRD 0x0004 /* OK to read */
  74. #define __SWR 0x0008 /* OK to write */
  75. /* RD and WR are never simultaneously asserted */
  76. #define __SRW 0x0010 /* open for reading & writing */
  77. #define __SEOF 0x0020 /* found EOF */
  78. #define __SERR 0x0040 /* found error */
  79. #define __SMBF 0x0080 /* _buf is from malloc */
  80. #define __SAPP 0x0100 /* fdopen()ed in append mode - so must write to end */
  81. #define __SSTR 0x0200 /* this is an sprintf/snprintf string */
  82. #define __SOPT 0x0400 /* do fseek() optimisation */
  83. #define __SNPT 0x0800 /* do not do fseek() optimisation */
  84. #define __SOFF 0x1000 /* set iff _offset is in fact correct */
  85. #define __SORD 0x2000 /* true => stream orientation (byte/wide) decided */
  86. #if defined(__CYGWIN__)
  87. # define __SCLE 0x4000 /* convert line endings CR/LF <-> NL */
  88. #endif
  89. #define __SL64 0x8000 /* is 64-bit offset large file */
  90. /* _flags2 flags */
  91. #define __SNLK 0x0001 /* stdio functions do not lock streams themselves */
  92. #define __SWID 0x2000 /* true => stream orientation wide, false => byte, only valid if __SORD in _flags is true */
  93. /*
  94. * The following three definitions are for ANSI C, which took them
  95. * from System V, which stupidly took internal interface macros and
  96. * made them official arguments to setvbuf(), without renaming them.
  97. * Hence, these ugly _IOxxx names are *supposed* to appear in user code.
  98. *
  99. * Although these happen to match their counterparts above, the
  100. * implementation does not rely on that (so these could be renumbered).
  101. */
  102. #define _IOFBF 0 /* setvbuf should set fully buffered */
  103. #define _IOLBF 1 /* setvbuf should set line buffered */
  104. #define _IONBF 2 /* setvbuf should set unbuffered */
  105. #define EOF (-1)
  106. #ifdef __BUFSIZ__
  107. #define BUFSIZ __BUFSIZ__
  108. #else
  109. #define BUFSIZ 1024
  110. #endif
  111. #ifdef __FOPEN_MAX__
  112. #define FOPEN_MAX __FOPEN_MAX__
  113. #else
  114. #define FOPEN_MAX 20
  115. #endif
  116. #ifdef __FILENAME_MAX__
  117. #define FILENAME_MAX __FILENAME_MAX__
  118. #else
  119. #define FILENAME_MAX 1024
  120. #endif
  121. #ifdef __L_tmpnam__
  122. #define L_tmpnam __L_tmpnam__
  123. #else
  124. #define L_tmpnam FILENAME_MAX
  125. #endif
  126. #if __BSD_VISIBLE || __XSI_VISIBLE
  127. #define P_tmpdir "/tmp"
  128. #endif
  129. #ifndef SEEK_SET
  130. #define SEEK_SET 0 /* set file offset to offset */
  131. #endif
  132. #ifndef SEEK_CUR
  133. #define SEEK_CUR 1 /* set file offset to current plus offset */
  134. #endif
  135. #ifndef SEEK_END
  136. #define SEEK_END 2 /* set file offset to EOF plus offset */
  137. #endif
  138. #define TMP_MAX 26
  139. #define stdin _REENT_STDIN(_REENT)
  140. #define stdout _REENT_STDOUT(_REENT)
  141. #define stderr _REENT_STDERR(_REENT)
  142. #define _stdin_r(x) _REENT_STDIN(x)
  143. #define _stdout_r(x) _REENT_STDOUT(x)
  144. #define _stderr_r(x) _REENT_STDERR(x)
  145. /*
  146. * Functions defined in ANSI C standard.
  147. */
  148. #ifndef __VALIST
  149. #ifdef __GNUC__
  150. #define __VALIST __gnuc_va_list
  151. #else
  152. #define __VALIST char*
  153. #endif
  154. #endif
  155. #if __POSIX_VISIBLE
  156. char * ctermid (char *);
  157. #endif
  158. #if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)
  159. char * cuserid (char *);
  160. #endif
  161. FILE * tmpfile (void);
  162. char * tmpnam (char *);
  163. #if __BSD_VISIBLE || __XSI_VISIBLE || __POSIX_VISIBLE >= 200112
  164. char * tempnam (const char *, const char *) __malloc_like __result_use_check;
  165. #endif
  166. int fclose (FILE *);
  167. int fflush (FILE *);
  168. FILE * freopen (const char *__restrict, const char *__restrict, FILE *__restrict);
  169. void setbuf (FILE *__restrict, char *__restrict);
  170. int setvbuf (FILE *__restrict, char *__restrict, int, size_t);
  171. int fprintf (FILE *__restrict, const char *__restrict, ...)
  172. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  173. int fscanf (FILE *__restrict, const char *__restrict, ...)
  174. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  175. int printf (const char *__restrict, ...)
  176. _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
  177. int scanf (const char *__restrict, ...)
  178. _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
  179. int sscanf (const char *__restrict, const char *__restrict, ...)
  180. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  181. int vfprintf (FILE *__restrict, const char *__restrict, __VALIST)
  182. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  183. int vprintf (const char *, __VALIST)
  184. _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
  185. int vsprintf (char *__restrict, const char *__restrict, __VALIST)
  186. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  187. int fgetc (FILE *);
  188. char * fgets (char *__restrict, int, FILE *__restrict);
  189. int fputc (int, FILE *);
  190. int fputs (const char *__restrict, FILE *__restrict);
  191. int getc (FILE *);
  192. int getchar (void);
  193. char * gets (char *);
  194. int putc (int, FILE *);
  195. int putchar (int);
  196. int puts (const char *);
  197. int ungetc (int, FILE *);
  198. size_t fread (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  199. size_t fwrite (const void *__restrict , size_t _size, size_t _n, FILE *);
  200. #ifdef _LIBC
  201. int fgetpos (FILE *, _fpos_t *);
  202. #else
  203. int fgetpos (FILE *__restrict, fpos_t *__restrict);
  204. #endif
  205. int fseek (FILE *, long, int);
  206. #ifdef _LIBC
  207. int fsetpos (FILE *, const _fpos_t *);
  208. #else
  209. int fsetpos (FILE *, const fpos_t *);
  210. #endif
  211. long ftell ( FILE *);
  212. void rewind (FILE *);
  213. void clearerr (FILE *);
  214. int feof (FILE *);
  215. int ferror (FILE *);
  216. void perror (const char *);
  217. #ifndef _REENT_ONLY
  218. FILE * fopen (const char *__restrict _name, const char *__restrict _type);
  219. int sprintf (char *__restrict, const char *__restrict, ...)
  220. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  221. int remove (const char *);
  222. int rename (const char *, const char *);
  223. #ifdef _LIBC
  224. int _rename (const char *, const char *);
  225. #endif
  226. #endif
  227. #if __LARGEFILE_VISIBLE || __POSIX_VISIBLE >= 200112
  228. #ifdef _LIBC
  229. int fseeko (FILE *, _off_t, int);
  230. _off_t ftello (FILE *);
  231. #else
  232. int fseeko (FILE *, off_t, int);
  233. off_t ftello (FILE *);
  234. #endif
  235. #endif
  236. #if __GNU_VISIBLE
  237. int fcloseall (void);
  238. #endif
  239. #ifndef _REENT_ONLY
  240. #if __ISO_C_VISIBLE >= 1999
  241. int snprintf (char *__restrict, size_t, const char *__restrict, ...)
  242. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  243. int vsnprintf (char *__restrict, size_t, const char *__restrict, __VALIST)
  244. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  245. int vfscanf (FILE *__restrict, const char *__restrict, __VALIST)
  246. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  247. int vscanf (const char *, __VALIST)
  248. _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
  249. int vsscanf (const char *__restrict, const char *__restrict, __VALIST)
  250. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  251. #endif
  252. #if __GNU_VISIBLE
  253. int asprintf (char **__restrict, const char *__restrict, ...)
  254. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  255. int vasprintf (char **, const char *, __VALIST)
  256. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  257. #endif
  258. #if __MISC_VISIBLE /* Newlib-specific */
  259. int asiprintf (char **, const char *, ...)
  260. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  261. char * asniprintf (char *, size_t *, const char *, ...)
  262. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  263. char * asnprintf (char *__restrict, size_t *__restrict, const char *__restrict, ...)
  264. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  265. #ifndef diprintf
  266. int diprintf (int, const char *, ...)
  267. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  268. #endif
  269. int fiprintf (FILE *, const char *, ...)
  270. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  271. int fiscanf (FILE *, const char *, ...)
  272. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  273. int iprintf (const char *, ...)
  274. _ATTRIBUTE ((__format__ (__printf__, 1, 2)));
  275. int iscanf (const char *, ...)
  276. _ATTRIBUTE ((__format__ (__scanf__, 1, 2)));
  277. int siprintf (char *, const char *, ...)
  278. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  279. int siscanf (const char *, const char *, ...)
  280. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  281. int sniprintf (char *, size_t, const char *, ...)
  282. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  283. int vasiprintf (char **, const char *, __VALIST)
  284. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  285. char * vasniprintf (char *, size_t *, const char *, __VALIST)
  286. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  287. char * vasnprintf (char *, size_t *, const char *, __VALIST)
  288. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  289. int vdiprintf (int, const char *, __VALIST)
  290. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  291. int vfiprintf (FILE *, const char *, __VALIST)
  292. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  293. int vfiscanf (FILE *, const char *, __VALIST)
  294. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  295. int viprintf (const char *, __VALIST)
  296. _ATTRIBUTE ((__format__ (__printf__, 1, 0)));
  297. int viscanf (const char *, __VALIST)
  298. _ATTRIBUTE ((__format__ (__scanf__, 1, 0)));
  299. int vsiprintf (char *, const char *, __VALIST)
  300. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  301. int vsiscanf (const char *, const char *, __VALIST)
  302. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  303. int vsniprintf (char *, size_t, const char *, __VALIST)
  304. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  305. #endif /* __MISC_VISIBLE */
  306. #endif /* !_REENT_ONLY */
  307. /*
  308. * Routines in POSIX 1003.1:2001.
  309. */
  310. #if __POSIX_VISIBLE
  311. #ifndef _REENT_ONLY
  312. FILE * fdopen (int, const char *);
  313. #endif
  314. int fileno (FILE *);
  315. #endif
  316. #if __MISC_VISIBLE || __POSIX_VISIBLE >= 199209
  317. int pclose (FILE *);
  318. FILE * popen (const char *, const char *);
  319. #endif
  320. #if __BSD_VISIBLE
  321. void setbuffer (FILE *, char *, int);
  322. int setlinebuf (FILE *);
  323. #endif
  324. #if __MISC_VISIBLE || (__XSI_VISIBLE && __POSIX_VISIBLE < 200112)
  325. int getw (FILE *);
  326. int putw (int, FILE *);
  327. #endif
  328. #if __MISC_VISIBLE || __POSIX_VISIBLE
  329. int getc_unlocked (FILE *);
  330. int getchar_unlocked (void);
  331. void flockfile (FILE *);
  332. int ftrylockfile (FILE *);
  333. void funlockfile (FILE *);
  334. int putc_unlocked (int, FILE *);
  335. int putchar_unlocked (int);
  336. #endif
  337. /*
  338. * Routines in POSIX 1003.1:200x.
  339. */
  340. #if __POSIX_VISIBLE >= 200809
  341. # ifndef _REENT_ONLY
  342. # ifndef dprintf
  343. int dprintf (int, const char *__restrict, ...)
  344. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  345. # endif
  346. FILE * fmemopen (void *__restrict, size_t, const char *__restrict);
  347. /* getdelim - see __getdelim for now */
  348. /* getline - see __getline for now */
  349. FILE * open_memstream (char **, size_t *);
  350. int vdprintf (int, const char *__restrict, __VALIST)
  351. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  352. # endif
  353. #endif
  354. #if __ATFILE_VISIBLE
  355. int renameat (int, const char *, int, const char *);
  356. # ifdef __CYGWIN__
  357. int renameat2 (int, const char *, int, const char *, unsigned int);
  358. # endif
  359. #endif
  360. /*
  361. * Recursive versions of the above.
  362. */
  363. int _asiprintf_r (struct _reent *, char **, const char *, ...)
  364. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  365. char * _asniprintf_r (struct _reent *, char *, size_t *, const char *, ...)
  366. _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
  367. char * _asnprintf_r (struct _reent *, char *__restrict, size_t *__restrict, const char *__restrict, ...)
  368. _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
  369. int _asprintf_r (struct _reent *, char **__restrict, const char *__restrict, ...)
  370. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  371. int _diprintf_r (struct _reent *, int, const char *, ...)
  372. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  373. int _dprintf_r (struct _reent *, int, const char *__restrict, ...)
  374. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  375. int _fclose_r (struct _reent *, FILE *);
  376. int _fcloseall_r (struct _reent *);
  377. FILE * _fdopen_r (struct _reent *, int, const char *);
  378. int _fflush_r (struct _reent *, FILE *);
  379. int _fgetc_r (struct _reent *, FILE *);
  380. int _fgetc_unlocked_r (struct _reent *, FILE *);
  381. char * _fgets_r (struct _reent *, char *__restrict, int, FILE *__restrict);
  382. char * _fgets_unlocked_r (struct _reent *, char *__restrict, int, FILE *__restrict);
  383. #ifdef _LIBC
  384. int _fgetpos_r (struct _reent *, FILE *__restrict, _fpos_t *__restrict);
  385. int _fsetpos_r (struct _reent *, FILE *, const _fpos_t *);
  386. #else
  387. int _fgetpos_r (struct _reent *, FILE *, fpos_t *);
  388. int _fsetpos_r (struct _reent *, FILE *, const fpos_t *);
  389. #endif
  390. int _fiprintf_r (struct _reent *, FILE *, const char *, ...)
  391. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  392. int _fiscanf_r (struct _reent *, FILE *, const char *, ...)
  393. _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
  394. FILE * _fmemopen_r (struct _reent *, void *__restrict, size_t, const char *__restrict);
  395. FILE * _fopen_r (struct _reent *, const char *__restrict, const char *__restrict);
  396. FILE * _freopen_r (struct _reent *, const char *__restrict, const char *__restrict, FILE *__restrict);
  397. int _fprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
  398. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  399. int _fpurge_r (struct _reent *, FILE *);
  400. int _fputc_r (struct _reent *, int, FILE *);
  401. int _fputc_unlocked_r (struct _reent *, int, FILE *);
  402. int _fputs_r (struct _reent *, const char *__restrict, FILE *__restrict);
  403. int _fputs_unlocked_r (struct _reent *, const char *__restrict, FILE *__restrict);
  404. size_t _fread_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  405. size_t _fread_unlocked_r (struct _reent *, void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  406. int _fscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, ...)
  407. _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
  408. int _fseek_r (struct _reent *, FILE *, long, int);
  409. int _fseeko_r (struct _reent *, FILE *, _off_t, int);
  410. long _ftell_r (struct _reent *, FILE *);
  411. _off_t _ftello_r (struct _reent *, FILE *);
  412. void _rewind_r (struct _reent *, FILE *);
  413. size_t _fwrite_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  414. size_t _fwrite_unlocked_r (struct _reent *, const void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  415. int _getc_r (struct _reent *, FILE *);
  416. int _getc_unlocked_r (struct _reent *, FILE *);
  417. int _getchar_r (struct _reent *);
  418. int _getchar_unlocked_r (struct _reent *);
  419. char * _gets_r (struct _reent *, char *);
  420. int _iprintf_r (struct _reent *, const char *, ...)
  421. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  422. int _iscanf_r (struct _reent *, const char *, ...)
  423. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  424. FILE * _open_memstream_r (struct _reent *, char **, size_t *);
  425. void _perror_r (struct _reent *, const char *);
  426. int _printf_r (struct _reent *, const char *__restrict, ...)
  427. _ATTRIBUTE ((__format__ (__printf__, 2, 3)));
  428. int _putc_r (struct _reent *, int, FILE *);
  429. int _putc_unlocked_r (struct _reent *, int, FILE *);
  430. int _putchar_unlocked_r (struct _reent *, int);
  431. int _putchar_r (struct _reent *, int);
  432. int _puts_r (struct _reent *, const char *);
  433. int _remove_r (struct _reent *, const char *);
  434. int _rename_r (struct _reent *,
  435. const char *_old, const char *_new);
  436. int _scanf_r (struct _reent *, const char *__restrict, ...)
  437. _ATTRIBUTE ((__format__ (__scanf__, 2, 3)));
  438. int _siprintf_r (struct _reent *, char *, const char *, ...)
  439. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  440. int _siscanf_r (struct _reent *, const char *, const char *, ...)
  441. _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
  442. int _sniprintf_r (struct _reent *, char *, size_t, const char *, ...)
  443. _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
  444. int _snprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, ...)
  445. _ATTRIBUTE ((__format__ (__printf__, 4, 5)));
  446. int _sprintf_r (struct _reent *, char *__restrict, const char *__restrict, ...)
  447. _ATTRIBUTE ((__format__ (__printf__, 3, 4)));
  448. int _sscanf_r (struct _reent *, const char *__restrict, const char *__restrict, ...)
  449. _ATTRIBUTE ((__format__ (__scanf__, 3, 4)));
  450. char * _tempnam_r (struct _reent *, const char *, const char *);
  451. FILE * _tmpfile_r (struct _reent *);
  452. char * _tmpnam_r (struct _reent *, char *);
  453. int _ungetc_r (struct _reent *, int, FILE *);
  454. int _vasiprintf_r (struct _reent *, char **, const char *, __VALIST)
  455. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  456. char * _vasniprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
  457. _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
  458. char * _vasnprintf_r (struct _reent*, char *, size_t *, const char *, __VALIST)
  459. _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
  460. int _vasprintf_r (struct _reent *, char **, const char *, __VALIST)
  461. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  462. int _vdiprintf_r (struct _reent *, int, const char *, __VALIST)
  463. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  464. int _vdprintf_r (struct _reent *, int, const char *__restrict, __VALIST)
  465. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  466. int _vfiprintf_r (struct _reent *, FILE *, const char *, __VALIST)
  467. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  468. int _vfiscanf_r (struct _reent *, FILE *, const char *, __VALIST)
  469. _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
  470. int _vfprintf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
  471. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  472. int _vfscanf_r (struct _reent *, FILE *__restrict, const char *__restrict, __VALIST)
  473. _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
  474. int _viprintf_r (struct _reent *, const char *, __VALIST)
  475. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  476. int _viscanf_r (struct _reent *, const char *, __VALIST)
  477. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  478. int _vprintf_r (struct _reent *, const char *__restrict, __VALIST)
  479. _ATTRIBUTE ((__format__ (__printf__, 2, 0)));
  480. int _vscanf_r (struct _reent *, const char *__restrict, __VALIST)
  481. _ATTRIBUTE ((__format__ (__scanf__, 2, 0)));
  482. int _vsiprintf_r (struct _reent *, char *, const char *, __VALIST)
  483. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  484. int _vsiscanf_r (struct _reent *, const char *, const char *, __VALIST)
  485. _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
  486. int _vsniprintf_r (struct _reent *, char *, size_t, const char *, __VALIST)
  487. _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
  488. int _vsnprintf_r (struct _reent *, char *__restrict, size_t, const char *__restrict, __VALIST)
  489. _ATTRIBUTE ((__format__ (__printf__, 4, 0)));
  490. int _vsprintf_r (struct _reent *, char *__restrict, const char *__restrict, __VALIST)
  491. _ATTRIBUTE ((__format__ (__printf__, 3, 0)));
  492. int _vsscanf_r (struct _reent *, const char *__restrict, const char *__restrict, __VALIST)
  493. _ATTRIBUTE ((__format__ (__scanf__, 3, 0)));
  494. /* Other extensions. */
  495. int fpurge (FILE *);
  496. ssize_t __getdelim (char **, size_t *, int, FILE *);
  497. ssize_t __getline (char **, size_t *, FILE *);
  498. #if __MISC_VISIBLE
  499. void clearerr_unlocked (FILE *);
  500. int feof_unlocked (FILE *);
  501. int ferror_unlocked (FILE *);
  502. int fileno_unlocked (FILE *);
  503. int fflush_unlocked (FILE *);
  504. int fgetc_unlocked (FILE *);
  505. int fputc_unlocked (int, FILE *);
  506. size_t fread_unlocked (void *__restrict, size_t _size, size_t _n, FILE *__restrict);
  507. size_t fwrite_unlocked (const void *__restrict , size_t _size, size_t _n, FILE *);
  508. #endif
  509. #if __GNU_VISIBLE
  510. char * fgets_unlocked (char *__restrict, int, FILE *__restrict);
  511. int fputs_unlocked (const char *__restrict, FILE *__restrict);
  512. #endif
  513. #ifdef __LARGE64_FILES
  514. #if !defined(__CYGWIN__) || defined(_LIBC)
  515. FILE * fdopen64 (int, const char *);
  516. FILE * fopen64 (const char *, const char *);
  517. FILE * freopen64 (const char *, const char *, FILE *);
  518. _off64_t ftello64 (FILE *);
  519. _off64_t fseeko64 (FILE *, _off64_t, int);
  520. int fgetpos64 (FILE *, _fpos64_t *);
  521. int fsetpos64 (FILE *, const _fpos64_t *);
  522. FILE * tmpfile64 (void);
  523. FILE * _fdopen64_r (struct _reent *, int, const char *);
  524. FILE * _fopen64_r (struct _reent *,const char *, const char *);
  525. FILE * _freopen64_r (struct _reent *, const char *, const char *, FILE *);
  526. _off64_t _ftello64_r (struct _reent *, FILE *);
  527. _off64_t _fseeko64_r (struct _reent *, FILE *, _off64_t, int);
  528. int _fgetpos64_r (struct _reent *, FILE *, _fpos64_t *);
  529. int _fsetpos64_r (struct _reent *, FILE *, const _fpos64_t *);
  530. FILE * _tmpfile64_r (struct _reent *);
  531. #endif /* !__CYGWIN__ */
  532. #endif /* __LARGE64_FILES */
  533. /*
  534. * Routines internal to the implementation.
  535. */
  536. int __srget_r (struct _reent *, FILE *);
  537. int __swbuf_r (struct _reent *, int, FILE *);
  538. /*
  539. * Stdio function-access interface.
  540. */
  541. #if __BSD_VISIBLE
  542. # ifdef __LARGE64_FILES
  543. FILE *funopen (const void *__cookie,
  544. int (*__readfn)(void *__c, char *__buf,
  545. _READ_WRITE_BUFSIZE_TYPE __n),
  546. int (*__writefn)(void *__c, const char *__buf,
  547. _READ_WRITE_BUFSIZE_TYPE __n),
  548. _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
  549. int (*__closefn)(void *__c));
  550. FILE *_funopen_r (struct _reent *, const void *__cookie,
  551. int (*__readfn)(void *__c, char *__buf,
  552. _READ_WRITE_BUFSIZE_TYPE __n),
  553. int (*__writefn)(void *__c, const char *__buf,
  554. _READ_WRITE_BUFSIZE_TYPE __n),
  555. _fpos64_t (*__seekfn)(void *__c, _fpos64_t __off, int __whence),
  556. int (*__closefn)(void *__c));
  557. # else
  558. FILE *funopen (const void *__cookie,
  559. int (*__readfn)(void *__cookie, char *__buf,
  560. _READ_WRITE_BUFSIZE_TYPE __n),
  561. int (*__writefn)(void *__cookie, const char *__buf,
  562. _READ_WRITE_BUFSIZE_TYPE __n),
  563. fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
  564. int (*__closefn)(void *__cookie));
  565. FILE *_funopen_r (struct _reent *, const void *__cookie,
  566. int (*__readfn)(void *__cookie, char *__buf,
  567. _READ_WRITE_BUFSIZE_TYPE __n),
  568. int (*__writefn)(void *__cookie, const char *__buf,
  569. _READ_WRITE_BUFSIZE_TYPE __n),
  570. fpos_t (*__seekfn)(void *__cookie, fpos_t __off, int __whence),
  571. int (*__closefn)(void *__cookie));
  572. # endif /* !__LARGE64_FILES */
  573. # define fropen(__cookie, __fn) funopen(__cookie, __fn, NULL, NULL, NULL)
  574. # define fwopen(__cookie, __fn) funopen(__cookie, NULL, __fn, NULL, NULL)
  575. #endif /* __BSD_VISIBLE */
  576. #if __GNU_VISIBLE
  577. typedef ssize_t cookie_read_function_t(void *__cookie, char *__buf, size_t __n);
  578. typedef ssize_t cookie_write_function_t(void *__cookie, const char *__buf,
  579. size_t __n);
  580. # ifdef __LARGE64_FILES
  581. typedef int cookie_seek_function_t(void *__cookie, _off64_t *__off,
  582. int __whence);
  583. # else
  584. typedef int cookie_seek_function_t(void *__cookie, off_t *__off, int __whence);
  585. # endif /* !__LARGE64_FILES */
  586. typedef int cookie_close_function_t(void *__cookie);
  587. typedef struct
  588. {
  589. /* These four struct member names are dictated by Linux; hopefully,
  590. they don't conflict with any macros. */
  591. cookie_read_function_t *read;
  592. cookie_write_function_t *write;
  593. cookie_seek_function_t *seek;
  594. cookie_close_function_t *close;
  595. } cookie_io_functions_t;
  596. FILE *fopencookie (void *__cookie,
  597. const char *__mode, cookie_io_functions_t __functions);
  598. FILE *_fopencookie_r (struct _reent *, void *__cookie,
  599. const char *__mode, cookie_io_functions_t __functions);
  600. #endif /* __GNU_VISIBLE */
  601. #ifndef __CUSTOM_FILE_IO__
  602. /*
  603. * The __sfoo macros are here so that we can
  604. * define function versions in the C library.
  605. */
  606. #define __sgetc_raw_r(__ptr, __f) (--(__f)->_r < 0 ? __srget_r(__ptr, __f) : (int)(*(__f)->_p++))
  607. #ifdef __SCLE
  608. /* For a platform with CR/LF, additional logic is required by
  609. __sgetc_r which would otherwise simply be a macro; therefore we
  610. use an inlined function. The function is only meant to be inlined
  611. in place as used and the function body should never be emitted.
  612. There are two possible means to this end when compiling with GCC,
  613. one when compiling with a standard C99 compiler, and for other
  614. compilers we're just stuck. At the moment, this issue only
  615. affects the Cygwin target, so we'll most likely be using GCC. */
  616. _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p);
  617. _ELIDABLE_INLINE int __sgetc_r(struct _reent *__ptr, FILE *__p)
  618. {
  619. int __c = __sgetc_raw_r(__ptr, __p);
  620. if ((__p->_flags & __SCLE) && (__c == '\r'))
  621. {
  622. int __c2 = __sgetc_raw_r(__ptr, __p);
  623. if (__c2 == '\n')
  624. __c = __c2;
  625. else
  626. ungetc(__c2, __p);
  627. }
  628. return __c;
  629. }
  630. #else
  631. #define __sgetc_r(__ptr, __p) __sgetc_raw_r(__ptr, __p)
  632. #endif
  633. #ifdef __GNUC__
  634. _ELIDABLE_INLINE int __sputc_r(struct _reent *_ptr, int _c, FILE *_p) {
  635. #ifdef __SCLE
  636. if ((_p->_flags & __SCLE) && _c == '\n')
  637. __sputc_r (_ptr, '\r', _p);
  638. #endif
  639. if (--_p->_w >= 0 || (_p->_w >= _p->_lbfsize && (char)_c != '\n'))
  640. return (*_p->_p++ = _c);
  641. else
  642. return (__swbuf_r(_ptr, _c, _p));
  643. }
  644. #else
  645. /*
  646. * This has been tuned to generate reasonable code on the vax using pcc
  647. */
  648. #define __sputc_raw_r(__ptr, __c, __p) \
  649. (--(__p)->_w < 0 ? \
  650. (__p)->_w >= (__p)->_lbfsize ? \
  651. (*(__p)->_p = (__c)), *(__p)->_p != '\n' ? \
  652. (int)*(__p)->_p++ : \
  653. __swbuf_r(__ptr, '\n', __p) : \
  654. __swbuf_r(__ptr, (int)(__c), __p) : \
  655. (*(__p)->_p = (__c), (int)*(__p)->_p++))
  656. #ifdef __SCLE
  657. #define __sputc_r(__ptr, __c, __p) \
  658. ((((__p)->_flags & __SCLE) && ((__c) == '\n')) \
  659. ? __sputc_raw_r(__ptr, '\r', (__p)) : 0 , \
  660. __sputc_raw_r((__ptr), (__c), (__p)))
  661. #else
  662. #define __sputc_r(__ptr, __c, __p) __sputc_raw_r(__ptr, __c, __p)
  663. #endif
  664. #endif
  665. #define __sfeof(p) ((int)(((p)->_flags & __SEOF) != 0))
  666. #define __sferror(p) ((int)(((p)->_flags & __SERR) != 0))
  667. #define __sclearerr(p) ((void)((p)->_flags &= ~(__SERR|__SEOF)))
  668. #define __sfileno(p) ((p)->_file)
  669. #ifndef __cplusplus
  670. #ifndef _REENT_SMALL
  671. #define feof(p) __sfeof(p)
  672. #define ferror(p) __sferror(p)
  673. #define clearerr(p) __sclearerr(p)
  674. #if __MISC_VISIBLE
  675. #define feof_unlocked(p) __sfeof(p)
  676. #define ferror_unlocked(p) __sferror(p)
  677. #define clearerr_unlocked(p) __sclearerr(p)
  678. #endif /* __MISC_VISIBLE */
  679. #endif /* _REENT_SMALL */
  680. #if 0 /* __POSIX_VISIBLE - FIXME: must initialize stdio first, use fn */
  681. #define fileno(p) __sfileno(p)
  682. #endif
  683. static __inline int
  684. _getchar_unlocked(void)
  685. {
  686. struct _reent *_ptr;
  687. _ptr = _REENT;
  688. return (__sgetc_r(_ptr, _stdin_r(_ptr)));
  689. }
  690. static __inline int
  691. _putchar_unlocked(int _c)
  692. {
  693. struct _reent *_ptr;
  694. _ptr = _REENT;
  695. return (__sputc_r(_ptr, _c, _stdout_r(_ptr)));
  696. }
  697. #ifdef __SINGLE_THREAD__
  698. #define getc(_p) __sgetc_r(_REENT, _p)
  699. #define putc(_c, _p) __sputc_r(_REENT, _c, _p)
  700. #define getchar() _getchar_unlocked()
  701. #define putchar(_c) _putchar_unlocked(_c)
  702. #endif /* __SINGLE_THREAD__ */
  703. #if __MISC_VISIBLE || __POSIX_VISIBLE
  704. #define getchar_unlocked() _getchar_unlocked()
  705. #define putchar_unlocked(_c) _putchar_unlocked(_c)
  706. #endif
  707. #endif /* __cplusplus */
  708. #if __MISC_VISIBLE
  709. /* fast always-buffered version, true iff error */
  710. #define fast_putc(x,p) (--(p)->_w < 0 ? \
  711. __swbuf_r(_REENT, (int)(x), p) == EOF : (*(p)->_p = (x), (p)->_p++, 0))
  712. #endif
  713. #if __GNU_VISIBLE || (__XSI_VISIBLE && __XSI_VISIBLE < 600)
  714. #define L_cuserid 9 /* posix says it goes in stdio.h :( */
  715. #endif
  716. #if __POSIX_VISIBLE
  717. #define L_ctermid 16
  718. #endif
  719. #else /* __CUSTOM_FILE_IO__ */
  720. #define getchar() getc(stdin)
  721. #define putchar(x) putc(x, stdout)
  722. #if __MISC_VISIBLE || __POSIX_VISIBLE
  723. #define getchar_unlocked() getc_unlocked(stdin)
  724. #define putchar_unlocked(x) putc_unlocked(x, stdout)
  725. #endif
  726. #endif /* !__CUSTOM_FILE_IO__ */
  727. _END_STD_C
  728. #if __SSP_FORTIFY_LEVEL > 0
  729. #include <ssp/stdio.h>
  730. #endif
  731. #endif /* _STDIO_H_ */