_stdio.h 15 KB

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