123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601 |
- #ifndef _STDIO_H
- #error Always include <stdio.h> rather than <bits/uClibc_stdio.h>
- #endif
- #ifdef __UCLIBC__
- #ifdef __UCLIBC_HAS_THREADS__
- #define __STDIO_THREADSAFE
- #endif
- #ifdef __UCLIBC_HAS_LFS__
- #define __STDIO_LARGE_FILES
- #endif
- #ifdef __UCLIBC_HAS_WCHAR__
- #define __STDIO_WIDE
- #endif
- #define __STDIO_BUFFERS
- #if defined(__UCLIBC_HAS_STDIO_BUFSIZ_NONE__)
- #define _STDIO_BUFSIZ 256
- #undef __STDIO_BUFFERS
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_256__)
- #define _STDIO_BUFSIZ 256
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_512__)
- #define _STDIO_BUFSIZ 512
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_1024__)
- #define _STDIO_BUFSIZ 1024
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_2048__)
- #define _STDIO_BUFSIZ 2048
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_4096__)
- #define _STDIO_BUFSIZ 4096
- #elif defined(__UCLIBC_HAS_STDIO_BUFSIZ_8192__)
- #define _STDIO_BUFSIZ 8192
- #else
- #error config seems to be out of sync regarding bufsiz options
- #endif
- #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
- #define __STDIO_GETC_MACRO
- #endif
- #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
- #define __STDIO_PUTC_MACRO
- #endif
- #ifdef __UCLIBC_HAS_STDIO_AUTO_RW_TRANSITION__
- #define __STDIO_AUTO_RW_TRANSITION
- #endif
- #ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
- #define __STDIO_FOPEN_LARGEFILE_MODE
- #endif
- #ifdef __UCLIBC_HAS_FOPEN_LARGEFILE_MODE__
- #define __STDIO_FOPEN_EXCLUSIVE_MODE
- #endif
- #ifdef __UCLIBC_HAS_PRINTF_M_SPEC__
- #define __STDIO_PRINTF_M_SUPPORT
- #endif
- #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- #define __STDIO_GLIBC_CUSTOM_STREAMS
- #endif
- #ifdef __UCLIBC_HAS_STDIO_BUFSIZ_NONE__
- #define _STDIO_BUILTIN_BUF_SIZE 0
- #else
- #if defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_NONE__)
- #define _STDIO_BUILTIN_BUF_SIZE 0
- #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_4__)
- #define _STDIO_BUILTIN_BUF_SIZE 4
- #elif defined(__UCLIBC_HAS_STDIO_BUILTIN_BUFFER_8__)
- #define _STDIO_BUILTIN_BUF_SIZE 8
- #else
- #error config seems to be out of sync regarding builtin buffer size
- #endif
- #endif
- #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_PRINTF__
- #define __STDIO_GLIBC_CUSTOM_PRINTF
- #endif
- #ifdef _LIBC
- #ifdef __UCLIBC_HAS_LFS__
- #undef __USE_LARGEFILE
- #undef __USE_LARGEFILE64
- #undef __USE_FILE_OFFSET64
- #define __USE_LARGEFILE64 1
- #endif
- #else
- #ifndef __UCLIBC_HAS_LFS__
- #if defined(__LARGEFILE64_SOURCE) || defined(__USE_LARGEFILE64) \
- || defined(__USE_FILE_OFFSET64)
- #error Sorry... uClibc was built without large file support!
- #endif
- #endif
- #endif
- #endif
- #ifdef __STDIO_WIDE
- #define __need_wchar_t
- #include <stddef.h>
- #define __STDIO_MBSTATE
- #define __need_mbstate_t
- #include <wchar.h>
- #endif
- #ifndef __STDIO_BUFFERS
- #undef __STDIO_GETC_MACRO
- #undef __STDIO_PUTC_MACRO
- #endif
- #ifdef __BCC__
- #undef __STDIO_LARGE_FILES
- #endif
- #ifndef __STDIO_LARGE_FILES
- #undef __STDIO_FOPEN_LARGEFILE_MODE
- #endif
- #ifdef __STDIO_THREADSAFE
- #include <bits/pthreadtypes.h>
- #define __STDIO_THREADLOCK(STREAM) \
- if ((STREAM)->user_locking == 0) { \
- __pthread_mutex_lock(&(STREAM)->lock); \
- }
- #define __STDIO_THREADUNLOCK(STREAM) \
- if ((STREAM)->user_locking == 0) { \
- __pthread_mutex_unlock(&(STREAM)->lock); \
- }
- #define __STDIO_THREADTRYLOCK(STREAM) \
- if ((STREAM)->user_locking == 0) { \
- __pthread_mutex_trylock(&(STREAM)->lock); \
- }
- #define __STDIO_SET_USER_LOCKING(STREAM) ((STREAM)->user_locking = 1)
- #else
- #define __STDIO_THREADLOCK(STREAM)
- #define __STDIO_THREADUNLOCK(STREAM)
- #define __STDIO_THREADTRYLOCK(STREAM)
- #define __STDIO_SET_USER_LOCKING(STREAM)
- #endif
- #define _STDIO_IOFBF 0
- #define _STDIO_IOLBF 1
- #define _STDIO_IONBF 2
- typedef struct {
- __off_t __pos;
- #ifdef __STDIO_MBSTATE
- __mbstate_t __mbstate;
- #endif
- #ifdef __STDIO_WIDE
- int mblen_pending;
- #endif
- } __stdio_fpos_t;
- #ifdef __STDIO_LARGE_FILES
- typedef struct {
- __off64_t __pos;
- #ifdef __STDIO_MBSTATE
- __mbstate_t __mbstate;
- #endif
- #ifdef __STDIO_WIDE
- int mblen_pending;
- #endif
- } __stdio_fpos64_t;
- #endif
- #ifdef __STDIO_LARGE_FILES
- typedef __off64_t __offmax_t;
- #else
- typedef __off_t __offmax_t;
- #endif
- #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
- typedef __ssize_t __io_read_fn(void *cookie,
- char *buf, size_t bufsize);
- typedef __ssize_t __io_write_fn(void *cookie,
- const char *buf, size_t bufsize);
- typedef int __io_seek_fn(void *cookie,
- __offmax_t *pos, int whence);
- typedef int __io_close_fn(void *cookie);
- typedef struct {
- __io_read_fn *read;
- __io_write_fn *write;
- __io_seek_fn *seek;
- __io_close_fn *close;
- } _IO_cookie_io_functions_t;
- #if defined(_LIBC) || defined(_GNU_SOURCE)
- typedef __io_read_fn cookie_read_function_t;
- typedef __io_write_fn cookie_write_function_t;
- typedef __io_seek_fn cookie_seek_function_t;
- typedef __io_close_fn cookie_close_function_t;
- typedef _IO_cookie_io_functions_t cookie_io_functions_t;
- #endif
- #endif
- #ifdef __UCLIBC__
- #define __stdio_file_struct _UC_FILE
- #endif
- struct __stdio_file_struct {
- unsigned short modeflags;
-
- #ifdef __STDIO_WIDE
-
- unsigned char ungot_width[2];
- wchar_t ungot[2];
- #else
- unsigned char ungot[2];
- #endif
- int filedes;
- #if defined(__STDIO_BUFFERS) || defined(__STDIO_GLIBC_CUSTOM_STREAMS)
- struct __stdio_file_struct *nextopen;
- #endif
- #ifdef __STDIO_BUFFERS
- unsigned char *bufstart;
- unsigned char *bufend;
- unsigned char *bufpos;
- unsigned char *bufread;
- #ifdef __STDIO_GETC_MACRO
- unsigned char *bufgetc;
- #endif
- #ifdef __STDIO_PUTC_MACRO
- unsigned char *bufputc;
- #endif
- #endif
- #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
- void *cookie;
- _IO_cookie_io_functions_t gcs;
- #endif
- #ifdef __STDIO_MBSTATE
- __mbstate_t state;
- #endif
- #ifdef __STDIO_THREADSAFE
- int user_locking;
- pthread_mutex_t lock;
- #endif
- #if __STDIO_BUILTIN_BUF_SIZE > 0
- unsigned char builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
- #endif
- };
- #define __MASK_UNGOT (0x0002|0x0001)
- #define __MASK_UNGOT1 0x0001
- #define __MASK_UNGOT2 0x0002
- #define __FLAG_EOF 0x0004
- #define __FLAG_ERROR 0x0008
- #define __FLAG_WRITEONLY 0x0010
- #define __FLAG_READONLY 0x0020
- #define __FLAG_FREEFILE 0x0040
- #define __FLAG_NARROW 0x0080
- #define __FLAG_FBF 0
- #define __FLAG_LBF 0x0100
- #define __FLAG_NBF 0x0200
- #define __MASK_BUFMODE 0x0300
- #define __FLAG_APPEND 0x0400
- #define __FLAG_WIDE 0x0800
- #define __FLAG_READING 0x1000
- #define __FLAG_WRITING 0x2000
- #define __FLAG_FREEBUF 0x4000
- #define __FLAG_LARGEFILE 0x8000
- #ifdef __STDIO_GLIBC_CUSTOM_STREAMS
- extern __ssize_t _cs_read(void *cookie, char *buf, size_t bufsize);
- extern __ssize_t _cs_write(void *cookie, const char *buf, size_t bufsize);
- extern int _cs_seek(void *cookie, __offmax_t *pos, int whence);
- extern int _cs_close(void *cookie);
- #endif
- #ifdef __STDIO_MBSTATE
- #define __COPY_MBSTATE(dest,src) ((dest)->mask = (src)->mask, (dest)->wc = (src)->wc)
- #define __INIT_MBSTATE(dest) ((dest)->mask = 0)
- #else
- #define __COPY_MBSTATE(dest,src)
- #define __INIT_MBSTATE(dest)
- #endif
- #define __CLEARERR(stream) \
- ((stream)->modeflags &= ~(__FLAG_EOF|__FLAG_ERROR), (void)0)
- #define __FEOF(stream) ((stream)->modeflags & __FLAG_EOF)
- #define __FERROR(stream) ((stream)->modeflags & __FLAG_ERROR)
- #define __FEOF_OR_FERROR(stream) \
- ((stream)->modeflags & (__FLAG_EOF|__FLAG_ERROR))
- #ifdef __STDIO_GETC_MACRO
- #define __GETC(stream) ( ((stream)->bufpos < (stream)->bufgetc) \
- ? (*(stream)->bufpos++) \
- : fgetc_unlocked(stream) )
- #else
- #define __GETC(stream) fgetc_unlocked(stream)
- #endif
- #ifdef __STDIO_PUTC_MACRO
- #define __PUTC(c, stream) ( ((stream)->bufpos < (stream)->bufputc) \
- ? (*(stream)->bufpos++) = (c) \
- : fputc_unlocked((c),(stream)) )
- #else
- #define __PUTC(c, stream) fputc_unlocked(c, stream)
- #endif
- #if 0
- #define clearerr(stream) __CLEARERR(stream)
- #define feof(stream) __FEOF(stream)
- #define ferror(stream) __FERROR(stream)
- #endif
- #if 0
- #define __fileno(fp) ((fp)->filedes)
- #endif
- extern FILE *_stdio_openlist;
- #ifdef __STDIO_THREADSAFE
- extern pthread_mutex_t _stdio_openlist_lock;
- extern void __stdio_init_mutex(pthread_mutex_t *m);
- #endif
- extern int _stdio_adjpos(FILE * __restrict stream, __offmax_t * pos);
- extern int _stdio_lseek(FILE *stream, __offmax_t *pos, int whence);
- extern size_t _stdio_fwrite(const unsigned char *buffer, size_t bytes,
- FILE *stream);
- extern size_t _stdio_fread(unsigned char *buffer, size_t bytes,
- FILE *stream);
- extern FILE *_stdio_fopen(const char * __restrict filename,
- const char * __restrict mode,
- FILE * __restrict stream, int filedes);
- extern FILE *_stdio_fsfopen(const char * __restrict filename,
- const char * __restrict mode,
- register FILE * __restrict stream);
- extern void _stdio_init(void);
- extern void _stdio_term(void);
- #ifndef NDEBUG
- extern void __stdio_validate_FILE(FILE *stream);
- #else
- #define __stdio_validate_FILE(stream) ((void)0)
- #endif
- #ifdef __STDIO_WIDE
- extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n,
- register FILE *__restrict stream);
- #endif
- #ifdef _STDIO_UTILITY
- #include <features.h>
- #include <limits.h>
- #include <stdint.h>
- #if INTMAX_MAX <= 2147483647L
- #define __UIM_BUFLEN 12
- #elif INTMAX_MAX <= 9223372036854775807LL
- #define __UIM_BUFLEN 22
- #else
- #error unknown number of digits for intmax_t!
- #endif
- #ifdef LLONG_MAX
- #if LLONG_MAX <= 2147483647L
- #define __UIM_BUFLEN_LLONG 12
- #elif LLONG_MAX <= 9223372036854775807LL
- #define __UIM_BUFLEN_LLONG 22
- #else
- #error unknown number of digits for long long!
- #endif
- #endif
- #if LONG_MAX <= 2147483647L
- #define __UIM_BUFLEN_LONG 12
- #elif LONG_MAX <= 9223372036854775807LL
- #define __UIM_BUFLEN_LONG 22
- #else
- #error unknown number of digits for long!
- #endif
- #if INT_MAX <= 32767
- #define __UIM_BUFLEN_INT 7
- #elif INT_MAX <= 2147483647L
- #define __UIM_BUFLEN_INT 12
- #else
- #error unknown number of digits for int!
- #endif
- typedef enum {
- __UIM_DECIMAL = 0,
- __UIM_GROUP = ',',
- __UIM_LOWER = 'a' - 10,
- __UIM_UPPER = 'A' - 10,
- } __UIM_CASE;
- extern void _stdio_fdout(int fd, ...);
- extern char *_uintmaxtostr(char * __restrict bufend, uintmax_t uval,
- int base, __UIM_CASE alphacase);
- #ifndef __BCC__
- #define _int10tostr(bufend, intval) \
- _uintmaxtostr((bufend), (intval), -10, __UIM_DECIMAL)
- #else
- #define _int10tostr(bufend, intval) \
- _uintmaxtostr((bufend), (uintmax_t)(intval), -10, __UIM_DECIMAL)
- #endif
- #define __BUFLEN_INT10TOSTR __UIM_BUFLEN_INT
- #endif
- typedef __stdio_fpos_t _UC_fpos_t;
- #ifdef __STDIO_LARGE_FILES
- typedef __stdio_fpos64_t _UC_fpos64_t;
- #endif
- #define _UC_IOFBF _STDIO_IOFBF
- #define _UC_IOLBF _STDIO_IOLBF
- #define _UC_IONBF _STDIO_IONBF
- #define _UC_BUFSIZ _STDIO_BUFSIZ
|