_stdio.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470
  1. /* Copyright (C) 2004-2005 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball.
  4. *
  5. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  6. */
  7. #define _GNU_SOURCE
  8. #include <features.h>
  9. #include <assert.h>
  10. #include <errno.h>
  11. #include <fcntl.h>
  12. #include <limits.h>
  13. #include <signal.h>
  14. #include <stdint.h>
  15. #include <stdio.h>
  16. #include <stdlib.h>
  17. #include <string.h>
  18. #include <unistd.h>
  19. extern int __vfprintf (FILE *__restrict __s, __const char *__restrict __format,
  20. __gnuc_va_list __arg) attribute_hidden;
  21. extern int __vsnprintf (char *__restrict __s, size_t __maxlen,
  22. __const char *__restrict __format, __gnuc_va_list __arg)
  23. __THROW __attribute__ ((__format__ (__printf__, 3, 0))) attribute_hidden;
  24. extern int __vfscanf (FILE *__restrict __s, __const char *__restrict __format,
  25. __gnuc_va_list __arg)
  26. __attribute__ ((__format__ (__scanf__, 2, 0))) attribute_hidden;
  27. extern int __vsscanf (__const char *__restrict __s,
  28. __const char *__restrict __format, __gnuc_va_list __arg)
  29. __THROW __attribute__ ((__format__ (__scanf__, 2, 0))) attribute_hidden;
  30. #ifdef __UCLIBC_HAS_WCHAR__
  31. #include <wchar.h>
  32. extern int __vfwprintf (__FILE *__restrict __s,
  33. __const wchar_t *__restrict __format,
  34. __gnuc_va_list __arg) attribute_hidden;
  35. extern int __vfwscanf (__FILE *__restrict __s,
  36. __const wchar_t *__restrict __format,
  37. __gnuc_va_list __arg) attribute_hidden;
  38. extern int __vswscanf (__const wchar_t *__restrict __s,
  39. __const wchar_t *__restrict __format,
  40. __gnuc_va_list __arg) __THROW attribute_hidden;
  41. #endif
  42. #ifdef __UCLIBC_HAS_THREADS__
  43. #include <pthread.h>
  44. #define __STDIO_THREADLOCK_OPENLIST \
  45. __pthread_mutex_lock(&_stdio_openlist_lock)
  46. #define __STDIO_THREADUNLOCK_OPENLIST \
  47. __pthread_mutex_unlock(&_stdio_openlist_lock)
  48. #define __STDIO_THREADTRYLOCK_OPENLIST \
  49. __pthread_mutex_trylock(&_stdio_openlist_lock)
  50. #else
  51. #define __STDIO_THREADLOCK_OPENLIST ((void)0)
  52. #define __STDIO_THREADUNLOCK_OPENLIST ((void)0)
  53. #endif
  54. #define __UNDEFINED_OR_NONPORTABLE ((void)0)
  55. /**********************************************************************/
  56. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  57. extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize) attribute_hidden;
  58. extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize) attribute_hidden;
  59. extern int _cs_seek(void *cookie, __offmax_t *pos, int whence) attribute_hidden;
  60. extern int _cs_close(void *cookie) attribute_hidden;
  61. #define __STDIO_STREAM_RESET_GCS(S) \
  62. (S)->__cookie = &((S)->__filedes); \
  63. (S)->__gcs.read = _cs_read; \
  64. (S)->__gcs.write = _cs_write; \
  65. (S)->__gcs.seek = _cs_seek; \
  66. (S)->__gcs.close = _cs_close
  67. #define __READ(STREAMPTR,BUF,SIZE) \
  68. ((((STREAMPTR)->__gcs.read) == NULL) ? -1 : \
  69. (((STREAMPTR)->__gcs.read)((STREAMPTR)->__cookie,(BUF),(SIZE))))
  70. #define __WRITE(STREAMPTR,BUF,SIZE) \
  71. ((((STREAMPTR)->__gcs.write) == NULL) ? -1 : \
  72. (((STREAMPTR)->__gcs.write)((STREAMPTR)->__cookie,(BUF),(SIZE))))
  73. #define __SEEK(STREAMPTR,PPOS,WHENCE) \
  74. ((((STREAMPTR)->__gcs.seek) == NULL) ? -1 : \
  75. (((STREAMPTR)->__gcs.seek)((STREAMPTR)->__cookie,(PPOS),(WHENCE))))
  76. #define __CLOSE(STREAMPTR) \
  77. ((((STREAMPTR)->__gcs.close) == NULL) ? 0 : \
  78. (((STREAMPTR)->__gcs.close)((STREAMPTR)->__cookie)))
  79. #else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
  80. extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attribute_hidden;
  81. #define __STDIO_STREAM_RESET_GCS(S) ((void)0)
  82. #define __READ(STREAMPTR,BUF,SIZE) \
  83. (read((STREAMPTR)->__filedes,(BUF),(SIZE)))
  84. #define __WRITE(STREAMPTR,BUF,SIZE) \
  85. (write((STREAMPTR)->__filedes,(BUF),(SIZE)))
  86. #define __SEEK(STREAMPTR,PPOS,WHENCE) \
  87. (__stdio_seek((STREAMPTR),(PPOS),(WHENCE)))
  88. #define __CLOSE(STREAMPTR) \
  89. (close((STREAMPTR)->__filedes))
  90. #endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
  91. /**********************************************************************/
  92. #ifdef __UCLIBC_HAS_WCHAR__
  93. #define __STDIO_STREAM_TRANS_TO_WRITE(S,O) __stdio_trans2w_o((S), (O))
  94. #define __STDIO_STREAM_TRANS_TO_READ(S,O) __stdio_trans2r_o((S), (O))
  95. #else
  96. #define __STDIO_STREAM_TRANS_TO_WRITE(S,O) __stdio_trans2w((S))
  97. #define __STDIO_STREAM_TRANS_TO_READ(S,O) __stdio_trans2r((S))
  98. #endif
  99. /**********************************************************************/
  100. #define __STDIO_STREAM_IS_READING(S) ((S)->__modeflags & __MASK_READING)
  101. #define __STDIO_STREAM_IS_WRITING(S) ((S)->__modeflags & __FLAG_WRITING)
  102. #define __STDIO_STREAM_SET_READING(S) ((S)->__modeflags |= __FLAG_READING)
  103. #define __STDIO_STREAM_SET_WRITING(S) ((S)->__modeflags |= __FLAG_WRITING)
  104. #define __STDIO_STREAM_IS_READING_OR_READONLY(S) \
  105. ((S)->__modeflags & (__MASK_READING|__FLAG_READONLY))
  106. #define __STDIO_STREAM_IS_WRITING_OR_WRITEONLY(S) \
  107. ((S)->__modeflags & (__FLAG_WRITING|__FLAG_WRITEONLY))
  108. #define __STDIO_STREAM_IS_READONLY(S) ((S)->__modeflags & __FLAG_READONLY)
  109. #define __STDIO_STREAM_IS_WRITEONLY(S) ((S)->__modeflags & __FLAG_WRITEONLY)
  110. /**********************************************************************/
  111. #ifdef __UCLIBC_HAS_WCHAR__
  112. #define __STDIO_STREAM_IS_NARROW_WRITING(S) \
  113. (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \
  114. == (__FLAG_WRITING|__FLAG_NARROW))
  115. #define __STDIO_STREAM_IS_WIDE_WRITING(S) \
  116. (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \
  117. == (__FLAG_WRITING|__FLAG_WIDE))
  118. #if (__FLAG_NARROW <= __MASK_READING)
  119. #error assumption violated regarding __FLAG_NARROW
  120. #endif
  121. #define __STDIO_STREAM_IS_NARROW_READING(S) \
  122. (((S)->__modeflags & (__MASK_READING|__FLAG_NARROW)) > __FLAG_NARROW)
  123. #define __STDIO_STREAM_IS_WIDE_READING(S) \
  124. (((S)->__modeflags & (__MASK_READING|__FLAG_WIDE)) > __FLAG_WIDE)
  125. #define __STDIO_STREAM_IS_NARROW(S) ((S)->__modeflags & __FLAG_NARROW)
  126. #define __STDIO_STREAM_IS_WIDE(S) ((S)->__modeflags & __FLAG_WIDE)
  127. #define __STDIO_STREAM_SET_NARROW(S) \
  128. ((void)((S)->__modeflags |= __FLAG_NARROW))
  129. #define __STDIO_STREAM_SET_WIDE(S) \
  130. ((void)((S)->__modeflags |= __FLAG_WIDE))
  131. #else
  132. #define __STDIO_STREAM_IS_NARROW_WRITING(S) __STDIO_STREAM_IS_WRITING(S)
  133. #define __STDIO_STREAM_IS_NARROW_READING(S) __STDIO_STREAM_IS_READING(S)
  134. #define __STDIO_STREAM_IS_NARROW(S) (1)
  135. #define __STDIO_STREAM_IS_WIDE(S) (0)
  136. #define __STDIO_STREAM_SET_NARROW(S) ((void)0)
  137. #define __STDIO_STREAM_SET_WIDE(S) ((void)0)
  138. #endif
  139. /**********************************************************************/
  140. #define __STDIO_STREAM_SET_EOF(S) \
  141. ((void)((S)->__modeflags |= __FLAG_EOF))
  142. #define __STDIO_STREAM_SET_ERROR(S) \
  143. ((void)((S)->__modeflags |= __FLAG_ERROR))
  144. #define __STDIO_STREAM_CLEAR_EOF(S) \
  145. ((void)((S)->__modeflags &= ~__FLAG_EOF))
  146. #define __STDIO_STREAM_CLEAR_ERROR(S) \
  147. ((void)((S)->__modeflags &= ~__FLAG_ERROR))
  148. #define __STDIO_STREAM_CLEAR_READING_AND_UNGOTS(S) \
  149. ((void)((S)->__modeflags &= ~__MASK_READING))
  150. #define __STDIO_STREAM_CLEAR_WRITING(S) \
  151. ((void)((S)->__modeflags &= ~__FLAG_WRITING))
  152. #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
  153. # define __STDIO_STREAM_DISABLE_GETC(S) \
  154. ((void)((S)->__bufgetc_u = (S)->__bufstart))
  155. # define __STDIO_STREAM_ENABLE_GETC(S) \
  156. ((void)((S)->__bufgetc_u = (S)->__bufread))
  157. # define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) \
  158. ((S)->__bufpos < (S)->__bufgetc_u)
  159. #else
  160. # define __STDIO_STREAM_DISABLE_GETC(S) ((void)0)
  161. # define __STDIO_STREAM_ENABLE_GETC(S) ((void)0)
  162. # define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0)
  163. #endif
  164. #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
  165. # define __STDIO_STREAM_DISABLE_PUTC(S) \
  166. ((void)((S)->__bufputc_u = (S)->__bufstart))
  167. # define __STDIO_STREAM_ENABLE_PUTC(S) \
  168. ((void)((S)->__bufputc_u = (S)->__bufend))
  169. # define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) \
  170. ((S)->__bufpos < (S)->__bufputc_u)
  171. #else
  172. # define __STDIO_STREAM_DISABLE_PUTC(S) ((void)0)
  173. # define __STDIO_STREAM_ENABLE_PUTC(S) ((void)0)
  174. # define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
  175. #endif
  176. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  177. #define __STDIO_STREAM_IS_CUSTOM(S) ((S)->__cookie != &((S)->__filedes))
  178. #else
  179. #define __STDIO_STREAM_IS_CUSTOM(S) (0)
  180. #endif
  181. /**********************************************************************/
  182. #ifdef __STDIO_BUFFERS
  183. #define __STDIO_STREAM_FREE_BUFFER(S) \
  184. do { if ((S)->__modeflags & __FLAG_FREEBUF) free((S)->__bufstart); } while (0)
  185. #else
  186. #define __STDIO_STREAM_FREE_BUFFER(S) ((void)0)
  187. #endif
  188. #define __STDIO_STREAM_FREE_FILE(S) \
  189. do { if ((S)->__modeflags & __FLAG_FREEFILE) free((S)); } while (0)
  190. #ifdef __UCLIBC_HAS_LFS__
  191. #define __STDIO_WHEN_LFS(E) E
  192. #else
  193. #define __STDIO_WHEN_LFS(E) ((void)0)
  194. #endif
  195. /**********************************************************************/
  196. /* The following return 0 on success. */
  197. #ifdef __STDIO_BUFFERS
  198. /* Assume stream in valid writing state. Do not reset writing flag
  199. * or disble putc macro unless error. */
  200. /* Should we assume that buffer is not empty to avoid a check? */
  201. extern size_t __stdio_wcommit(FILE *__restrict stream) attribute_hidden;
  202. /* Remember to fail if at EOF! */
  203. extern size_t __stdio_rfill(FILE *__restrict stream) attribute_hidden;
  204. extern size_t __stdio_fwrite(const unsigned char *__restrict buffer,
  205. size_t bytes, FILE *__restrict stream) attribute_hidden;
  206. #else
  207. #define __stdio_fwrite(B,N,S) __stdio_WRITE((S),(B),(N))
  208. #endif
  209. extern size_t __stdio_WRITE(FILE *stream, const unsigned char *buf,
  210. size_t bufsize) attribute_hidden;
  211. extern size_t __stdio_READ(FILE *stream, unsigned char *buf, size_t bufsize) attribute_hidden;
  212. extern int __stdio_trans2r(FILE *__restrict stream) attribute_hidden;
  213. extern int __stdio_trans2w(FILE *__restrict stream) attribute_hidden;
  214. extern int __stdio_trans2r_o(FILE *__restrict stream, int oflag) attribute_hidden;
  215. extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidden;
  216. extern int __setvbuf (FILE *__restrict __stream, char *__restrict __buf,
  217. int __modes, size_t __n) __THROW attribute_hidden;
  218. /**********************************************************************/
  219. #ifdef __STDIO_BUFFERS
  220. #define __STDIO_STREAM_IS_FBF(S) (!((S)->__modeflags & __MASK_BUFMODE))
  221. #define __STDIO_STREAM_IS_LBF(S) ((S)->__modeflags & __FLAG_LBF)
  222. #define __STDIO_STREAM_IS_NBF(S) ((S)->__modeflags & __FLAG_NBF)
  223. #define __STDIO_STREAM_BUFFER_SIZE(S) ((S)->__bufend - (S)->__bufstart)
  224. /* Valid when writing... */
  225. #define __STDIO_STREAM_BUFFER_ADD(S,C) (*(S)->__bufpos++ = (C))
  226. #define __STDIO_STREAM_BUFFER_UNADD(S) (--(S)->__bufpos)
  227. #define __STDIO_STREAM_BUFFER_WAVAIL(S) ((S)->__bufend - (S)->__bufpos)
  228. #define __STDIO_STREAM_BUFFER_WUSED(S) ((S)->__bufpos - (S)->__bufstart)
  229. #define __STDIO_COMMIT_WRITE_BUFFER(S) __stdio_wcommit((S))
  230. #ifdef __UCLIBC_HAS_WCHAR__
  231. #define __STDIO_STREAM_IS_NARROW_FBF(S) \
  232. (!((S)->__modeflags & (__MASK_BUFMODE|__FLAG_WIDE)))
  233. #else
  234. #define __STDIO_STREAM_IS_NARROW_FBF(S) __STDIO_STREAM_IS_FBF((S))
  235. #endif
  236. /* Valid when reading... */
  237. #define __STDIO_STREAM_BUFFER_RAVAIL(S) ((S)->__bufread - (S)->__bufpos)
  238. #define __STDIO_STREAM_BUFFER_GET(S) (*(S)->__bufpos++)
  239. #define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S))
  240. #define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \
  241. (S)->__bufread = (S)->__bufpos = (S)->__bufstart
  242. #define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-2)
  243. #define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2)
  244. #define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-3)
  245. #define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-3)
  246. #define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) \
  247. ((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES)
  248. #define __STDIO_STREAM_IS_FAKE_VSSCANF(S) \
  249. ((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES)
  250. #define __STDIO_STREAM_IS_FAKE_VSWPRINTF(S) \
  251. ((S)->__filedes == __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES)
  252. #define __STDIO_STREAM_IS_FAKE_VSWSCANF(S) \
  253. ((S)->__filedes == __STDIO_STREAM_FAKE_VSWSCANF_FILEDES)
  254. #else /* __STDIO_BUFFERS */
  255. #define __STDIO_STREAM_IS_FBF(S) (0)
  256. #define __STDIO_STREAM_IS_LBF(S) (0)
  257. #define __STDIO_STREAM_IS_NBF(S) (1)
  258. #define __STDIO_STREAM_BUFFER_SIZE(S) (0)
  259. #define __STDIO_STREAM_BUFFER_ADD(S,C) ((void)0)
  260. #define __STDIO_STREAM_BUFFER_UNADD(S) ((void)0)
  261. #define __STDIO_STREAM_BUFFER_WAVAIL(S) (0)
  262. #define __STDIO_STREAM_BUFFER_WUSED(S) (0)
  263. #define __STDIO_COMMIT_WRITE_BUFFER(S) (0)
  264. #define __STDIO_STREAM_IS_NARROW_FBF(S) (0)
  265. #define __STDIO_STREAM_BUFFER_RAVAIL(S) (0)
  266. #define __STDIO_STREAM_BUFFER_GET(S) (EOF)
  267. #define __STDIO_FILL_READ_BUFFER(S) (0)
  268. #define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0)
  269. #undef __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES
  270. #undef __STDIO_STREAM_FAKE_VSSCANF_FILEDES
  271. #undef __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES
  272. #define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) (0)
  273. #define __STDIO_STREAM_IS_FAKE_VSSCANF(S) (0)
  274. #undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
  275. # ifdef __USE_OLD_VFPRINTF__
  276. # define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
  277. # define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \
  278. ((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB)
  279. # endif
  280. # ifndef __UCLIBC_HAS_WCHAR__
  281. # define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2)
  282. # define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \
  283. ((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB)
  284. # endif
  285. #endif /* __STDIO_BUFFERS */
  286. /**********************************************************************/
  287. extern int __fputs_unlocked(const char *__restrict s, FILE *__restrict stream) attribute_hidden;
  288. extern int __putchar_unlocked(int c);
  289. extern size_t __fwrite_unlocked(const void *__restrict ptr, size_t size,
  290. size_t nmemb, FILE *__restrict stream) attribute_hidden;
  291. extern size_t __fread_unlocked(void *__restrict ptr, size_t size,
  292. size_t nmemb, FILE *__restrict stream) attribute_hidden;
  293. extern int __fputc_unlocked_internal(int c, FILE *stream) attribute_hidden;
  294. extern int __fflush_unlocked(FILE *stream) attribute_hidden;
  295. extern int __stdio_adjust_position(FILE *__restrict stream, __offmax_t *pos) attribute_hidden;
  296. extern void __clearerr_unlocked(FILE *stream);
  297. extern int __feof_unlocked(FILE *stream);
  298. extern int __ferror_unlocked(FILE *stream);
  299. extern int __fgetc_unlocked_internal(FILE *stream) attribute_hidden;
  300. extern char *__fgets_unlocked(char *__restrict s, int n,
  301. FILE * __restrict stream) attribute_hidden;
  302. extern int __fileno_unlocked(FILE *stream) attribute_hidden;
  303. extern int __getchar_unlocked(void) attribute_hidden;
  304. extern int __fseek(FILE *stream, long int offset, int whence) attribute_hidden;
  305. extern long int __ftell(FILE *stream) attribute_hidden;
  306. #ifdef __UCLIBC_HAS_LFS__
  307. extern int __fseeko64(FILE *stream, __off64_t offset, int whence) attribute_hidden;
  308. extern __off64_t __ftello64(FILE *stream) attribute_hidden;
  309. #endif
  310. #ifdef __STDIO_HAS_OPENLIST
  311. /* Uses an implementation hack!!! */
  312. #define __STDIO_FLUSH_LBF_STREAMS __fflush_unlocked((FILE *) &_stdio_openlist)
  313. #else
  314. #define __STDIO_FLUSH_LBF_STREAMS ((void)0)
  315. #endif
  316. #ifdef NDEBUG
  317. #define __STDIO_STREAM_VALIDATE(S) ((void)0)
  318. #else
  319. extern void _stdio_validate_FILE(const FILE *stream);
  320. #define __STDIO_STREAM_VALIDATE(S) _stdio_validate_FILE((S))
  321. #endif
  322. #ifdef __STDIO_MBSTATE
  323. #define __COPY_MBSTATE(dest,src) \
  324. ((void)((dest)->__mask = (src)->__mask, (dest)->__wc = (src)->__wc))
  325. #define __INIT_MBSTATE(dest) ((void)((dest)->__mask = 0))
  326. #else
  327. #define __COPY_MBSTATE(dest,src) ((void)0)
  328. #define __INIT_MBSTATE(dest) ((void)0)
  329. #endif
  330. /**********************************************************************/
  331. extern int _stdio_adjpos(FILE *__restrict stream, __offmax_t * pos);
  332. extern int _stdio_lseek(FILE *stream, __offmax_t *pos, int whence);
  333. extern size_t _stdio_fwrite(const unsigned char *buffer, size_t bytes,
  334. FILE *stream);
  335. extern size_t _stdio_fread(unsigned char *buffer, size_t bytes,
  336. FILE *stream);
  337. extern FILE *_stdio_fopen(intptr_t fname_or_mode,
  338. const char *__restrict mode,
  339. FILE *__restrict stream, int filedes) attribute_hidden;
  340. #ifdef __UCLIBC_HAS_WCHAR__
  341. extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
  342. FILE *__restrict stream) attribute_hidden;
  343. extern wint_t __fgetwc_unlocked(register FILE *stream) attribute_hidden;
  344. extern wint_t __fputwc_unlocked(wchar_t wc, FILE *stream) attribute_hidden;
  345. #endif
  346. /**********************************************************************/
  347. /* Only use the macro below if you know fp is a valid FILE for a valid fd.
  348. * This is _not_ true for custom streams! */
  349. #define __FILENO_UNLOCKED(fp) ((fp)->__filedes)
  350. #define __FEOF_OR_FERROR_UNLOCKED(stream) \
  351. ((stream)->__modeflags & (__FLAG_EOF|__FLAG_ERROR))
  352. #if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
  353. #define __STDIO_HAS_VSNPRINTF 1
  354. #endif