diff options
Diffstat (limited to 'libc/stdio/_stdio.h')
| -rw-r--r-- | libc/stdio/_stdio.h | 174 |
1 files changed, 113 insertions, 61 deletions
diff --git a/libc/stdio/_stdio.h b/libc/stdio/_stdio.h index 58b013dda..e8ef08983 100644 --- a/libc/stdio/_stdio.h +++ b/libc/stdio/_stdio.h @@ -15,39 +15,76 @@ #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <stdarg.h> #include <unistd.h> #ifdef __UCLIBC_HAS_WCHAR__ #include <wchar.h> #endif -#ifdef __UCLIBC_HAS_THREADS__ -#include <pthread.h> +#include <bits/uClibc_mutex.h> -#ifdef __USE_STDIO_FUTEXES__ -#define __STDIO_THREADLOCK_OPENLIST \ - _IO_lock_lock(_stdio_openlist_lock) +#define __STDIO_THREADLOCK_OPENLIST_ADD \ + __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_add_lock) -#define __STDIO_THREADUNLOCK_OPENLIST \ - _IO_lock_unlock(_stdio_openlist_lock) +#define __STDIO_THREADUNLOCK_OPENLIST_ADD \ + __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_add_lock) -#define __STDIO_THREADTRYLOCK_OPENLIST \ - _IO_lock_trylock(_stdio_openlist_lock) -#else -#define __STDIO_THREADLOCK_OPENLIST \ - __pthread_mutex_lock(&_stdio_openlist_lock) +#ifdef __STDIO_BUFFERS -#define __STDIO_THREADUNLOCK_OPENLIST \ - __pthread_mutex_unlock(&_stdio_openlist_lock) +#define __STDIO_THREADLOCK_OPENLIST_DEL \ + __UCLIBC_IO_MUTEX_LOCK(_stdio_openlist_del_lock) -#define __STDIO_THREADTRYLOCK_OPENLIST \ - __pthread_mutex_trylock(&_stdio_openlist_lock) -#endif +#define __STDIO_THREADUNLOCK_OPENLIST_DEL \ + __UCLIBC_IO_MUTEX_UNLOCK(_stdio_openlist_del_lock) -#else -#define __STDIO_THREADLOCK_OPENLIST ((void)0) -#define __STDIO_THREADUNLOCK_OPENLIST ((void)0) +#ifdef __UCLIBC_HAS_THREADS__ +#define __STDIO_OPENLIST_INC_USE \ +do { \ + __STDIO_THREADLOCK_OPENLIST_DEL; \ + ++_stdio_openlist_use_count; \ + __STDIO_THREADUNLOCK_OPENLIST_DEL; \ +} while (0) + +extern void _stdio_openlist_dec_use(void); + +#define __STDIO_OPENLIST_DEC_USE \ + _stdio_openlist_dec_use() + +#define __STDIO_OPENLIST_INC_DEL_CNT \ +do { \ + __STDIO_THREADLOCK_OPENLIST_DEL; \ + ++_stdio_openlist_del_count; \ + __STDIO_THREADUNLOCK_OPENLIST_DEL; \ +} while (0) + +#define __STDIO_OPENLIST_DEC_DEL_CNT \ +do { \ + __STDIO_THREADLOCK_OPENLIST_DEL; \ + --_stdio_openlist_del_count; \ + __STDIO_THREADUNLOCK_OPENLIST_DEL; \ +} while (0) + +#endif /* __UCLIBC_HAS_THREADS__ */ +#endif /* __STDIO_BUFFERS */ +#ifndef __STDIO_THREADLOCK_OPENLIST_DEL +#define __STDIO_THREADLOCK_OPENLIST_DEL ((void)0) +#endif +#ifndef __STDIO_THREADUNLOCK_OPENLIST_DEL +#define __STDIO_THREADUNLOCK_OPENLIST_DEL ((void)0) +#endif +#ifndef __STDIO_OPENLIST_INC_USE +#define __STDIO_OPENLIST_INC_USE ((void)0) +#endif +#ifndef __STDIO_OPENLIST_DEC_USE +#define __STDIO_OPENLIST_DEC_USE ((void)0) +#endif +#ifndef __STDIO_OPENLIST_INC_DEL_CNT +#define __STDIO_OPENLIST_INC_DEL_CNT ((void)0) +#endif +#ifndef __STDIO_OPENLIST_DEC_DEL_CNT +#define __STDIO_OPENLIST_DEC_DEL_CNT ((void)0) #endif #define __UNDEFINED_OR_NONPORTABLE ((void)0) @@ -91,10 +128,10 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr (read((STREAMPTR)->__filedes,(BUF),(SIZE))) #define __WRITE(STREAMPTR,BUF,SIZE) \ (write((STREAMPTR)->__filedes,(BUF),(SIZE))) -#define __CLOSE(STREAMPTR) \ - (close((STREAMPTR)->__filedes)) #define __SEEK(STREAMPTR,PPOS,WHENCE) \ (__stdio_seek((STREAMPTR),(PPOS),(WHENCE))) +#define __CLOSE(STREAMPTR) \ + (close((STREAMPTR)->__filedes)) #endif /* __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ */ @@ -131,30 +168,30 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr /**********************************************************************/ #ifdef __UCLIBC_HAS_WCHAR__ -#define __STDIO_STREAM_IS_NARROW_WRITING(S) \ - (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \ +#define __STDIO_STREAM_IS_NARROW_WRITING(S) \ + (((S)->__modeflags & (__FLAG_WRITING|__FLAG_NARROW)) \ == (__FLAG_WRITING|__FLAG_NARROW)) -#define __STDIO_STREAM_IS_WIDE_WRITING(S) \ - (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \ +#define __STDIO_STREAM_IS_WIDE_WRITING(S) \ + (((S)->__modeflags & (__FLAG_WRITING|__FLAG_WIDE)) \ == (__FLAG_WRITING|__FLAG_WIDE)) #if (__FLAG_NARROW <= __MASK_READING) #error assumption violated regarding __FLAG_NARROW #endif -#define __STDIO_STREAM_IS_NARROW_READING(S) \ +#define __STDIO_STREAM_IS_NARROW_READING(S) \ (((S)->__modeflags & (__MASK_READING|__FLAG_NARROW)) > __FLAG_NARROW) -#define __STDIO_STREAM_IS_WIDE_READING(S) \ +#define __STDIO_STREAM_IS_WIDE_READING(S) \ (((S)->__modeflags & (__MASK_READING|__FLAG_WIDE)) > __FLAG_WIDE) #define __STDIO_STREAM_IS_NARROW(S) ((S)->__modeflags & __FLAG_NARROW) #define __STDIO_STREAM_IS_WIDE(S) ((S)->__modeflags & __FLAG_WIDE) -#define __STDIO_STREAM_SET_NARROW(S) \ +#define __STDIO_STREAM_SET_NARROW(S) \ ((void)((S)->__modeflags |= __FLAG_NARROW)) -#define __STDIO_STREAM_SET_WIDE(S) \ +#define __STDIO_STREAM_SET_WIDE(S) \ ((void)((S)->__modeflags |= __FLAG_WIDE)) #else @@ -163,11 +200,11 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr #define __STDIO_STREAM_IS_NARROW_READING(S) __STDIO_STREAM_IS_READING(S) -#define __STDIO_STREAM_IS_NARROW(S) (1) -#define __STDIO_STREAM_IS_WIDE(S) (0) +#define __STDIO_STREAM_IS_NARROW(S) (1) +#define __STDIO_STREAM_IS_WIDE(S) (0) -#define __STDIO_STREAM_SET_NARROW(S) ((void)0) -#define __STDIO_STREAM_SET_WIDE(S) ((void)0) +#define __STDIO_STREAM_SET_NARROW(S) ((void)0) +#define __STDIO_STREAM_SET_WIDE(S) ((void)0) #endif /**********************************************************************/ @@ -197,7 +234,7 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr #else # define __STDIO_STREAM_DISABLE_GETC(S) ((void)0) # define __STDIO_STREAM_ENABLE_GETC(S) ((void)0) -# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0) +# define __STDIO_STREAM_CAN_USE_BUFFER_GET(S) (0) #endif #ifdef __UCLIBC_HAS_STDIO_PUTC_MACRO__ @@ -210,26 +247,28 @@ extern int __stdio_seek(FILE *stream, register __offmax_t *pos, int whence) attr #else # define __STDIO_STREAM_DISABLE_PUTC(S) ((void)0) # define __STDIO_STREAM_ENABLE_PUTC(S) ((void)0) -# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0) +# define __STDIO_STREAM_CAN_USE_BUFFER_ADD(S) (0) #endif #ifdef __UCLIBC_HAS_GLIBC_CUSTOM_STREAMS__ #define __STDIO_STREAM_IS_CUSTOM(S) ((S)->__cookie != &((S)->__filedes)) #else -#define __STDIO_STREAM_IS_CUSTOM(S) (0) +#define __STDIO_STREAM_IS_CUSTOM(S) (0) #endif /**********************************************************************/ #ifdef __STDIO_BUFFERS -#define __STDIO_STREAM_FREE_BUFFER(S) \ - do { if ((S)->__modeflags & __FLAG_FREEBUF) free((S)->__bufstart); } while (0) +#define __STDIO_STREAM_FREE_BUFFER(S) \ + do { if ((S)->__modeflags & __FLAG_FREEBUF) \ + free((S)->__bufstart); } while (0) #else #define __STDIO_STREAM_FREE_BUFFER(S) ((void)0) #endif #define __STDIO_STREAM_FREE_FILE(S) \ - do { if ((S)->__modeflags & __FLAG_FREEFILE) free((S)); } while (0) + do { if ((S)->__modeflags & __FLAG_FREEFILE) \ + free((S)); } while (0) #ifdef __UCLIBC_HAS_LFS__ @@ -251,7 +290,7 @@ extern size_t __stdio_wcommit(FILE *__restrict stream) attribute_hidden; extern size_t __stdio_rfill(FILE *__restrict stream) attribute_hidden; extern size_t __stdio_fwrite(const unsigned char *__restrict buffer, - size_t bytes, FILE *__restrict stream) attribute_hidden; + size_t bytes, FILE *__restrict stream) attribute_hidden; #else #define __stdio_fwrite(B,N,S) __stdio_WRITE((S),(B),(N)) @@ -259,8 +298,9 @@ extern size_t __stdio_fwrite(const unsigned char *__restrict buffer, #endif extern size_t __stdio_WRITE(FILE *stream, const unsigned char *buf, - size_t bufsize) attribute_hidden; -extern size_t __stdio_READ(FILE *stream, unsigned char *buf, size_t bufsize) attribute_hidden; + size_t bufsize) attribute_hidden; +extern size_t __stdio_READ(FILE *stream, unsigned char *buf, + size_t bufsize) attribute_hidden; extern int __stdio_trans2r(FILE *__restrict stream) attribute_hidden; extern int __stdio_trans2w(FILE *__restrict stream) attribute_hidden; @@ -293,14 +333,14 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde /* Valid when reading... */ #define __STDIO_STREAM_BUFFER_RAVAIL(S) ((S)->__bufread - (S)->__bufpos) #define __STDIO_STREAM_BUFFER_GET(S) (*(S)->__bufpos++) -#define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S)) +#define __STDIO_FILL_READ_BUFFER(S) __stdio_rfill((S)) -#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \ +#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) \ (S)->__bufread = (S)->__bufpos = (S)->__bufstart #define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES (-2) -#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2) +#define __STDIO_STREAM_FAKE_VSSCANF_FILEDES (-2) #define __STDIO_STREAM_FAKE_VSWPRINTF_FILEDES (-3) #define __STDIO_STREAM_FAKE_VSWSCANF_FILEDES (-3) @@ -315,9 +355,9 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde #else /* __STDIO_BUFFERS */ -#define __STDIO_STREAM_IS_FBF(S) (0) -#define __STDIO_STREAM_IS_LBF(S) (0) -#define __STDIO_STREAM_IS_NBF(S) (1) +#define __STDIO_STREAM_IS_FBF(S) (0) +#define __STDIO_STREAM_IS_LBF(S) (0) +#define __STDIO_STREAM_IS_NBF(S) (1) #define __STDIO_STREAM_BUFFER_SIZE(S) (0) #define __STDIO_STREAM_BUFFER_ADD(S,C) ((void)0) @@ -329,8 +369,8 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde #define __STDIO_STREAM_BUFFER_RAVAIL(S) (0) #define __STDIO_STREAM_BUFFER_GET(S) (EOF) -#define __STDIO_FILL_READ_BUFFER(S) (0) -#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0) +#define __STDIO_FILL_READ_BUFFER(S) (0) +#define __STDIO_STREAM_INIT_BUFREAD_BUFPOS(S) ((void)0) #undef __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES #undef __STDIO_STREAM_FAKE_VSSCANF_FILEDES @@ -341,14 +381,14 @@ extern int __stdio_trans2w_o(FILE *__restrict stream, int oflag) attribute_hidde #undef __STDIO_STREAM_IS_FAKE_VSWPRINTF # ifdef __USE_OLD_VFPRINTF__ -# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2) -# define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \ +# define __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB (-2) +# define __STDIO_STREAM_IS_FAKE_VSNPRINTF_NB(S) \ ((S)->__filedes == __STDIO_STREAM_FAKE_VSNPRINTF_FILEDES_NB) # endif # ifndef __UCLIBC_HAS_WCHAR__ -# define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2) -# define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \ +# define __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB (-2) +# define __STDIO_STREAM_IS_FAKE_VSSCANF_NB(S) \ ((S)->__filedes == __STDIO_STREAM_FAKE_VSSCANF_FILEDES_NB) # endif @@ -359,7 +399,8 @@ extern int __stdio_adjust_position(FILE *__restrict stream, __offmax_t *pos) att #ifdef __STDIO_HAS_OPENLIST /* Uses an implementation hack!!! */ -#define __STDIO_FLUSH_LBF_STREAMS fflush_unlocked((FILE *) &_stdio_openlist) +#define __STDIO_FLUSH_LBF_STREAMS \ + fflush_unlocked((FILE *) &_stdio_openlist) #else #define __STDIO_FLUSH_LBF_STREAMS ((void)0) #endif @@ -382,13 +423,24 @@ extern void _stdio_validate_FILE(const FILE *stream); /**********************************************************************/ -extern FILE *_stdio_fopen(intptr_t fname_or_mode, - const char *__restrict mode, - FILE *__restrict stream, int filedes) attribute_hidden; +extern FILE *_stdio_fopen(intptr_t fname_or_mode, const char *__restrict mode, + FILE *__restrict stream, int filedes) attribute_hidden; + +#ifdef __UCLIBC_HAS_WCHAR__ +extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, + size_t n, FILE *__restrict stream) attribute_hidden; +#endif + +/**********************************************************************/ + +extern int _vfprintf_internal (FILE * __restrict stream, + const char * __restrict format, + va_list arg) attribute_hidden; #ifdef __UCLIBC_HAS_WCHAR__ -extern size_t _wstdio_fwrite(const wchar_t *__restrict ws, size_t n, - FILE *__restrict stream) attribute_hidden; +extern int _vfwprintf_internal (FILE * __restrict stream, + const wchar_t * __restrict format, + va_list arg) attribute_hidden; #endif /**********************************************************************/ |
