uClibc_stdio.h 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601
  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. #define __STDIO_SET_USER_LOCKING(STREAM) ((STREAM)->user_locking = 1)
  181. #else /* __STDIO_THREADSAFE */
  182. #define __STDIO_THREADLOCK(STREAM)
  183. #define __STDIO_THREADUNLOCK(STREAM)
  184. #define __STDIO_THREADTRYLOCK(STREAM)
  185. #define __STDIO_SET_USER_LOCKING(STREAM)
  186. #endif /* __STDIO_THREADSAFE */
  187. /* This file may eventually have two personalities:
  188. 1) core stuff (similar to glibc's libio.h)
  189. 2) extern inlines (for glibc's bits/stdio.h)
  190. Right now, only (1) is implemented. */
  191. #define _STDIO_IOFBF 0 /* Fully buffered. */
  192. #define _STDIO_IOLBF 1 /* Line buffered. */
  193. #define _STDIO_IONBF 2 /* No buffering. */
  194. typedef struct {
  195. __off_t __pos;
  196. #ifdef __STDIO_MBSTATE
  197. __mbstate_t __mbstate;
  198. #endif
  199. #ifdef __STDIO_WIDE
  200. int mblen_pending;
  201. #endif
  202. } __stdio_fpos_t;
  203. #ifdef __STDIO_LARGE_FILES
  204. typedef struct {
  205. __off64_t __pos;
  206. #ifdef __STDIO_MBSTATE
  207. __mbstate_t __mbstate;
  208. #endif
  209. #ifdef __STDIO_WIDE
  210. int mblen_pending;
  211. #endif
  212. } __stdio_fpos64_t;
  213. #endif
  214. /**********************************************************************/
  215. #ifdef __STDIO_LARGE_FILES
  216. typedef __off64_t __offmax_t; /* TODO -- rename this? */
  217. #else
  218. typedef __off_t __offmax_t; /* TODO -- rename this? */
  219. #endif
  220. /**********************************************************************/
  221. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  222. typedef __ssize_t __io_read_fn(void *cookie,
  223. char *buf, size_t bufsize);
  224. typedef __ssize_t __io_write_fn(void *cookie,
  225. const char *buf, size_t bufsize);
  226. /* NOTE: GLIBC difference!!! -- fopencookie seek function
  227. * For glibc, the type of pos is always (__off64_t *) but in our case
  228. * it is type (__off_t *) when the lib is built without large file support.
  229. */
  230. typedef int __io_seek_fn(void *cookie,
  231. __offmax_t *pos, int whence);
  232. typedef int __io_close_fn(void *cookie);
  233. typedef struct {
  234. __io_read_fn *read;
  235. __io_write_fn *write;
  236. __io_seek_fn *seek;
  237. __io_close_fn *close;
  238. } _IO_cookie_io_functions_t;
  239. #if defined(_LIBC) || defined(_GNU_SOURCE)
  240. typedef __io_read_fn cookie_read_function_t;
  241. typedef __io_write_fn cookie_write_function_t;
  242. typedef __io_seek_fn cookie_seek_function_t;
  243. typedef __io_close_fn cookie_close_function_t;
  244. typedef _IO_cookie_io_functions_t cookie_io_functions_t;
  245. #endif /* _GNU_SOURCE */
  246. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  247. /*
  248. * ungot scheme:
  249. * 0 0 none
  250. * 0 1 one user (unused ungot is 1) or one scanf (unused ungot is 0)
  251. * 1 0 must be scanf[0] and user[1]
  252. * 1 1 illegal -- could be used to signal safe for setbuf
  253. * but if used, need to fix _stdio_adjpos at least!
  254. */
  255. #ifdef __UCLIBC__
  256. #define __stdio_file_struct _UC_FILE
  257. #endif
  258. struct __stdio_file_struct {
  259. unsigned short modeflags;
  260. /* There could be a hole here, but modeflags is used most.*/
  261. #ifdef __STDIO_WIDE
  262. /* TODO - ungot_width could be combined with ungot. But what about hole? */
  263. unsigned char ungot_width[2]; /* 0 is current (building) char, 1 is scanf */
  264. wchar_t ungot[2];
  265. #else /* __STDIO_WIDE */
  266. unsigned char ungot[2];
  267. #endif /* __STDIO_WIDE */
  268. int filedes;
  269. #if defined(__STDIO_BUFFERS) || defined(__STDIO_GLIBC_CUSTOM_STREAMS)
  270. struct __stdio_file_struct *nextopen;
  271. #endif /* defined(__STDIO_BUFFERS) || defined(__STDIO_GLIBC_CUSTOM_STREAMS) */
  272. #ifdef __STDIO_BUFFERS
  273. unsigned char *bufstart; /* pointer to buffer */
  274. unsigned char *bufend; /* pointer to 1 past end of buffer */
  275. unsigned char *bufpos;
  276. unsigned char *bufread; /* pointer to 1 past last buffered read char. */
  277. #ifdef __STDIO_GETC_MACRO
  278. unsigned char *bufgetc; /* 1 past last readable by getc */
  279. #endif /* __STDIO_GETC_MACRO */
  280. #ifdef __STDIO_PUTC_MACRO
  281. unsigned char *bufputc; /* 1 past last writeable by putc */
  282. #endif /* __STDIO_PUTC_MACRO */
  283. #endif /* __STDIO_BUFFERS */
  284. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  285. void *cookie;
  286. _IO_cookie_io_functions_t gcs;
  287. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  288. #ifdef __STDIO_MBSTATE
  289. __mbstate_t state;
  290. #endif
  291. #ifdef __STDIO_THREADSAFE
  292. int user_locking;
  293. pthread_mutex_t lock;
  294. #endif
  295. /* Everything after this is unimplemented... and may be trashed. */
  296. #if __STDIO_BUILTIN_BUF_SIZE > 0
  297. unsigned char builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
  298. #endif /* __STDIO_BUILTIN_BUF_SIZE > 0 */
  299. };
  300. /***********************************************************************/
  301. #define __MASK_UNGOT (0x0002|0x0001)
  302. #define __MASK_UNGOT1 0x0001
  303. #define __MASK_UNGOT2 0x0002
  304. #define __FLAG_EOF 0x0004 /* EOF reached? */
  305. #define __FLAG_ERROR 0x0008 /* stream in error state? */
  306. #define __FLAG_WRITEONLY 0x0010 /* unreadable */
  307. #define __FLAG_READONLY 0x0020 /* unwriteable */
  308. #define __FLAG_FREEFILE 0x0040 /* free FILE struct after use */
  309. #define __FLAG_NARROW 0x0080
  310. #define __FLAG_FBF 0 /* convenience value */
  311. #define __FLAG_LBF 0x0100
  312. #define __FLAG_NBF 0x0200
  313. #define __MASK_BUFMODE 0x0300
  314. #define __FLAG_APPEND 0x0400
  315. #define __FLAG_WIDE 0x0800
  316. #define __FLAG_READING 0x1000
  317. #define __FLAG_WRITING 0x2000
  318. #define __FLAG_FREEBUF 0x4000 /* free buffer after use */
  319. #define __FLAG_LARGEFILE 0x8000
  320. /**********************************************************************/
  321. #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
  322. extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize);
  323. extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize);
  324. extern int _cs_seek(void *cookie, __offmax_t *pos, int whence);
  325. extern int _cs_close(void *cookie);
  326. #endif /* __STDIO_GLIBC_CUSTOM_STREAMS */
  327. /**********************************************************************/
  328. #ifdef __STDIO_MBSTATE
  329. #define __COPY_MBSTATE(dest,src) ((dest)->mask = (src)->mask, (dest)->wc = (src)->wc)
  330. #define __INIT_MBSTATE(dest) ((dest)->mask = 0)
  331. #else
  332. #define __COPY_MBSTATE(dest,src)
  333. #define __INIT_MBSTATE(dest)
  334. #endif
  335. /**********************************************************************/
  336. /* TODO -- thread safety issues */
  337. #define __CLEARERR(stream) \
  338. ((stream)->modeflags &= ~(__FLAG_EOF|__FLAG_ERROR), (void)0)
  339. #define __FEOF(stream) ((stream)->modeflags & __FLAG_EOF)
  340. #define __FERROR(stream) ((stream)->modeflags & __FLAG_ERROR)
  341. #define __FEOF_OR_FERROR(stream) \
  342. ((stream)->modeflags & (__FLAG_EOF|__FLAG_ERROR))
  343. /* TODO: check this
  344. * If we want to implement the getc and putc macros, we need to take
  345. * into account wide streams. So... would need two additional variables
  346. * if we have wide streams (bufread and bufwrite), and one otherwise
  347. * (bufwrite). getc would be effective for FBF streams. It isn't for
  348. * LBF streams because other LBF streams need to be flushed. putc
  349. * thouch is only effective for FBF streams. Of course, to support
  350. * threads, we have to use functions.
  351. */
  352. #ifdef __STDIO_GETC_MACRO
  353. #define __GETC(stream) ( ((stream)->bufpos < (stream)->bufgetc) \
  354. ? (*(stream)->bufpos++) \
  355. : fgetc_unlocked(stream) )
  356. #else /* __STDIO_GETC_MACRO */
  357. #define __GETC(stream) fgetc_unlocked(stream)
  358. #endif /* __STDIO_GETC_MACRO */
  359. #ifdef __STDIO_PUTC_MACRO
  360. #define __PUTC(c, stream) ( ((stream)->bufpos < (stream)->bufputc) \
  361. ? (*(stream)->bufpos++) = (c) \
  362. : fputc_unlocked((c),(stream)) )
  363. #else /* __STDIO_PUTC_MACRO */
  364. #define __PUTC(c, stream) fputc_unlocked(c, stream)
  365. #endif /* __STDIO_PUTC_MACRO */
  366. #if 0
  367. /* TODO: disabled for now */
  368. /* Masking macros for the above _are_ allowed by the standard. */
  369. #define clearerr(stream) __CLEARERR(stream)
  370. #define feof(stream) __FEOF(stream)
  371. #define ferror(stream) __FERROR(stream)
  372. #endif
  373. #if 0
  374. /* TODO -- what about custom streams!!! */
  375. /* Only use the macro below if you know fp is a valid FILE for a valid fd. */
  376. #define __fileno(fp) ((fp)->filedes)
  377. #endif
  378. /**********************************************************************
  379. * PROTOTYPES OF INTERNAL FUNCTIONS
  380. **********************************************************************/
  381. extern FILE *_stdio_openlist;
  382. #ifdef __STDIO_THREADSAFE
  383. extern pthread_mutex_t _stdio_openlist_lock;
  384. extern void __stdio_init_mutex(pthread_mutex_t *m);
  385. #endif
  386. extern int _stdio_adjpos(FILE * __restrict stream, __offmax_t * pos);
  387. extern int _stdio_lseek(FILE *stream, __offmax_t *pos, int whence);
  388. /* TODO: beware of signals with _stdio_fwrite!!!! */
  389. extern size_t _stdio_fwrite(const unsigned char *buffer, size_t bytes,
  390. FILE *stream);
  391. extern size_t _stdio_fread(unsigned char *buffer, size_t bytes,
  392. FILE *stream);
  393. extern FILE *_stdio_fopen(const char * __restrict filename,
  394. const char * __restrict mode,
  395. FILE * __restrict stream, int filedes);
  396. extern FILE *_stdio_fsfopen(const char * __restrict filename,
  397. const char * __restrict mode,
  398. register FILE * __restrict stream);
  399. extern void _stdio_init(void);
  400. extern void _stdio_term(void);
  401. #ifndef NDEBUG
  402. extern void __stdio_validate_FILE(FILE *stream);
  403. #else
  404. #define __stdio_validate_FILE(stream) ((void)0)
  405. #endif
  406. #ifdef __STDIO_WIDE
  407. extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
  408. register FILE *__restrict stream);
  409. #endif
  410. /**********************************************************************
  411. * UTILITY functions
  412. **********************************************************************/
  413. #ifdef _STDIO_UTILITY
  414. #include <features.h>
  415. #include <limits.h>
  416. #include <stdint.h>
  417. #if INTMAX_MAX <= 2147483647L
  418. #define __UIM_BUFLEN 12 /* 10 digits + 1 nul + 1 sign */
  419. #elif INTMAX_MAX <= 9223372036854775807LL
  420. #define __UIM_BUFLEN 22 /* 20 digits + 1 nul + 1 sign */
  421. #else
  422. #error unknown number of digits for intmax_t!
  423. #endif
  424. #ifdef LLONG_MAX /* --------------- */
  425. #if LLONG_MAX <= 2147483647L
  426. #define __UIM_BUFLEN_LLONG 12 /* 10 digits + 1 nul + 1 sign */
  427. #elif LLONG_MAX <= 9223372036854775807LL
  428. #define __UIM_BUFLEN_LLONG 22 /* 20 digits + 1 nul + 1 sign */
  429. #else
  430. #error unknown number of digits for long long!
  431. #endif
  432. #endif /* ULLONG_MAX ----------------------------- */
  433. #if LONG_MAX <= 2147483647L
  434. #define __UIM_BUFLEN_LONG 12 /* 10 digits + 1 nul + 1 sign */
  435. #elif LONG_MAX <= 9223372036854775807LL
  436. #define __UIM_BUFLEN_LONG 22 /* 20 digits + 1 nul + 1 sign */
  437. #else
  438. #error unknown number of digits for long!
  439. #endif
  440. #if INT_MAX <= 32767
  441. #define __UIM_BUFLEN_INT 7 /* 10 digits + 1 nul + 1 sign */
  442. #elif INT_MAX <= 2147483647L
  443. #define __UIM_BUFLEN_INT 12 /* 10 digits + 1 nul + 1 sign */
  444. #else
  445. #error unknown number of digits for int!
  446. #endif
  447. typedef enum {
  448. __UIM_DECIMAL = 0,
  449. __UIM_GROUP = ',', /* Base 10 locale-dependent grouping. */
  450. __UIM_LOWER = 'a' - 10,
  451. __UIM_UPPER = 'A' - 10,
  452. } __UIM_CASE;
  453. /* Write a NULL-terminated list of "char *" args to file descriptor fd.
  454. * For an example of usage, see __assert.c.
  455. */
  456. extern void _stdio_fdout(int fd, ...);
  457. /* Convert the int val to a string in base abs(base). val is treated as
  458. * an unsigned ??? int type if base > 0, and signed if base < 0. This
  459. * is an internal function with _no_ error checking done unless assert()s
  460. * are enabled.
  461. *
  462. * Note: bufend is a pointer to the END of the buffer passed.
  463. * Call like this:
  464. * char buf[SIZE], *p;
  465. * p = _xltostr(buf + sizeof(buf) - 1, {unsigned int}, 10, __UIM_DECIMAL)
  466. * p = _xltostr(buf + sizeof(buf) - 1, {int}, -10, __UIM_DECIMAL)
  467. *
  468. * WARNING: If base > 10, case _must_be_ either __UIM_LOWER or __UIM_UPPER
  469. * for lower and upper case alphas respectively.
  470. * WARNING: If val is really a signed type, make sure base is negative!
  471. * Otherwise, you could overflow your buffer.
  472. */
  473. extern char *_uintmaxtostr(char * __restrict bufend, uintmax_t uval,
  474. int base, __UIM_CASE alphacase);
  475. /* TODO -- make this either a (possibly inline) function? */
  476. #ifndef __BCC__
  477. #define _int10tostr(bufend, intval) \
  478. _uintmaxtostr((bufend), (intval), -10, __UIM_DECIMAL)
  479. #else /* bcc doesn't do prototypes, we need to explicitly cast */
  480. #define _int10tostr(bufend, intval) \
  481. _uintmaxtostr((bufend), (uintmax_t)(intval), -10, __UIM_DECIMAL)
  482. #endif
  483. #define __BUFLEN_INT10TOSTR __UIM_BUFLEN_INT
  484. #endif /* _STDIO_UTILITY */
  485. /**********************************************************************/
  486. /* uClibc translations */
  487. /**********************************************************************/
  488. /* TODO: note done above.. typedef struct __stdio_file_struct _UC_FILE; */
  489. typedef __stdio_fpos_t _UC_fpos_t;
  490. #ifdef __STDIO_LARGE_FILES
  491. typedef __stdio_fpos64_t _UC_fpos64_t;
  492. #endif
  493. #define _UC_IOFBF _STDIO_IOFBF /* Fully buffered. */
  494. #define _UC_IOLBF _STDIO_IOLBF /* Line buffered. */
  495. #define _UC_IONBF _STDIO_IONBF /* No buffering. */
  496. #define _UC_BUFSIZ _STDIO_BUFSIZ