You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

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