stdio.h 30 KB

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