_stdio.h 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485
  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. #ifndef __STDIO_H_I
  8. #define __STDIO_H_I 1
  9. #include <features.h>
  10. #include <assert.h>
  11. #include <errno.h>
  12. #include <fcntl.h>
  13. #include <limits.h>
  14. #include <signal.h>
  15. #include <stdint.h>
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <string.h>
  19. #include <stdarg.h>
  20. #include <unistd.h>
  21. #ifdef __UCLIBC_HAS_WCHAR__
  22. #include <wchar.h>
  23. #endif
  24. #include <bits/uClibc_mutex.h>
  25. #define __STDIO_THREADLOCK_OPENLIST_ADD \
  26. __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_add_lock)
  27. #define __STDIO_THREADUNLOCK_OPENLIST_ADD \
  28. __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_add_lock)
  29. #ifdef __STDIO_BUFFERS
  30. #define __STDIO_THREADLOCK_OPENLIST_DEL \
  31. __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_del_lock)
  32. #define __STDIO_THREADUNLOCK_OPENLIST_DEL \
  33. __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_del_lock)
  34. #ifdef __UCLIBC_HAS_THREADS__
  35. extern void __stdio_init_mutex(__UCLIBC_MUTEX_TYPE *m) attribute_hidden;
  36. extern volatile int _stdio_openlist_use_count attribute_hidden; /* _stdio_openlist_del_lock */
  37. #define __STDIO_OPENLIST_INC_USE \
  38. do { \
  39. __STDIO_THREADLOCK_OPENLIST_DEL; \
  40. ++_stdio_openlist_use_count; \
  41. __STDIO_THREADUNLOCK_OPENLIST_DEL; \
  42. } while (0)
  43. extern void _stdio_openlist_dec_use(void) attribute_hidden;
  44. #define __STDIO_OPENLIST_DEC_USE \
  45. _stdio_openlist_dec_use()
  46. extern int _stdio_openlist_del_count attribute_hidden; /* _stdio_openlist_del_lock */
  47. #define __STDIO_OPENLIST_INC_DEL_CNT \
  48. do { \
  49. __STDIO_THREADLOCK_OPENLIST_DEL; \
  50. ++_stdio_openlist_del_count; \
  51. __STDIO_THREADUNLOCK_OPENLIST_DEL; \
  52. } while (0)
  53. #define __STDIO_OPENLIST_DEC_DEL_CNT \
  54. do { \
  55. __STDIO_THREADLOCK_OPENLIST_DEL; \
  56. --_stdio_openlist_del_count; \
  57. __STDIO_THREADUNLOCK_OPENLIST_DEL; \
  58. } while (0)
  59. #endif /* __UCLIBC_HAS_THREADS__ */
  60. #endif /* __STDIO_BUFFERS */
  61. #ifndef __STDIO_THREADLOCK_OPENLIST_DEL
  62. #define __STDIO_THREADLOCK_OPENLIST_DEL ((void)0)
  63. #endif
  64. #ifndef __STDIO_THREADUNLOCK_OPENLIST_DEL
  65. #define __STDIO_THREADUNLOCK_OPENLIST_DEL ((void)0)
  66. #endif
  67. #ifndef __STDIO_OPENLIST_INC_USE
  68. #define __STDIO_OPENLIST_INC_USE ((void)0)
  69. #endif
  70. #ifndef __STDIO_OPENLIST_DEC_USE
  71. #define __STDIO_OPENLIST_DEC_USE ((void)0)
  72. #endif
  73. #ifndef __STDIO_OPENLIST_INC_DEL_CNT
  74. #define __STDIO_OPENLIST_INC_DEL_CNT ((void)0)
  75. #endif
  76. #ifndef __STDIO_OPENLIST_DEC_DEL_CNT
  77. #define __STDIO_OPENLIST_DEC_DEL_CNT ((void)0)
  78. #endif
  79. #define __UNDEFINED_OR_NONPORTABLE ((void)0)
  80. /**********************************************************************/
  81. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  82. #define __STDIO_STREAM_GLIBC_CUSTOM_FILEDES (-2)
  83. #define __STDIO_STREAM_IS_CUSTOM(S) \
  84. ((S)->__filedes == __STDIO_STREAM_GLIBC_CUSTOM_FILEDES)
  85. #define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...) \
  86. if (__STDIO_STREAM_IS_CUSTOM((S))) { \
  87. _IO_cookie_file_t *cfile = (_IO_cookie_file_t *) (S); \
  88. return (cfile->__gcs.NAME == NULL) ? (RC) : \
  89. cfile->__gcs.NAME(cfile->__cookie, ##ARGS); \
  90. }
  91. #define __STDIO_STREAM_CUSTOM_WRITE_FUNC(S, ARGS...) \
  92. if (__STDIO_STREAM_IS_CUSTOM((S))) { \
  93. ssize_t w; \
  94. _IO_cookie_file_t *cfile = (_IO_cookie_file_t *) (S); \
  95. if (cfile->__gcs.write == NULL) { \
  96. __set_errno(EINVAL); \
  97. return -1; \
  98. } \
  99. __set_errno(EAGAIN); \
  100. w = cfile->__gcs.write(cfile->__cookie, ##ARGS); \
  101. return (w == 0 ? -1 : w); \
  102. }
  103. typedef struct {
  104. struct __STDIO_FILE_STRUCT __fp;
  105. void *__cookie;
  106. _IO_cookie_io_functions_t __gcs;
  107. } _IO_cookie_file_t;
  108. #else /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
  109. #undef __STDIO_STREAM_GLIBC_CUSTOM_FILEDES
  110. #define __STDIO_STREAM_IS_CUSTOM(S) (0)
  111. #define __STDIO_STREAM_CUSTOM_IO_FUNC(S, NAME, RC, ARGS...)
  112. #define __STDIO_STREAM_CUSTOM_WRITE_FUNC(S, ARGS...)
  113. #endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */
  114. extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attribute_hidden;
  115. static inline ssize_t __READ(FILE *stream, char *buf, size_t bufsize)
  116. {
  117. __STDIO_STREAM_CUSTOM_IO_FUNC(stream, read, -1, buf, bufsize);
  118. return read(stream->__filedes, buf, bufsize);
  119. }
  120. static inline ssize_t __WRITE(FILE *stream, const char *buf, size_t bufsize)
  121. {
  122. __STDIO_STREAM_CUSTOM_WRITE_FUNC(stream, buf, bufsize);
  123. return write(stream->__filedes, buf, bufsize);
  124. }
  125. static inline int __SEEK(FILE *stream, register __offmax_t *pos, int whence)
  126. {
  127. __STDIO_STREAM_CUSTOM_IO_FUNC(stream, seek, -1, pos, whence);
  128. return __stdio_seek(stream, pos, whence);
  129. }
  130. static inline int __CLOSE(FILE *stream)
  131. {
  132. __STDIO_STREAM_CUSTOM_IO_FUNC(stream, close, 0);
  133. return close(stream->__filedes);
  134. }
  135. /**********************************************************************/
  136. #ifdef __UCLIBC_HAS_WCHAR__
  137. #define __STDIO_STREAM_TRANS_TO_WRITE(S,O) __stdio_trans2w_o((S), (O))
  138. #define __STDIO_STREAM_TRANS_TO_READ(S,O) __stdio_trans2r_o((S), (O))
  139. #else
  140. #define __STDIO_STREAM_TRANS_TO_WRITE(S,O) __stdio_trans2w((S))
  141. #define __STDIO_STREAM_TRANS_TO_READ(S,O) __stdio_trans2r((S))
  142. #endif
  143. /**********************************************************************/
  144. #define __STDIO_STREAM_IS_READING(S) ((S)->__modeflags & __MASK_READING)
  145. #define __STDIO_STREAM_IS_WRITING(S) ((S)->__modeflags & __FLAG_WRITING)
  146. #define __STDIO_STREAM_SET_READING(S) ((S)->__modeflags |= __FLAG_READING)
  147. #define __STDIO_STREAM_SET_WRITING(S) ((S)->__modeflags |= __FLAG_WRITING)
  148. #define __STDIO_STREAM_IS_READING_OR_READONLY(S) \
  149. ((S)->__modeflags & (__MASK_READING|__FLAG_READONLY))
  150. #define __STDIO_STREAM_IS_WRITING_OR_WRITEONLY(S) \
  151. ((S)->__modeflags & (__FLAG_WRITING|__FLAG_WRITEONLY))
  152. #define __STDIO_STREAM_IS_READONLY(S) ((S)->__modeflags & __FLAG_READONLY)
  153. #define __STDIO_STREAM_IS_WRITEONLY(S) ((S)->__modeflags & __FLAG_WRITEONLY)
  154. /**********************************************************************/
  155. #ifdef __UCLIBC_HAS_WCHAR__
  156. #define __STDIO_STREAM_IS_NARROW_WRITING(S) \
  157. (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \
  158. == (__FLAG_WRITING|__FLAG_NARROW))
  159. #define __STDIO_STREAM_IS_WIDE_WRITING(S) \
  160. (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \
  161. == (__FLAG_WRITING|__FLAG_WIDE))
  162. #if (__FLAG_NARROW <= __MASK_READING)
  163. #error assumption violated regarding __FLAG_NARROW
  164. #endif
  165. #define __STDIO_STREAM_IS_NARROW_READING(S) \
  166. (((S)->__modeflags & (__MASK_READING|__FLAG_NARROW)) > __FLAG_NARROW)
  167. #define __STDIO_STREAM_IS_WIDE_READING(S) \
  168. (((S)->__modeflags & (__MASK_READING|__FLAG_WIDE)) > __FLAG_WIDE)
  169. #define __STDIO_STREAM_IS_NARROW(S) ((S)->__modeflags & __FLAG_NARROW)
  170. #define __STDIO_STREAM_IS_WIDE(S) ((S)->__modeflags & __FLAG_WIDE)
  171. #define __STDIO_STREAM_SET_NARROW(S) \
  172. ((void)((S)->__modeflags |= __FLAG_NARROW))
  173. #define __STDIO_STREAM_SET_WIDE(S) \
  174. ((void)((S)->__modeflags |= __FLAG_WIDE))
  175. #else
  176. #define __STDIO_STREAM_IS_NARROW_WRITING(S) __STDIO_STREAM_IS_WRITING(S)
  177. #define __STDIO_STREAM_IS_NARROW_READING(S) __STDIO_STREAM_IS_READING(S)
  178. #define __STDIO_STREAM_IS_NARROW(S) (1)
  179. #define __STDIO_STREAM_IS_WIDE(S) (0)
  180. #define __STDIO_STREAM_SET_NARROW(S) ((void)0)
  181. #define __STDIO_STREAM_SET_WIDE(S) ((void)0)
  182. #endif
  183. /**********************************************************************/
  184. #define __STDIO_STREAM_SET_EOF(S) \
  185. ((void)((S)->__modeflags |= __FLAG_EOF))
  186. #define __STDIO_STREAM_SET_ERROR(S) \
  187. ((void)((S)->__modeflags |= __FLAG_ERROR))
  188. #define __STDIO_STREAM_CLEAR_EOF(S) \
  189. ((void)((S)->__modeflags &= ~__FLAG_EOF))
  190. #define __STDIO_STREAM_CLEAR_ERROR(S) \
  191. ((void)((S)->__modeflags &= ~__FLAG_ERROR))
  192. #define __STDIO_STREAM_CLEAR_READING_AND_UNGOTS(S) \
  193. ((void)((S)->__modeflags &= ~__MASK_READING))
  194. #define __STDIO_STREAM_CLEAR_WRITING(S) \
  195. ((void)((S)->__modeflags &= ~__FLAG_WRITING))
  196. #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
  197. # define __STDIO_STREAM_DISABLE_GETC(S) \
  198. ((void)((S)->__bufgetc_u = (S)->__bufstart))
  199. # define __STDIO_STREAM_ENABLE_GETC(S) \
  200. ((void)((S)->__bufgetc_u = (S)->__bufread))
  201. # define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) \
  202. ((S)->__bufpos < (S)->__bufgetc_u)
  203. #else
  204. # define __STDIO_STREAM_DISABLE_GETC(S) ((void)0)
  205. # define __STDIO_STREAM_ENABLE_GETC(S) ((void)0)
  206. # define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0)
  207. #endif
  208. #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
  209. # define __STDIO_STREAM_DISABLE_PUTC(S) \
  210. ((void)((S)->__bufputc_u = (S)->__bufstart))
  211. # define __STDIO_STREAM_ENABLE_PUTC(S) \
  212. ((void)((S)->__bufputc_u = (S)->__bufend))
  213. # define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) \
  214. ((S)->__bufpos < (S)->__bufputc_u)
  215. #else
  216. # define __STDIO_STREAM_DISABLE_PUTC(S) ((void)0)
  217. # define __STDIO_STREAM_ENABLE_PUTC(S) ((void)0)
  218. # define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0)
  219. #endif
  220. /**********************************************************************/
  221. #ifdef __STDIO_BUFFERS
  222. #define __STDIO_STREAM_FREE_BUFFER(S) \
  223. do { if ((S)->__modeflags & __FLAG_FREEBUF) \
  224. free((S)->__bufstart); } while (0)
  225. #else
  226. #define __STDIO_STREAM_FREE_BUFFER(S) ((void)0)
  227. #endif
  228. #define __STDIO_STREAM_FREE_FILE(S) \
  229. do { if ((S)->__modeflags & __FLAG_FREEFILE) \
  230. free((S)); } while (0)
  231. #define __STDIO_WHEN_LFS(E) E
  232. /**********************************************************************/
  233. /* The following return 0 on success. */
  234. #ifdef __STDIO_BUFFERS
  235. /* Assume stream in valid writing state. Do not reset writing flag
  236. * or disble putc macro unless error. */
  237. /* Should we assume that buffer is not empty to avoid a check? */
  238. extern size_t __stdio_wcommit(FILE *__restrict stream) attribute_hidden;
  239. /* Remember to fail if at EOF! */
  240. extern size_t __stdio_rfill(FILE *__restrict stream) attribute_hidden;
  241. extern size_t __stdio_fwrite(const unsigned char *__restrict buffer,
  242. size_t bytes, FILE *__restrict stream) attribute_hidden;
  243. #else
  244. #define __stdio_fwrite(B,N,S) __stdio_WRITE((S),(B),(N))
  245. #endif
  246. extern size_t __stdio_WRITE(FILE *stream, const unsigned char *buf,
  247. size_t bufsize) attribute_hidden;
  248. extern size_t __stdio_READ(FILE *stream, unsigned char *buf,
  249. size_t bufsize) attribute_hidden;
  250. extern int __stdio_trans2r(FILE *__restrict stream) attribute_hidden;
  251. extern int __stdio_trans2w(FILE *__restrict stream) attribute_hidden;
  252. extern int __stdio_trans2r_o(FILE *__restrict stream, int oflag) attribute_hidden;
  253. extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidden;
  254. extern uintmax_t _load_inttype(int desttype, register const void *src, int uflag) attribute_hidden;
  255. extern void _store_inttype(void *dest, int desttype, uintmax_t val) attribute_hidden;
  256. /**********************************************************************/
  257. #ifdef __STDIO_BUFFERS
  258. #define __STDIO_STREAM_IS_FBF(S) (!((S)->__modeflags & __MASK_BUFMODE))
  259. #define __STDIO_STREAM_IS_LBF(S) ((S)->__modeflags & __FLAG_LBF)
  260. #define __STDIO_STREAM_IS_NBF(S) ((S)->__modeflags & __FLAG_NBF)
  261. #define __STDIO_STREAM_BUFFER_SIZE(S) ((S)->__bufend - (S)->__bufstart)
  262. /* Valid when writing... */
  263. #define __STDIO_STREAM_BUFFER_ADD(S,C) (*(S)->__bufpos++ = (C))
  264. #define __STDIO_STREAM_BUFFER_UNADD(S) (--(S)->__bufpos)
  265. #define __STDIO_STREAM_BUFFER_WAVAIL(S) ((S)->__bufend - (S)->__bufpos)
  266. #define __STDIO_STREAM_BUFFER_WUSED(S) ((S)->__bufpos - (S)->__bufstart)
  267. #define __STDIO_COMMIT_WRITE_BUFFER(S) __stdio_wcommit((S))
  268. #ifdef __UCLIBC_HAS_WCHAR__
  269. #define __STDIO_STREAM_IS_NARROW_FBF(S) \
  270. (!((S)->__modeflags & (__MASK_BUFMODE|__FLAG_WIDE)))
  271. #else
  272. #define __STDIO_STREAM_IS_NARROW_FBF(S) __STDIO_STREAM_IS_FBF((S))
  273. #endif
  274. /* Valid when reading... */
  275. #define __STDIO_STREAM_BUFFER_RAVAIL(S) ((S)->__bufread - (S)->__bufpos)
  276. #define __STDIO_STREAM_BUFFER_GET(S) (*(S)->__bufpos++)
  277. #define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S))
  278. #define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \
  279. (S)->__bufread = (S)->__bufpos = (S)->__bufstart
  280. #define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-3)
  281. #define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-3)
  282. #define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-4)
  283. #define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-4)
  284. #define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) \
  285. ((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES)
  286. #define __STDIO_STREAM_IS_FAKE_VSSCANF(S) \
  287. ((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES)
  288. #define __STDIO_STREAM_IS_FAKE_VSWPRINTF(S) \
  289. ((S)->__filedes == __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES)
  290. #define __STDIO_STREAM_IS_FAKE_VSWSCANF(S) \
  291. ((S)->__filedes == __STDIO_STREAM_FAKE_VSWSCANF_FILEDES)
  292. #else /* __STDIO_BUFFERS */
  293. #define __STDIO_STREAM_IS_FBF(S) (0)
  294. #define __STDIO_STREAM_IS_LBF(S) (0)
  295. #define __STDIO_STREAM_IS_NBF(S) (1)
  296. #define __STDIO_STREAM_BUFFER_SIZE(S) (0)
  297. #define __STDIO_STREAM_BUFFER_ADD(S,C) ((void)0)
  298. #define __STDIO_STREAM_BUFFER_UNADD(S) ((void)0)
  299. #define __STDIO_STREAM_BUFFER_WAVAIL(S) (0)
  300. #define __STDIO_STREAM_BUFFER_WUSED(S) (0)
  301. #define __STDIO_COMMIT_WRITE_BUFFER(S) (0)
  302. #define __STDIO_STREAM_IS_NARROW_FBF(S) (0)
  303. #define __STDIO_STREAM_BUFFER_RAVAIL(S) (0)
  304. #define __STDIO_STREAM_BUFFER_GET(S) (EOF)
  305. #define __STDIO_FILL_READ_BUFFER(S) (0)
  306. #define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0)
  307. #undef __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES
  308. #undef __STDIO_STREAM_FAKE_VSSCANF_FILEDES
  309. #undef __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES
  310. #define __STDIO_STREAM_IS_FAKE_VSNPRINTF(S) (0)
  311. #define __STDIO_STREAM_IS_FAKE_VSSCANF(S) (0)
  312. #undef __STDIO_STREAM_IS_FAKE_VSWPRINTF
  313. #undef __STDIO_STREAM_IS_FAKE_VSWSCANF
  314. # ifdef __USE_OLD_VFPRINTF__
  315. # define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2)
  316. # define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \
  317. ((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB)
  318. # endif
  319. # ifndef __UCLIBC_HAS_WCHAR__
  320. # define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2)
  321. # define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \
  322. ((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB)
  323. # endif
  324. #endif /* __STDIO_BUFFERS */
  325. /**********************************************************************/
  326. extern int __stdio_adjust_position(FILE *__restrict stream, __offmax_t *pos) attribute_hidden;
  327. #ifdef __STDIO_HAS_OPENLIST
  328. /* Uses an implementation hack!!! */
  329. #define __STDIO_FLUSH_LBF_STREAMS \
  330. fflush_unlocked((FILE *) &_stdio_openlist)
  331. #else
  332. #define __STDIO_FLUSH_LBF_STREAMS ((void)0)
  333. #endif
  334. #ifdef NDEBUG
  335. #define __STDIO_STREAM_VALIDATE(S) ((void)0)
  336. #else
  337. extern void _stdio_validate_FILE(const FILE *stream) attribute_hidden;
  338. #define __STDIO_STREAM_VALIDATE(S) _stdio_validate_FILE((S))
  339. #endif
  340. #ifdef __STDIO_MBSTATE
  341. #define __COPY_MBSTATE(dest,src) \
  342. ((void)((dest)->__mask = (src)->__mask, (dest)->__wc = (src)->__wc))
  343. #define __INIT_MBSTATE(dest) ((void)((dest)->__mask = 0))
  344. #else
  345. #define __COPY_MBSTATE(dest,src) ((void)0)
  346. #define __INIT_MBSTATE(dest) ((void)0)
  347. #endif
  348. /**********************************************************************/
  349. extern FILE *_stdio_fopen(intptr_t fname_or_mode, const char *__restrict mode,
  350. FILE *__restrict stream, int filedes) attribute_hidden;
  351. #ifdef __UCLIBC_HAS_WCHAR__
  352. extern size_t _wstdio_fwrite(const wchar_t *__restrict ws,
  353. size_t n, FILE *__restrict stream) attribute_hidden;
  354. #endif
  355. /**********************************************************************/
  356. extern int _vfprintf_internal (FILE * __restrict stream,
  357. const char * __restrict format,
  358. va_list arg) attribute_hidden;
  359. #ifdef __UCLIBC_HAS_WCHAR__
  360. extern int _vfwprintf_internal (FILE * __restrict stream,
  361. const wchar_t * __restrict format,
  362. va_list arg) attribute_hidden;
  363. #endif
  364. /**********************************************************************/
  365. /* Only use the macro below if you know fp is a valid FILE for a valid fd.
  366. * This is _not_ true for custom streams! */
  367. #define __FILENO_UNLOCKED(fp) ((fp)->__filedes)
  368. #define __FEOF_OR_FERROR_UNLOCKED(stream) \
  369. ((stream)->__modeflags & (__FLAG_EOF|__FLAG_ERROR))
  370. #if defined(__STDIO_BUFFERS) || defined(__USE_OLD_VFPRINTF__) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__)
  371. #define __STDIO_HAS_VSNPRINTF 1
  372. #endif
  373. #endif /* __STDIO_H_I */