123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501 |
- #ifndef _STDIO_H
- #error Always include <stdio.h> rather than <bits/uClibc_stdio.h>
- #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_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
- #if defined(__STDIO_BUFFERS) || defined(__UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__) || defined(__UCLIBC_HAS_THREADS__)
- #define __STDIO_HAS_OPENLIST 1
- #else
- #undef __STDIO_HAS_OPENLIST
- #endif
- #ifdef __UCLIBC_HAS_WCHAR__
- #define __need_wchar_t
- #include <stddef.h>
- #define __STDIO_MBSTATE
- #define __need_mbstate_t
- #include <wchar.h>
- #endif
- #ifdef __UCLIBC_HAS_STDIO_GETC_MACRO__
- #define __STDIO_GETC_MACRO
- #endif
- #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__
- #define __STDIO_PUTC_MACRO
- #endif
- #include <bits/uClibc_mutex.h>
- #define __STDIO_AUTO_THREADLOCK_VAR \
- __UCLIBC_MUTEX_AUTO_LOCK_VAR(__infunc_user_locking)
- #define __STDIO_AUTO_THREADLOCK(__stream) \
- __UCLIBC_IO_MUTEX_AUTO_LOCK((__stream)->__lock, __infunc_user_locking, \
- (__stream)->__user_locking)
- #define __STDIO_AUTO_THREADUNLOCK(__stream) \
- __UCLIBC_IO_MUTEX_AUTO_UNLOCK((__stream)->__lock, __infunc_user_locking)
- #define __STDIO_ALWAYS_THREADLOCK(__stream) \
- __UCLIBC_IO_MUTEX_LOCK((__stream)->__lock)
- #define __STDIO_ALWAYS_THREADUNLOCK(__stream) \
- __UCLIBC_IO_MUTEX_UNLOCK((__stream)->__lock)
- #define __STDIO_ALWAYS_THREADLOCK_CANCEL_UNSAFE(__stream) \
- __UCLIBC_IO_MUTEX_LOCK_CANCEL_UNSAFE((__stream)->__lock)
- #define __STDIO_ALWAYS_THREADTRYLOCK_CANCEL_UNSAFE(__stream) \
- __UCLIBC_IO_MUTEX_TRYLOCK_CANCEL_UNSAFE((__stream)->__lock)
- #define __STDIO_ALWAYS_THREADUNLOCK_CANCEL_UNSAFE(__stream) \
- __UCLIBC_IO_MUTEX_UNLOCK_CANCEL_UNSAFE((__stream)->__lock)
- #ifdef __UCLIBC_HAS_THREADS__
- #define __STDIO_SET_USER_LOCKING(__stream) ((__stream)->__user_locking = 1)
- #else
- #define __STDIO_SET_USER_LOCKING(__stream) ((void)0)
- #endif
- #ifdef __UCLIBC_HAS_THREADS__
- #ifdef __USE_STDIO_FUTEXES__
- #define STDIO_INIT_MUTEX(M) _IO_lock_init(M)
- #else
- #define STDIO_INIT_MUTEX(M) __stdio_init_mutex(& M)
- #endif
- #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 __UCLIBC_HAS_WCHAR__
- int __mblen_pending;
- #endif
- } __STDIO_fpos_t;
- #ifdef __UCLIBC_HAS_LFS__
- typedef struct {
- __off64_t __pos;
- #ifdef __STDIO_MBSTATE
- __mbstate_t __mbstate;
- #endif
- #ifdef __UCLIBC_HAS_WCHAR__
- int __mblen_pending;
- #endif
- } __STDIO_fpos64_t;
- #endif
- #ifdef __UCLIBC_HAS_LFS__
- typedef __off64_t __offmax_t;
- #else
- typedef __off_t __offmax_t;
- #endif
- #ifdef __UCLIBC_HAS_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
- struct __STDIO_FILE_STRUCT {
- unsigned short __modeflags;
-
- #ifdef __UCLIBC_HAS_WCHAR__
- unsigned char __ungot_width[2];
-
-
- #else
- unsigned char __ungot[2];
- #endif
- int __filedes;
- #ifdef __STDIO_BUFFERS
- unsigned char *__bufstart;
- unsigned char *__bufend;
- unsigned char *__bufpos;
- unsigned char *__bufread;
- #ifdef __STDIO_GETC_MACRO
- unsigned char *__bufgetc_u;
- #endif
- #ifdef __STDIO_PUTC_MACRO
- unsigned char *__bufputc_u;
- #endif
- #endif
- #ifdef __STDIO_HAS_OPENLIST
- struct __STDIO_FILE_STRUCT *__nextopen;
- #endif
- #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__
- void *__cookie;
- _IO_cookie_io_functions_t __gcs;
- #endif
- #ifdef __UCLIBC_HAS_WCHAR__
- wchar_t __ungot[2];
- #endif
- #ifdef __STDIO_MBSTATE
- __mbstate_t __state;
- #endif
- #ifdef __UCLIBC_HAS_XLOCALE__
- void *__unused;
- #endif
- #ifdef __UCLIBC_HAS_THREADS__
- int __user_locking;
- __UCLIBC_IO_MUTEX(__lock);
- #endif
- #if __STDIO_BUILTIN_BUF_SIZE > 0
- unsigned char __builtinbuf[__STDIO_BUILTIN_BUF_SIZE];
- #endif
- };
- #define __MASK_READING 0x0003U
- #define __FLAG_READING 0x0001U
- #define __FLAG_UNGOT 0x0002U
- #define __FLAG_EOF 0x0004U
- #define __FLAG_ERROR 0x0008U
- #define __FLAG_WRITEONLY 0x0010U
- #define __FLAG_READONLY 0x0020U
- #define __FLAG_WRITING 0x0040U
- #define __FLAG_NARROW 0x0080U
- #define __FLAG_FBF 0x0000U
- #define __FLAG_LBF 0x0100U
- #define __FLAG_NBF 0x0200U
- #define __MASK_BUFMODE 0x0300U
- #define __FLAG_APPEND 0x0400U
- #define __FLAG_WIDE 0x0800U
- #define __FLAG_FREEFILE 0x2000U
- #define __FLAG_FREEBUF 0x4000U
- #define __FLAG_LARGEFILE 0x8000U
- #define __FLAG_FAILED_FREOPEN __FLAG_LARGEFILE
- #if defined _LIBC && (defined IS_IN_libc || defined NOT_IN_libc)
- extern void _stdio_init(void) attribute_hidden;
- extern void _stdio_term(void) attribute_hidden;
- #ifdef __STDIO_HAS_OPENLIST
- extern struct __STDIO_FILE_STRUCT *_stdio_openlist;
- #ifdef __UCLIBC_HAS_THREADS__
- __UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_add_lock)
- # ifndef __UCLIBC_HAS_THREADS_NATIVE__
- attribute_hidden
- # endif
- ;
- #ifdef __STDIO_BUFFERS
- __UCLIBC_IO_MUTEX_EXTERN(_stdio_openlist_del_lock)
- # ifndef __UCLIBC_HAS_THREADS_NATIVE__
- attribute_hidden
- # endif
- ;
- #endif
- extern int _stdio_user_locking;
- #endif
- #endif
- #endif
- #define __CLEARERR_UNLOCKED(__stream) \
- ((void)((__stream)->__modeflags &= ~(__FLAG_EOF|__FLAG_ERROR)))
- #define __FEOF_UNLOCKED(__stream) ((__stream)->__modeflags & __FLAG_EOF)
- #define __FERROR_UNLOCKED(__stream) ((__stream)->__modeflags & __FLAG_ERROR)
- #ifdef __UCLIBC_HAS_THREADS__
- # define __CLEARERR(__stream) (clearerr)(__stream)
- # define __FERROR(__stream) (ferror)(__stream)
- # define __FEOF(__stream) (feof)(__stream)
- #else
- # define __CLEARERR(__stream) __CLEARERR_UNLOCKED(__stream)
- # define __FERROR(__stream) __FERROR_UNLOCKED(__stream)
- # define __FEOF(__stream) __FEOF_UNLOCKED(__stream)
- #endif
- extern int __fgetc_unlocked(FILE *__stream);
- libc_hidden_proto(__fgetc_unlocked)
- extern int __fputc_unlocked(int __c, FILE *__stream);
- libc_hidden_proto(__fputc_unlocked)
- #define __FGETC_UNLOCKED(__stream) (__fgetc_unlocked)((__stream))
- #define __FGETC(__stream) (fgetc)((__stream))
- #define __GETC_UNLOCKED_MACRO(__stream) (__fgetc_unlocked)((__stream))
- #define __GETC_UNLOCKED(__stream) (__fgetc_unlocked)((__stream))
- #define __GETC(__stream) (fgetc)((__stream))
- #define __FPUTC_UNLOCKED(__c, __stream) (__fputc_unlocked)((__c),(__stream))
- #define __FPUTC(__c, __stream) (fputc)((__c),(__stream))
- #define __PUTC_UNLOCKED_MACRO(__c, __stream) (__fputc_unlocked)((__c),(__stream))
- #define __PUTC_UNLOCKED(__c, __stream) (__fputc_unlocked)((__c),(__stream))
- #define __PUTC(__c, __stream) (fputc)((__c),(__stream))
- #ifdef __STDIO_GETC_MACRO
- extern FILE *__stdin;
- # undef __GETC_UNLOCKED_MACRO
- # define __GETC_UNLOCKED_MACRO(__stream) \
- ( ((__stream)->__bufpos < (__stream)->__bufgetc_u) \
- ? (*(__stream)->__bufpos++) \
- : __fgetc_unlocked(__stream) )
- # if 0
-
- # undef __GETC_UNLOCKED
- # define __GETC_UNLOCKED(__stream) __GETC_UNLOCKED_MACRO((__stream))
- # ifndef __UCLIBC_HAS_THREADS__
- # undef __GETC
- # define __GETC(__stream) __GETC_UNLOCKED_MACRO((__stream))
- # endif
- # else
-
- # undef __FGETC_UNLOCKED
- # define __FGETC_UNLOCKED(__stream) \
- (__extension__ ({ \
- FILE *__S = (__stream); \
- __GETC_UNLOCKED_MACRO(__S); \
- }) )
- # undef __GETC_UNLOCKED
- # define __GETC_UNLOCKED(__stream) __FGETC_UNLOCKED((__stream))
- # ifdef __UCLIBC_HAS_THREADS__
- # undef __FGETC
- # define __FGETC(__stream) \
- (__extension__ ({ \
- FILE *__S = (__stream); \
- ((__S->__user_locking ) \
- ? __GETC_UNLOCKED_MACRO(__S) \
- : (fgetc)(__S)); \
- }) )
- # undef __GETC
- # define __GETC(__stream) __FGETC((__stream))
- # else
- # undef __FGETC
- # define __FGETC(__stream) __FGETC_UNLOCKED((__stream))
- # undef __GETC
- # define __GETC(__stream) __FGETC_UNLOCKED((__stream))
- # endif
- # endif
- #else
- # define __stdin stdin
- #endif
- #ifdef __STDIO_PUTC_MACRO
- extern FILE *__stdout;
- # undef __PUTC_UNLOCKED_MACRO
- # define __PUTC_UNLOCKED_MACRO(__c, __stream) \
- ( ((__stream)->__bufpos < (__stream)->__bufputc_u) \
- ? (*(__stream)->__bufpos++) = (__c) \
- : __fputc_unlocked((__c),(__stream)) )
- # if 0
-
- # undef __PUTC_UNLOCKED
- # define __PUTC_UNLOCKED(__c, __stream) \
- __PUTC_UNLOCKED_MACRO((__c), (__stream))
- # ifndef __UCLIBC_HAS_THREADS__
- # undef __PUTC
- # define __PUTC(__c, __stream) __PUTC_UNLOCKED_MACRO((__c), (__stream))
- # endif
- # else
-
- # undef __FPUTC_UNLOCKED
- # define __FPUTC_UNLOCKED(__c, __stream) \
- (__extension__ ({ \
- FILE *__S = (__stream); \
- __PUTC_UNLOCKED_MACRO((__c),__S); \
- }) )
- # undef __PUTC_UNLOCKED
- # define __PUTC_UNLOCKED(__c, __stream) __FPUTC_UNLOCKED((__c), (__stream))
- # ifdef __UCLIBC_HAS_THREADS__
- # undef __FPUTC
- # define __FPUTC(__c, __stream) \
- (__extension__ ({ \
- FILE *__S = (__stream); \
- ((__S->__user_locking) \
- ? __PUTC_UNLOCKED_MACRO((__c),__S) \
- : (fputc)((__c),__S)); \
- }) )
- # undef __PUTC
- # define __PUTC(__c, __stream) __FPUTC((__c), (__stream))
- # else
- # undef __FPUTC
- # define __FPUTC(__c, __stream) __FPUTC_UNLOCKED((__c),(__stream))
- # undef __PUTC
- # define __PUTC(__c, __stream) __FPUTC_UNLOCKED((__c),(__stream))
- # endif
- # endif
- #else
- # define __stdout stdout
- #endif
|