[1] | 1 | /* diet stdio */ |
---|
| 2 | |
---|
| 3 | #include <sys/types.h> |
---|
| 4 | #include "dietfeatures.h" |
---|
| 5 | #ifdef WANT_THREAD_SAFE |
---|
| 6 | #include <pthread.h> |
---|
| 7 | #endif |
---|
| 8 | #include <stdarg.h> |
---|
| 9 | |
---|
| 10 | #ifdef WANT_SMALL_STDIO_BUFS |
---|
| 11 | #define BUFSIZE 128 |
---|
| 12 | #else |
---|
| 13 | #define BUFSIZE 2048 |
---|
| 14 | #endif |
---|
| 15 | |
---|
| 16 | struct __stdio_file { |
---|
| 17 | int fd; |
---|
| 18 | int flags; |
---|
| 19 | uint32_t bs; /* read: bytes in buffer */ |
---|
| 20 | uint32_t bm; /* position in buffer */ |
---|
| 21 | uint32_t buflen; /* length of buf */ |
---|
| 22 | char *buf; |
---|
| 23 | struct __stdio_file *next; /* for fflush */ |
---|
| 24 | pid_t popen_kludge; |
---|
| 25 | unsigned char ungetbuf; |
---|
| 26 | char ungotten; |
---|
| 27 | #ifdef WANT_THREAD_SAFE |
---|
| 28 | pthread_mutex_t m; |
---|
| 29 | #endif |
---|
| 30 | }; |
---|
| 31 | |
---|
| 32 | #define ERRORINDICATOR 1 |
---|
| 33 | #define EOFINDICATOR 2 |
---|
| 34 | #define BUFINPUT 4 |
---|
| 35 | #define BUFLINEWISE 8 |
---|
| 36 | #define NOBUF 16 |
---|
| 37 | #define STATICBUF 32 |
---|
| 38 | #define FDPIPE 64 |
---|
| 39 | #define CANREAD 128 |
---|
| 40 | #define CANWRITE 256 |
---|
| 41 | |
---|
| 42 | #define _IONBF 0 |
---|
| 43 | #define _IOLBF 1 |
---|
| 44 | #define _IOFBF 2 |
---|
| 45 | |
---|
| 46 | #include <stdio.h> |
---|
| 47 | |
---|
| 48 | /* internal function to flush buffer. |
---|
| 49 | * However, if next is BUFINPUT and the buffer is an input buffer, it |
---|
| 50 | * will not be flushed. Vice versa for output */ |
---|
| 51 | extern int __fflush4(FILE *stream,int next); |
---|
| 52 | extern int __buffered_outs(const char *s,size_t len); |
---|
| 53 | |
---|
| 54 | /* ..scanf */ |
---|
| 55 | struct arg_scanf { |
---|
| 56 | void *data; |
---|
| 57 | int (*getch)(void*); |
---|
| 58 | int (*putch)(int,void*); |
---|
| 59 | }; |
---|
| 60 | |
---|
| 61 | int __v_scanf(struct arg_scanf* fn, const char *format, va_list arg_ptr); |
---|
| 62 | |
---|
| 63 | struct arg_printf { |
---|
| 64 | void *data; |
---|
| 65 | int (*put)(void*,size_t,void*); |
---|
| 66 | }; |
---|
| 67 | |
---|
| 68 | int __v_printf(struct arg_printf* fn, const char *format, va_list arg_ptr); |
---|
| 69 | |
---|
| 70 | extern FILE *__stdio_root; |
---|
| 71 | |
---|
| 72 | int __fflush_stdin(void); |
---|
| 73 | int __fflush_stdout(void); |
---|
| 74 | int __fflush_stderr(void); |
---|
| 75 | |
---|
| 76 | FILE* __stdio_init_file(int fd,int closeonerror,int mode); |
---|
| 77 | int __stdio_parse_mode(const char *mode); |
---|
| 78 | void __stdio_flushall(void); |
---|
| 79 | |
---|
| 80 | FILE *fopen_unlocked(const char *path, const char *mode); |
---|
| 81 | FILE *fdopen_unlocked(int fildes, const char *mode); |
---|
| 82 | FILE *freopen_unlocked(const char *path, const char *mode, FILE *stream); |
---|
| 83 | |
---|
| 84 | int __stdout_is_tty(void); |
---|
| 85 | int __stdin_is_tty(void); |
---|