uClibc_stdio.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566
  1. /* Copyright (C) 2002-2004 Manuel Novoa III <mjn3@codepoet.org>
  2. *
  3. * Dedicated to Toni. See uClibc/DEDICATION.mjn3 for details.
  4. *
  5. * This library is free software; you can redistribute it and/or
  6. * modify it under the terms of the GNU Lesser General Public
  7. * License as published by the Free Software Foundation; either
  8. * version 2.1 of the License, or (at your option) any later version.
  9. *
  10. * The GNU C Library is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  13. * Lesser General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU Lesser General Public
  16. * License along with the GNU C Library; if not, write to the Free
  17. * Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA
  18. * 02111-1307 USA.
  19. */
  20. #ifndef _STDIO_H
  21. #error Always include <stdio.h> rather than <bits/uClibc_stdio.h>
  22. #endif
  23. /**********************************************************************/
  24. #define __STDIO_BUFFERS
  25. /* ANSI/ISO mandate at least 256. */
  26. #if defined(__UCLIBC_HAS_STDIO_BUFSIZ_NONE__)
  27. /* Fake this because some apps use stdio.h BUFSIZ. */
  28. #define __STDIO_BUFSIZ 256
  29. #undef __STDIO_BUFFERS
  30. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_256__)
  31. #define __STDIO_BUFSIZ 256
  32. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_512__)
  33. #define __STDIO_BUFSIZ 512
  34. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_1024__)
  35. #define __STDIO_BUFSIZ 1024
  36. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_2048__)
  37. #define __STDIO_BUFSIZ 2048
  38. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_4096__)
  39. #define __STDIO_BUFSIZ 4096
  40. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_8192__)
  41. #define __STDIO_BUFSIZ 8192
  42. #else
  43. #error config seems to be out of sync regarding bufsiz options
  44. #endif
  45. #ifdef __UCLIBC_HAS_STDIO_BUFSIZ_NONE__
  46. #define __STDIO_BUILTIN_BUF_SIZE 0
  47. #else /* __UCLIBC_HAS_STDIO_BUFSIZ_NONE__ */
  48. #if defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE__)
  49. #define __STDIO_BUILTIN_BUF_SIZE 0
  50. #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4__)
  51. #define __STDIO_BUILTIN_BUF_SIZE 4
  52. #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8__)
  53. #define __STDIO_BUILTIN_BUF_SIZE 8
  54. #else
  55. #error config seems to be out of sync regarding builtin buffer size
  56. #endif
  57. #endif
  58. #if defined(__STDIO_BUFFERS) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__) || defined(__UCLIBC_HAS_THREADS__)
  59. #define __STDIO_HAS_OPENLIST 1
  60. #else
  61. #undef __STDIO_HAS_OPENLIST
  62. #endif
  63. /**********************************************************************/
  64. /* Make sure defines related to large files are consistent. */
  65. #if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc)
  66. #ifdef __UCLIBC_HAS_LFS__
  67. #undef __USE_LARGEFILE
  68. #undef __USE_LARGEFILE64
  69. #undef __USE_FILE_OFFSET64
  70. /* If we're actually building uClibc with large file support, only define... */
  71. #define __USE_LARGEFILE64 1
  72. #endif /* __UCLIBC_HAS_LFS__ */
  73. #else /* not _LIBC */
  74. #ifndef __UCLIBC_HAS_LFS__
  75. #if defined(__LARGEFILE64_SOURCE) || defined(__USE_LARGEFILE64) || defined(__USE_FILE_OFFSET64)
  76. #error Sorry... uClibc was built without large file support!
  77. #endif
  78. #endif /* __UCLIBC_HAS_LFS__ */
  79. #endif /* _LIBC */
  80. /**********************************************************************/
  81. #ifdef __UCLIBC_HAS_WCHAR__
  82. #define __need_wchar_t
  83. #include <stddef.h>
  84. /* Note: we don't really need mbstate for 8-bit locales. We do for UTF-8.
  85. * For now, always use it. */
  86. #define __STDIO_MBSTATE
  87. #define __need_mbstate_t
  88. #include <wchar.h>
  89. #endif
  90. /**********************************************************************/
  91. /* Currently unimplemented/untested */
  92. /* #define __STDIO_FLEXIBLE_SETVBUF */
  93. #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
  94. #define __STDIO_GETC_MACRO
  95. #endif
  96. #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
  97. #define __STDIO_PUTC_MACRO
  98. #endif
  99. /* These are consistency checks on the different options */
  100. #ifndef __STDIO_BUFFERS
  101. #undef __STDIO_GETC_MACRO
  102. #undef __STDIO_PUTC_MACRO
  103. #endif
  104. #ifdef __BCC__
  105. #undef __UCLIBC_HAS_LFS__
  106. #endif
  107. #ifndef __UCLIBC_HAS_LFS__
  108. #undef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
  109. #endif
  110. /**********************************************************************/
  111. #ifdef __UCLIBC_HAS_THREADS__
  112. /* Need this for pthread_mutex_t. */
  113. #include <bits/pthreadtypes.h>
  114. /* user_locking
  115. * 0 : do auto locking/unlocking
  116. * 1 : user does locking/unlocking
  117. * 2 : initial state prior to thread initialization
  118. * with no auto locking/unlocking
  119. *
  120. * When threading is initialized, walk the stdio open stream list
  121. * and do "if (user_locking == 2) user_locking = 0;".
  122. *
  123. * This way, we avoid calling the weak lock/unlock functions.
  124. */
  125. #define __STDIO_AUTO_THREADLOCK_VAR int __infunc_user_locking
  126. #define __STDIO_AUTO_THREADLOCK(__stream) \
  127. do { \
  128. struct _pthread_cleanup_buffer __infunc_pthread_cleanup_buffer; \
  129. if ((__infunc_user_locking = (__stream)->__user_locking) == 0) { \
  130. _pthread_cleanup_push_defer(&__infunc_pthread_cleanup_buffer, \
  131. __pthread_mutex_unlock, \
  132. &(__stream)->__lock); \
  133. __pthread_mutex_lock(&(__stream)->__lock); \
  134. } \
  135. ((void)0)
  136. #define __STDIO_AUTO_THREADUNLOCK(__stream) \
  137. if (__infunc_user_locking == 0) { \
  138. _pthread_cleanup_pop_restore(&__infunc_pthread_cleanup_buffer,1);\
  139. } \
  140. } while (0)
  141. #define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1)
  142. #define __STDIO_ALWAYS_THREADLOCK(__stream) \
  143. do { \
  144. struct _pthread_cleanup_buffer __infunc_pthread_cleanup_buffer; \
  145. _pthread_cleanup_push_defer(&__infunc_pthread_cleanup_buffer, \
  146. __pthread_mutex_unlock, \
  147. &(__stream)->__lock); \
  148. __pthread_mutex_lock(&(__stream)->__lock); \
  149. ((void)0)
  150. /* #define __STDIO_ALWAYS_THREADTRYLOCK(__stream) \ */
  151. /* __pthread_mutex_trylock(&(__stream)->__lock) */
  152. #define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
  153. _pthread_cleanup_pop_restore(&__infunc_pthread_cleanup_buffer,1); \
  154. } while (0)
  155. #define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) \
  156. __pthread_mutex_lock(&(__stream)->__lock)
  157. #define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) \
  158. __pthread_mutex_trylock(&(__stream)->__lock)
  159. #define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) \
  160. __pthread_mutex_unlock(&(__stream)->__lock)
  161. #else /* __UCLIBC_HAS_THREADS__ */
  162. #define __STDIO_AUTO_THREADLOCK_VAR ((void)0)
  163. #define __STDIO_AUTO_THREADLOCK(__stream) ((void)0)
  164. #define __STDIO_AUTO_THREADUNLOCK(__stream) ((void)0)
  165. #define __STDIO_SET_USER_LOCKING(__stream) ((void)0)
  166. #define __STDIO_ALWAYS_THREADLOCK(__stream) ((void)0)
  167. /* #define __STDIO_ALWAYS_THREADTRYLOCK(__stream) (0) /\* Always succeed. *\/ */
  168. #define __STDIO_ALWAYS_THREADUNLOCK(__stream) ((void)0)
  169. #define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) ((void)0)
  170. #define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) (0) /* Ok? */
  171. #define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) ((void)0)
  172. #endif /* __UCLIBC_HAS_THREADS__ */
  173. /**********************************************************************/
  174. #define __STDIO_IOFBF 0 /* Fully buffered. */
  175. #define __STDIO_IOLBF 1 /* Line buffered. */
  176. #define __STDIO_IONBF 2 /* No buffering. */
  177. typedef struct {
  178. __off_t __pos;
  179. #ifdef __STDIO_MBSTATE
  180. __mbstate_t __mbstate;
  181. #endif
  182. #ifdef __UCLIBC_HAS_WCHAR__
  183. int __mblen_pending;
  184. #endif
  185. } __STDIO_fpos_t;
  186. #ifdef __UCLIBC_HAS_LFS__
  187. typedef struct {
  188. __off64_t __pos;
  189. #ifdef __STDIO_MBSTATE
  190. __mbstate_t __mbstate;
  191. #endif
  192. #ifdef __UCLIBC_HAS_WCHAR__
  193. int __mblen_pending;
  194. #endif
  195. } __STDIO_fpos64_t;
  196. #endif
  197. /**********************************************************************/
  198. #ifdef __UCLIBC_HAS_LFS__
  199. typedef __off64_t __offmax_t; /* TODO -- rename this? */
  200. #else
  201. typedef __off_t __offmax_t; /* TODO -- rename this? */
  202. #endif
  203. /**********************************************************************/
  204. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  205. typedef __ssize_t __io_read_fn(void *__cookie, char *__buf, size_t __bufsize);
  206. typedef __ssize_t __io_write_fn(void *__cookie,
  207. __const char *__buf, size_t __bufsize);
  208. /* NOTE: GLIBC difference!!! -- fopencookie seek function
  209. * For glibc, the type of pos is always (__off64_t *) but in our case
  210. * it is type (__off_t *) when the lib is built without large file support.
  211. */
  212. typedef int __io_seek_fn(void *__cookie, __offmax_t *__pos, int __whence);
  213. typedef int __io_close_fn(void *__cookie);
  214. typedef struct {
  215. __io_read_fn *read;
  216. __io_write_fn *write;
  217. __io_seek_fn *seek;
  218. __io_close_fn *close;
  219. } _IO_cookie_io_functions_t;
  220. #ifdef __USE_GNU
  221. typedef __io_read_fn cookie_read_function_t;
  222. typedef __io_write_fn cookie_write_function_t;
  223. typedef __io_seek_fn cookie_seek_function_t;
  224. typedef __io_close_fn cookie_close_function_t;
  225. typedef _IO_cookie_io_functions_t cookie_io_functions_t;
  226. #endif
  227. #endif
  228. /**********************************************************************/
  229. struct __STDIO_FILE_STRUCT {
  230. unsigned short __modeflags;
  231. /* There could be a hole here, but modeflags is used most.*/
  232. #ifdef __UCLIBC_HAS_WCHAR__
  233. unsigned char __ungot_width[2]; /* 0: current (building) char; 1: scanf */
  234. /* Move the following futher down to avoid problems with getc/putc
  235. * macros breaking shared apps when wchar config support is changed. */
  236. /* wchar_t ungot[2]; */
  237. #else /* __UCLIBC_HAS_WCHAR__ */
  238. unsigned char __ungot[2];
  239. #endif /* __UCLIBC_HAS_WCHAR__ */
  240. int __filedes;
  241. #ifdef __STDIO_BUFFERS
  242. unsigned char *__bufstart; /* pointer to buffer */
  243. unsigned char *__bufend; /* pointer to 1 past end of buffer */
  244. unsigned char *__bufpos;
  245. unsigned char *__bufread; /* pointer to 1 past last buffered read char */
  246. #ifdef __STDIO_GETC_MACRO
  247. unsigned char *__bufgetc_u; /* 1 past last readable by getc_unlocked */
  248. #endif /* __STDIO_GETC_MACRO */
  249. #ifdef __STDIO_PUTC_MACRO
  250. unsigned char *__bufputc_u; /* 1 past last writeable by putc_unlocked */
  251. #endif /* __STDIO_PUTC_MACRO */
  252. #endif /* __STDIO_BUFFERS */
  253. #ifdef __STDIO_HAS_OPENLIST
  254. struct __STDIO_FILE_STRUCT *__nextopen;
  255. #endif
  256. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  257. void *__cookie;
  258. _IO_cookie_io_functions_t __gcs;
  259. #endif
  260. #ifdef __UCLIBC_HAS_WCHAR__
  261. wchar_t __ungot[2];
  262. #endif
  263. #ifdef __STDIO_MBSTATE
  264. __mbstate_t __state;
  265. #endif
  266. #ifdef __UCLIBC_HAS_XLOCALE__
  267. void *__unused; /* Placeholder for codeset binding. */
  268. #endif
  269. #ifdef __UCLIBC_HAS_THREADS__
  270. int __user_locking;
  271. pthread_mutex_t __lock;
  272. #endif
  273. /* Everything after this is unimplemented... and may be trashed. */
  274. #if __STDIO_BUILTIN_BUF_SIZE > 0
  275. unsigned char __builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
  276. #endif /* __STDIO_BUILTIN_BUF_SIZE > 0 */
  277. };
  278. /***********************************************************************/
  279. /* Having ungotten characters implies the stream is reading.
  280. * The scheme used here treats the least significant 2 bits of
  281. * the stream's modeflags member as follows:
  282. * 0 0 Not currently reading.
  283. * 0 1 Reading, but no ungetc() or scanf() push back chars.
  284. * 1 0 Reading with one ungetc() char (ungot[1] is 1)
  285. * or one scanf() pushed back char (ungot[1] is 0).
  286. * 1 1 Reading with both an ungetc() char and a scanf()
  287. * pushed back char. Note that this must be the result
  288. * of a scanf() push back (in ungot[0]) _followed_ by
  289. * an ungetc() call (in ungot[1]).
  290. *
  291. * Notes:
  292. * scanf() can NOT use ungetc() to push back characters.
  293. * (See section 7.19.6.2 of the C9X rationale -- WG14/N897.)
  294. */
  295. #define __MASK_READING 0x0003U /* (0x0001 | 0x0002) */
  296. #define __FLAG_READING 0x0001U
  297. #define __FLAG_UNGOT 0x0002U
  298. #define __FLAG_EOF 0x0004U
  299. #define __FLAG_ERROR 0x0008U
  300. #define __FLAG_WRITEONLY 0x0010U
  301. #define __FLAG_READONLY 0x0020U /* (__FLAG_WRITEONLY << 1) */
  302. #define __FLAG_WRITING 0x0040U
  303. #define __FLAG_NARROW 0x0080U
  304. #define __FLAG_FBF 0x0000U /* must be 0 */
  305. #define __FLAG_LBF 0x0100U
  306. #define __FLAG_NBF 0x0200U /* (__FLAG_LBF << 1) */
  307. #define __MASK_BUFMODE 0x0300U /* (__FLAG_LBF|__FLAG_NBF) */
  308. #define __FLAG_APPEND 0x0400U /* fixed! == O_APPEND for linux */
  309. #define __FLAG_WIDE 0x0800U
  310. /* available slot 0x1000U */
  311. #define __FLAG_FREEFILE 0x2000U
  312. #define __FLAG_FREEBUF 0x4000U
  313. #define __FLAG_LARGEFILE 0x8000U /* fixed! == 0_LARGEFILE for linux */
  314. #define __FLAG_FAILED_FREOPEN __FLAG_LARGEFILE
  315. /* Note: In no-buffer mode, it would be possible to pack the necessary
  316. * flags into one byte. Since we wouldn't be buffering and there would
  317. * be no support for wchar, the only flags we would need would be:
  318. * 2 bits : ungot count
  319. * 2 bits : eof + error
  320. * 2 bits : readonly + writeonly
  321. * 1 bit : freefile
  322. * 1 bit : appending
  323. * So, for a very small system (< 128 files) we might have a
  324. * 4-byte FILE struct of:
  325. * unsigned char flags;
  326. * signed char filedes;
  327. * unsigned char ungot[2];
  328. */
  329. /**********************************************************************
  330. * PROTOTYPES OF INTERNAL FUNCTIONS
  331. **********************************************************************/
  332. #if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc)
  333. extern void _stdio_init(void) attribute_hidden;
  334. extern void _stdio_term(void) attribute_hidden;
  335. #ifdef __STDIO_HAS_OPENLIST
  336. extern struct __STDIO_FILE_STRUCT *_stdio_openlist;
  337. #ifdef __UCLIBC_HAS_THREADS__
  338. extern pthread_mutex_t _stdio_openlist_add_lock;
  339. #ifdef __STDIO_BUFFERS
  340. extern pthread_mutex_t _stdio_openlist_del_lock;
  341. extern volatile int _stdio_openlist_use_count; /* _stdio_openlist_del_lock */
  342. extern int _stdio_openlist_del_count; /* _stdio_openlist_del_lock */
  343. #endif
  344. extern int _stdio_user_locking;
  345. /* #ifdef _LIBC */
  346. extern void __stdio_init_mutex(pthread_mutex_t *m) attribute_hidden;
  347. /* #endif */
  348. #endif
  349. #endif
  350. #endif
  351. /**********************************************************************/
  352. #define __CLEARERR_UNLOCKED(__stream) \
  353. ((void)((__stream)->__modeflags &= ~(__FLAG_EOF|__FLAG_ERROR)))
  354. #define __FEOF_UNLOCKED(__stream) ((__stream)->__modeflags & __FLAG_EOF)
  355. #define __FERROR_UNLOCKED(__stream) ((__stream)->__modeflags & __FLAG_ERROR)
  356. #ifdef __UCLIBC_HAS_THREADS__
  357. # define __CLEARERR(__stream) (clearerr)(__stream)
  358. # define __FERROR(__stream) (ferror)(__stream)
  359. # define __FEOF(__stream) (feof)(__stream)
  360. #else
  361. # define __CLEARERR(__stream) __CLEARERR_UNLOCKED(__stream)
  362. # define __FERROR(__stream) __FERROR_UNLOCKED(__stream)
  363. # define __FEOF(__stream) __FEOF_UNLOCKED(__stream)
  364. #endif
  365. extern int __fgetc_unlocked(FILE *__stream);
  366. extern int __fputc_unlocked(int __c, FILE *__stream);
  367. /* First define the default definitions. They will be overwritten below as necessary. */
  368. #define __FGETC_UNLOCKED(__stream) (__fgetc_unlocked)((__stream))
  369. #define __FGETC(__stream) (fgetc)((__stream))
  370. #define __GETC_UNLOCKED_MACRO(__stream) (__fgetc_unlocked)((__stream))
  371. #define __GETC_UNLOCKED(__stream) (__fgetc_unlocked)((__stream))
  372. #define __GETC(__stream) (fgetc)((__stream))
  373. #define __FPUTC_UNLOCKED(__c, __stream) (__fputc_unlocked)((__c),(__stream))
  374. #define __FPUTC(__c, __stream) (fputc)((__c),(__stream))
  375. #define __PUTC_UNLOCKED_MACRO(__c, __stream) (__fputc_unlocked)((__c),(__stream))
  376. #define __PUTC_UNLOCKED(__c, __stream) (__fputc_unlocked)((__c),(__stream))
  377. #define __PUTC(__c, __stream) (fputc)((__c),(__stream))
  378. #ifdef __STDIO_GETC_MACRO
  379. extern FILE *__stdin; /* For getchar() macro. */
  380. # undef __GETC_UNLOCKED_MACRO
  381. # define __GETC_UNLOCKED_MACRO(__stream) \
  382. ( ((__stream)->__bufpos < (__stream)->__bufgetc_u) \
  383. ? (*(__stream)->__bufpos++) \
  384. : __fgetc_unlocked(__stream) )
  385. # if 0
  386. /* Classic macro approach. getc{_unlocked} can have side effects. */
  387. # undef __GETC_UNLOCKED
  388. # define __GETC_UNLOCKED(__stream) __GETC_UNLOCKED_MACRO((__stream))
  389. # ifndef __UCLIBC_HAS_THREADS__
  390. # undef __GETC
  391. # define __GETC(__stream) __GETC_UNLOCKED_MACRO((__stream))
  392. # endif
  393. # else
  394. /* Using gcc extension for safety and additional inlining. */
  395. # undef __FGETC_UNLOCKED
  396. # define __FGETC_UNLOCKED(__stream) \
  397. (__extension__ ({ \
  398. FILE *__S = (__stream); \
  399. __GETC_UNLOCKED_MACRO(__S); \
  400. }) )
  401. # undef __GETC_UNLOCKED
  402. # define __GETC_UNLOCKED(__stream) __FGETC_UNLOCKED((__stream))
  403. # ifdef __UCLIBC_HAS_THREADS__
  404. # undef __FGETC
  405. # define __FGETC(__stream) \
  406. (__extension__ ({ \
  407. FILE *__S = (__stream); \
  408. ((__S->__user_locking ) \
  409. ? __GETC_UNLOCKED_MACRO(__S) \
  410. : (fgetc)(__S)); \
  411. }) )
  412. # undef __GETC
  413. # define __GETC(__stream) __FGETC((__stream))
  414. # else
  415. # undef __FGETC
  416. # define __FGETC(__stream) __FGETC_UNLOCKED((__stream))
  417. # undef __GETC
  418. # define __GETC(__stream) __FGETC_UNLOCKED((__stream))
  419. # endif
  420. # endif
  421. #else
  422. #endif /* __STDIO_GETC_MACRO */
  423. #ifdef __STDIO_PUTC_MACRO
  424. extern FILE *__stdout; /* For putchar() macro. */
  425. # undef __PUTC_UNLOCKED_MACRO
  426. # define __PUTC_UNLOCKED_MACRO(__c, __stream) \
  427. ( ((__stream)->__bufpos < (__stream)->__bufputc_u) \
  428. ? (*(__stream)->__bufpos++) = (__c) \
  429. : __fputc_unlocked((__c),(__stream)) )
  430. # if 0
  431. /* Classic macro approach. putc{_unlocked} can have side effects.*/
  432. # undef __PUTC_UNLOCKED
  433. # define __PUTC_UNLOCKED(__c, __stream) \
  434. __PUTC_UNLOCKED_MACRO((__c), (__stream))
  435. # ifndef __UCLIBC_HAS_THREADS__
  436. # undef __PUTC
  437. # define __PUTC(__c, __stream) __PUTC_UNLOCKED_MACRO((__c), (__stream))
  438. # endif
  439. # else
  440. /* Using gcc extension for safety and additional inlining. */
  441. # undef __FPUTC_UNLOCKED
  442. # define __FPUTC_UNLOCKED(__c, __stream) \
  443. (__extension__ ({ \
  444. FILE *__S = (__stream); \
  445. __PUTC_UNLOCKED_MACRO((__c),__S); \
  446. }) )
  447. # undef __PUTC_UNLOCKED
  448. # define __PUTC_UNLOCKED(__c, __stream) __FPUTC_UNLOCKED((__c), (__stream))
  449. # ifdef __UCLIBC_HAS_THREADS__
  450. # undef __FPUTC
  451. # define __FPUTC(__c, __stream) \
  452. (__extension__ ({ \
  453. FILE *__S = (__stream); \
  454. ((__S->__user_locking) \
  455. ? __PUTC_UNLOCKED_MACRO((__c),__S) \
  456. : (fputc)((__c),__S)); \
  457. }) )
  458. # undef __PUTC
  459. # define __PUTC(__c, __stream) __FPUTC((__c), (__stream))
  460. # else
  461. # undef __FPUTC
  462. # define __FPUTC(__c, __stream) __FPUTC_UNLOCKED((__c),(__stream))
  463. # undef __PUTC
  464. # define __PUTC(__c, __stream) __FPUTC_UNLOCKED((__c),(__stream))
  465. # endif
  466. # endif
  467. #endif /* __STDIO_PUTC_MACRO */