_stdio.h 16 KB

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