uClibc_stdio.h 18 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597
  1. /* Copyright (C) 2002 Manuel Novoa III
  2. * Header for my stdio library for linux and (soon) elks.
  3. *
  4. * This library is free software; you can redistribute it and/or
  5. * modify it under the terms of the GNU Library General Public
  6. * License as published by the Free Software Foundation; either
  7. * version 2 of the License, or (at your option) any later version.
  8. *
  9. * This library is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  12. * Library General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU Library General Public
  15. * License along with this library; if not, write to the Free
  16. * Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  17. */
  18. /* ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION!
  19. *
  20. * This code is currently under development. Also, I plan to port
  21. * it to elks which is a 16-bit environment with a fairly limited
  22. * compiler. Therefore, please refrain from modifying this code
  23. * and, instead, pass any bug-fixes, etc. to me. Thanks. Manuel
  24. *
  25. * ATTENTION! ATTENTION! ATTENTION! ATTENTION! ATTENTION! */
  26. #ifndef _STDIO_H
  27. #error Always include <stdio.h> rather than <bits/uClibc_stdio.h>
  28. #endif
  29. /**********************************************************************/
  30. #ifdef __UCLIBC__
  31. #ifdef __UCLIBC_HAS_THREADS__
  32. #define __STDIO_THREADSAFE
  33. #endif
  34. #ifdef __UCLIBC_HAS_LFS__
  35. #define __STDIO_LARGE_FILES
  36. #endif /* __UCLIBC_HAS_LFS__ */
  37. #ifdef __UCLIBC_HAS_WCHAR__
  38. #define __STDIO_WIDE
  39. #endif
  40. #define __STDIO_BUFFERS
  41. /* ANSI/ISO mandate at least 256. */
  42. #if defined(__UCLIBC_HAS_STDIO_BUFSIZ_NONE__)
  43. /* Fake this because some apps use stdio.h BUFSIZ. */
  44. #define _STDIO_BUFSIZ 256
  45. #undef __STDIO_BUFFERS
  46. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_256__)
  47. #define _STDIO_BUFSIZ 256
  48. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_512__)
  49. #define _STDIO_BUFSIZ 512
  50. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_1024__)
  51. #define _STDIO_BUFSIZ 1024
  52. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_2048__)
  53. #define _STDIO_BUFSIZ 2048
  54. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_4096__)
  55. #define _STDIO_BUFSIZ 4096
  56. #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_8192__)
  57. #define _STDIO_BUFSIZ 8192
  58. #else
  59. #error config seems to be out of sync regarding bufsiz options
  60. #endif
  61. #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
  62. #define __STDIO_GETC_MACRO
  63. #endif
  64. #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
  65. #define __STDIO_PUTC_MACRO
  66. #endif
  67. #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
  68. #define __STDIO_AUTO_RW_TRANSITION
  69. #endif
  70. #ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
  71. #define __STDIO_FOPEN_LARGEFILE_MODE
  72. #endif
  73. #ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
  74. #define __STDIO_FOPEN_EXCLUSIVE_MODE
  75. #endif
  76. #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
  77. #define __STDIO_PRINTF_M_SUPPORT
  78. #endif
  79. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
  80. #define __STDIO_GLIBC_CUSTOM_STREAMS
  81. #endif
  82. #ifdef __UCLIBC_HAS_STDIO_BUFSIZ_NONE__
  83. #define _STDIO_BUILTIN_BUF_SIZE 0
  84. #else /* __UCLIBC_HAS_STDIO_BUFSIZ_NONE__ */
  85. #if defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE__)
  86. #define _STDIO_BUILTIN_BUF_SIZE 0
  87. #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4__)
  88. #define _STDIO_BUILTIN_BUF_SIZE 4
  89. #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8__)
  90. #define _STDIO_BUILTIN_BUF_SIZE 8
  91. #else
  92. #error config seems to be out of sync regarding builtin buffer size
  93. #endif
  94. #endif /* __UCLIBC_HAS_STDIO_BUFSIZ_NONE__ */
  95. #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
  96. #define __STDIO_GLIBC_CUSTOM_PRINTF
  97. #endif
  98. /* Currently unimplemented/untested */
  99. /* #define __STDIO_FLEXIBLE_SETVBUF */
  100. /* Make sure defines related to large files are consistent. */
  101. #ifdef _LIBC
  102. #ifdef __UCLIBC_HAS_LFS__
  103. #undef __USE_LARGEFILE
  104. #undef __USE_LARGEFILE64
  105. #undef __USE_FILE_OFFSET64
  106. /* if we're actually building uClibc with large file support, only define... */
  107. #define __USE_LARGEFILE64 1
  108. #endif /* __UCLIBC_HAS_LFS__ */
  109. #else /* not _LIBC */
  110. #ifndef __UCLIBC_HAS_LFS__
  111. #if defined(__LARGEFILE64_SOURCE) || defined(__USE_LARGEFILE64) \
  112. || defined(__USE_FILE_OFFSET64)
  113. #error Sorry... uClibc was built without large file support!
  114. #endif
  115. #endif /* __UCLIBC_HAS_LFS__ */
  116. #endif /* _LIBC */
  117. #endif /* __UCLIBC__ */
  118. /**********************************************************************/
  119. /* These are the stdio configuration options. Keep them here until
  120. uClibc's configuration process gets reworked. */
  121. #ifdef __STDIO_WIDE
  122. #define __need_wchar_t
  123. #include <stddef.h>
  124. /* Note: we don't really need mbstate for 8-bit locales. We do for UTF-8.
  125. * For now, always use it. */
  126. #define __STDIO_MBSTATE
  127. #define __need_mbstate_t
  128. #include <wchar.h>
  129. #endif
  130. /* For uClibc, these are currently handled above. */
  131. /* #define __STDIO_BUFFERS */
  132. /* #define __STDIO_GETC_MACRO */
  133. /* #define __STDIO_PUTC_MACRO */
  134. /* #define __STDIO_LARGE_FILES */
  135. /* #define __STDIO_THREADSAFE */
  136. /* ANSI/ISO mandate at least 256. */
  137. /* #define _STDIO_BUFSIZ 256 */
  138. /* #define __STDIO_AUTO_RW_TRANSITION */
  139. /* #define __STDIO_FOPEN_EXCLUSIVE_MODE */
  140. /* #define __STDIO_PRINTF_M_SPEC */
  141. /* #define __STDIO_GLIBC_CUSTOM_STREAMS */
  142. /* L mode extension for fopen. */
  143. /* #define __STDIO_FOPEN_LARGEFILE_MODE */
  144. /* size of builtin buf -- only tested with 0 */
  145. /* #define _STDIO_BUILTIN_BUF_SIZE 0 */
  146. /* Currently unimplemented/untested */
  147. /* #define __STDIO_FLEXIBLE_SETVBUF */
  148. /**********************************************************************/
  149. /* TODO -- posix or gnu -- belongs in limits.h and >= 9 for sus */
  150. /* NOTE: for us it is currently _always_ 9 */
  151. /*#define NL_ARGMAX 9*/
  152. /**********************************************************************/
  153. /* These are consistency checks on the different options */
  154. #ifndef __STDIO_BUFFERS
  155. #undef __STDIO_GETC_MACRO
  156. #undef __STDIO_PUTC_MACRO
  157. #endif
  158. #ifdef __BCC__
  159. #undef __STDIO_LARGE_FILES
  160. #endif
  161. #ifndef __STDIO_LARGE_FILES
  162. #undef __STDIO_FOPEN_LARGEFILE_MODE
  163. #endif
  164. /**********************************************************************/
  165. #ifdef __STDIO_THREADSAFE
  166. /* Need this for pthread_mutex_t. */
  167. #include <bits/pthreadtypes.h>
  168. #define __STDIO_THREADLOCK(STREAM) \
  169. if ((STREAM)->user_locking == 0) { \
  170. pthread_mutex_lock(&(STREAM)->lock); \
  171. }
  172. #define __STDIO_THREADUNLOCK(STREAM) \
  173. if ((STREAM)->user_locking == 0) { \
  174. pthread_mutex_unlock(&(STREAM)->lock); \
  175. }
  176. #define __STDIO_THREADTRYLOCK(STREAM) \
  177. if ((STREAM)->user_locking == 0) { \
  178. pthread_mutex_trylock(&(STREAM)->lock); \
  179. }
  180. #else /* __STDIO_THREADSAFE */
  181. #define __STDIO_THREADLOCK(STREAM)
  182. #define __STDIO_THREADUNLOCK(STREAM)
  183. #define __STDIO_THREADTRYLOCK(STREAM)
  184. #endif /* __STDIO_THREADSAFE */
  185. /* This file may eventually have two personalities:
  186. 1) core stuff (similar to glibc's libio.h)
  187. 2) extern inlines (for glibc's bits/stdio.h)
  188. Right now, only (1) is implemented. */
  189. #define _STDIO_IOFBF 0 /* Fully buffered. */
  190. #define _STDIO_IOLBF 1 /* Line buffered. */
  191. #define _STDIO_IONBF 2 /* No buffering. */
  192. typedef struct {
  193. __off_t __pos;
  194. #ifdef __STDIO_MBSTATE
  195. __mbstate_t __mbstate;
  196. #endif
  197. #ifdef __STDIO_WIDE
  198. int mblen_pending;
  199. #endif
  200. } __stdio_fpos_t;
  201. #ifdef __STDIO_LARGE_FILES
  202. typedef struct {
  203. __off64_t __pos;
  204. #ifdef __STDIO_MBSTATE
  205. __mbstate_t __mbstate;
  206. #endif
  207. #ifdef __STDIO_WIDE
  208. int mblen_pending;
  209. #endif
  210. } __stdio_fpos64_t;
  211. #endif
  212. /**********************************************************************/
  213. #ifdef __STDIO_LARGE_FILES
  214. typedef __off64_t __offmax_t; /* TODO -- rename this? */
  215. #else
  216. typedef __off_t __offmax_t; /* TODO -- rename this? */
  217. #endif
  218. /**********************************************************************/
  219. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  220. typedef __ssize_t __io_read_fn(void *cookie,
  221. char *buf, size_t bufsize);
  222. typedef __ssize_t __io_write_fn(void *cookie,
  223. const char *buf, size_t bufsize);
  224. /* NOTE: GLIBC difference!!! -- fopencookie seek function
  225. * For glibc, the type of pos is always (__off64_t *) but in our case
  226. * it is type (__off_t *) when the lib is built without large file support.
  227. */
  228. typedef int __io_seek_fn(void *cookie,
  229. __offmax_t *pos, int whence);
  230. typedef int __io_close_fn(void *cookie);
  231. typedef struct {
  232. __io_read_fn *read;
  233. __io_write_fn *write;
  234. __io_seek_fn *seek;
  235. __io_close_fn *close;
  236. } _IO_cookie_io_functions_t;
  237. #if defined(_LIBC) || defined(_GNU_SOURCE)
  238. typedef __io_read_fn cookie_read_function_t;
  239. typedef __io_write_fn cookie_write_function_t;
  240. typedef __io_seek_fn cookie_seek_function_t;
  241. typedef __io_close_fn cookie_close_function_t;
  242. typedef _IO_cookie_io_functions_t cookie_io_functions_t;
  243. #endif /* _GNU_SOURCE */
  244. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  245. /*
  246. * ungot scheme:
  247. * 0 0 none
  248. * 0 1 one user (unused ungot is 1) or one scanf (unused ungot is 0)
  249. * 1 0 must be scanf[0] and user[1]
  250. * 1 1 illegal -- could be used to signal safe for setbuf
  251. * but if used, need to fix _stdio_adjpos at least!
  252. */
  253. #ifdef __UCLIBC__
  254. #define __stdio_file_struct _UC_FILE
  255. #endif
  256. struct __stdio_file_struct {
  257. unsigned short modeflags;
  258. /* There could be a hole here, but modeflags is used most.*/
  259. #ifdef __STDIO_WIDE
  260. /* TODO - ungot_width could be combined with ungot. But what about hole? */
  261. unsigned char ungot_width[2]; /* 0 is current (building) char, 1 is scanf */
  262. wchar_t ungot[2];
  263. #else /* __STDIO_WIDE */
  264. unsigned char ungot[2];
  265. #endif /* __STDIO_WIDE */
  266. int filedes;
  267. #if defined(__STDIO_BUFFERS) || defined(__STDIO_GLIBC_CUSTOM_STREAMS)
  268. struct __stdio_file_struct *nextopen;
  269. #endif /* defined(__STDIO_BUFFERS) || defined(__STDIO_GLIBC_CUSTOM_STREAMS) */
  270. #ifdef __STDIO_BUFFERS
  271. unsigned char *bufstart; /* pointer to buffer */
  272. unsigned char *bufend; /* pointer to 1 past end of buffer */
  273. unsigned char *bufpos;
  274. unsigned char *bufread; /* pointer to 1 past last buffered read char. */
  275. #ifdef __STDIO_GETC_MACRO
  276. unsigned char *bufgetc; /* 1 past last readable by getc */
  277. #endif /* __STDIO_GETC_MACRO */
  278. #ifdef __STDIO_PUTC_MACRO
  279. unsigned char *bufputc; /* 1 past last writeable by putc */
  280. #endif /* __STDIO_PUTC_MACRO */
  281. #endif /* __STDIO_BUFFERS */
  282. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  283. void *cookie;
  284. _IO_cookie_io_functions_t gcs;
  285. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  286. #ifdef __STDIO_MBSTATE
  287. __mbstate_t state;
  288. #endif
  289. #ifdef __STDIO_THREADSAFE
  290. int user_locking;
  291. pthread_mutex_t lock;
  292. #endif
  293. /* Everything after this is unimplemented... and may be trashed. */
  294. #if __STDIO_BUILTIN_BUF_SIZE > 0
  295. unsigned char builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
  296. #endif /* __STDIO_BUILTIN_BUF_SIZE > 0 */
  297. };
  298. /***********************************************************************/
  299. #define __MASK_UNGOT (0x0002|0x0001)
  300. #define __MASK_UNGOT1 0x0001
  301. #define __MASK_UNGOT2 0x0002
  302. #define __FLAG_EOF 0x0004 /* EOF reached? */
  303. #define __FLAG_ERROR 0x0008 /* stream in error state? */
  304. #define __FLAG_WRITEONLY 0x0010 /* unreadable */
  305. #define __FLAG_READONLY 0x0020 /* unwriteable */
  306. #define __FLAG_FREEFILE 0x0040 /* free FILE struct after use */
  307. #define __FLAG_NARROW 0x0080
  308. #define __FLAG_FBF 0 /* convenience value */
  309. #define __FLAG_LBF 0x0100
  310. #define __FLAG_NBF 0x0200
  311. #define __MASK_BUFMODE 0x0300
  312. #define __FLAG_APPEND 0x0400
  313. #define __FLAG_WIDE 0x0800
  314. #define __FLAG_READING 0x1000
  315. #define __FLAG_WRITING 0x2000
  316. #define __FLAG_FREEBUF 0x4000 /* free buffer after use */
  317. #define __FLAG_LARGEFILE 0x8000
  318. /**********************************************************************/
  319. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  320. extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize);
  321. extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize);
  322. extern int _cs_seek(void *cookie, __offmax_t *pos, int whence);
  323. extern int _cs_close(void *cookie);
  324. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  325. /**********************************************************************/
  326. #ifdef __STDIO_MBSTATE
  327. #define __COPY_MBSTATE(dest,src) ((dest)->mask = (src)->mask, (dest)->wc = (src)->wc)
  328. #define __INIT_MBSTATE(dest) ((dest)->mask = 0)
  329. #else
  330. #define __COPY_MBSTATE(dest,src)
  331. #define __INIT_MBSTATE(dest)
  332. #endif
  333. /**********************************************************************/
  334. /* TODO -- thread safety issues */
  335. #define __CLEARERR(stream) \
  336. ((stream)->modeflags &= ~(__FLAG_EOF|__FLAG_ERROR), (void)0)
  337. #define __FEOF(stream) ((stream)->modeflags & __FLAG_EOF)
  338. #define __FERROR(stream) ((stream)->modeflags & __FLAG_ERROR)
  339. #define __FEOF_OR_FERROR(stream) \
  340. ((stream)->modeflags & (__FLAG_EOF|__FLAG_ERROR))
  341. /* TODO: check this
  342. * If we want to implement the getc and putc macros, we need to take
  343. * into account wide streams. So... would need two additional variables
  344. * if we have wide streams (bufread and bufwrite), and one otherwise
  345. * (bufwrite). getc would be effective for FBF streams. It isn't for
  346. * LBF streams because other LBF streams need to be flushed. putc
  347. * thouch is only effective for FBF streams. Of course, to support
  348. * threads, we have to use functions.
  349. */
  350. #ifdef __STDIO_GETC_MACRO
  351. #define __GETC(stream) ( ((stream)->bufpos < (stream)->bufgetc) \
  352. ? (*(stream)->bufpos++) \
  353. : fgetc_unlocked(stream) )
  354. #else /* __STDIO_GETC_MACRO */
  355. #define __GETC(stream) fgetc_unlocked(stream)
  356. #endif /* __STDIO_GETC_MACRO */
  357. #ifdef __STDIO_PUTC_MACRO
  358. #define __PUTC(c, stream) ( ((stream)->bufpos < (stream)->bufputc) \
  359. ? (*(stream)->bufpos++) = (c) \
  360. : fputc_unlocked((c),(stream)) )
  361. #else /* __STDIO_PUTC_MACRO */
  362. #define __PUTC(c, stream) fputc_unlocked(c, stream);
  363. #endif /* __STDIO_PUTC_MACRO */
  364. #if 0
  365. /* TODO: disabled for now */
  366. /* Masking macros for the above _are_ allowed by the standard. */
  367. #define clearerr(stream) __CLEARERR(stream)
  368. #define feof(stream) __FEOF(stream)
  369. #define ferror(stream) __FERROR(stream)
  370. #endif
  371. #if 0
  372. /* TODO -- what about custom streams!!! */
  373. /* Only use the macro below if you know fp is a valid FILE for a valid fd. */
  374. #define __fileno(fp) ((fp)->filedes)
  375. #endif
  376. /**********************************************************************
  377. * PROTOTYPES OF INTERNAL FUNCTIONS
  378. **********************************************************************/
  379. extern FILE *_stdio_openlist;
  380. #ifdef __STDIO_THREADSAFE
  381. extern pthread_mutex_t _stdio_openlist_lock;
  382. extern void __stdio_init_mutex(pthread_mutex_t *m);
  383. #endif
  384. extern int _stdio_adjpos(FILE * __restrict stream, __offmax_t * pos);
  385. extern int _stdio_lseek(FILE *stream, __offmax_t *pos, int whence);
  386. /* TODO: beware of signals with _stdio_fwrite!!!! */
  387. extern size_t _stdio_fwrite(const unsigned char *buffer, size_t bytes,
  388. FILE *stream);
  389. extern size_t _stdio_fread(unsigned char *buffer, size_t bytes,
  390. FILE *stream);
  391. extern FILE *_stdio_fopen(const char * __restrict filename,
  392. const char * __restrict mode,
  393. FILE * __restrict stream, int filedes);
  394. extern FILE *_stdio_fsfopen(const char * __restrict filename,
  395. const char * __restrict mode,
  396. register FILE * __restrict stream);
  397. extern void _stdio_init(void);
  398. extern void _stdio_term(void);
  399. #ifndef NDEBUG
  400. extern void __stdio_validate_FILE(FILE *stream);
  401. #else
  402. #define __stdio_validate_FILE(stream) ((void)0)
  403. #endif
  404. #ifdef __STDIO_WIDE
  405. extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
  406. register FILE *__restrict stream);
  407. #endif
  408. /**********************************************************************
  409. * UTILITY functions
  410. **********************************************************************/
  411. #ifdef _STDIO_UTILITY
  412. #include <features.h>
  413. #include <limits.h>
  414. #include <stdint.h>
  415. #if INTMAX_MAX <= 2147483647L
  416. #define __UIM_BUFLEN 12 /* 10 digits + 1 nul + 1 sign */
  417. #elif INTMAX_MAX <= 9223372036854775807LL
  418. #define __UIM_BUFLEN 22 /* 20 digits + 1 nul + 1 sign */
  419. #else
  420. #error unknown number of digits for intmax_t!
  421. #endif
  422. #ifdef LLONG_MAX /* --------------- */
  423. #if LLONG_MAX <= 2147483647L
  424. #define __UIM_BUFLEN_LLONG 12 /* 10 digits + 1 nul + 1 sign */
  425. #elif LLONG_MAX <= 9223372036854775807LL
  426. #define __UIM_BUFLEN_LLONG 22 /* 20 digits + 1 nul + 1 sign */
  427. #else
  428. #error unknown number of digits for long long!
  429. #endif
  430. #endif /* ULLONG_MAX ----------------------------- */
  431. #if LONG_MAX <= 2147483647L
  432. #define __UIM_BUFLEN_LONG 12 /* 10 digits + 1 nul + 1 sign */
  433. #elif LONG_MAX <= 9223372036854775807LL
  434. #define __UIM_BUFLEN_LONG 22 /* 20 digits + 1 nul + 1 sign */
  435. #else
  436. #error unknown number of digits for long!
  437. #endif
  438. #if INT_MAX <= 32767
  439. #define __UIM_BUFLEN_INT 7 /* 10 digits + 1 nul + 1 sign */
  440. #elif INT_MAX <= 2147483647L
  441. #define __UIM_BUFLEN_INT 12 /* 10 digits + 1 nul + 1 sign */
  442. #else
  443. #error unknown number of digits for int!
  444. #endif
  445. typedef enum {
  446. __UIM_DECIMAL = 0,
  447. __UIM_GROUP = ',', /* Base 10 locale-dependent grouping. */
  448. __UIM_LOWER = 'a' - 10,
  449. __UIM_UPPER = 'A' - 10,
  450. } __UIM_CASE;
  451. /* Write a NULL-terminated list of "char *" args to file descriptor fd.
  452. * For an example of usage, see __assert.c.
  453. */
  454. extern void _stdio_fdout(int fd, ...);
  455. /* Convert the int val to a string in base abs(base). val is treated as
  456. * an unsigned ??? int type if base > 0, and signed if base < 0. This
  457. * is an internal function with _no_ error checking done unless assert()s
  458. * are enabled.
  459. *
  460. * Note: bufend is a pointer to the END of the buffer passed.
  461. * Call like this:
  462. * char buf[SIZE], *p;
  463. * p = _xltostr(buf + sizeof(buf) - 1, {unsigned int}, 10, __UIM_DECIMAL)
  464. * p = _xltostr(buf + sizeof(buf) - 1, {int}, -10, __UIM_DECIMAL)
  465. *
  466. * WARNING: If base > 10, case _must_be_ either __UIM_LOWER or __UIM_UPPER
  467. * for lower and upper case alphas respectively.
  468. * WARNING: If val is really a signed type, make sure base is negative!
  469. * Otherwise, you could overflow your buffer.
  470. */
  471. extern char *_uintmaxtostr(char * __restrict bufend, uintmax_t uval,
  472. int base, __UIM_CASE alphacase);
  473. /* TODO -- make this either a (possibly inline) function? */
  474. #ifndef __BCC__
  475. #define _int10tostr(bufend, intval) \
  476. _uintmaxtostr((bufend), (intval), -10, __UIM_DECIMAL)
  477. #else /* bcc doesn't do prototypes, we need to explicitly cast */
  478. #define _int10tostr(bufend, intval) \
  479. _uintmaxtostr((bufend), (uintmax_t)(intval), -10, __UIM_DECIMAL)
  480. #endif
  481. #define __BUFLEN_INT10TOSTR __UIM_BUFLEN_INT
  482. #endif /* _STDIO_UTILITY */
  483. /**********************************************************************/
  484. /* uClibc translations */
  485. /**********************************************************************/
  486. /* TODO: note done above.. typedef struct __stdio_file_struct _UC_FILE; */
  487. typedef __stdio_fpos_t _UC_fpos_t;
  488. #ifdef __STDIO_LARGE_FILES
  489. typedef __stdio_fpos64_t _UC_fpos64_t;
  490. #endif
  491. #define _UC_IOFBF _STDIO_IOFBF /* Fully buffered. */
  492. #define _UC_IOLBF _STDIO_IOLBF /* Line buffered. */
  493. #define _UC_IONBF _STDIO_IONBF /* No buffering. */
  494. #define _UC_BUFSIZ _STDIO_BUFSIZ