00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00035 #ifndef LIBC_STDIO_H_
00036 #define LIBC_STDIO_H_
00037
00038 #include <sys/types.h>
00039 #include <stdarg.h>
00040 #include <str.h>
00041 #include <adt/list.h>
00042
00043 #ifndef NVERIFY_PRINTF
00044
00045 #define PRINTF_ATTRIBUTE(start, end) \
00046 __attribute__((format(gnu_printf, start, end)))
00047
00048 #else
00049
00050 #define PRINTF_ATTRIBUTE(start, end)
00051
00052 #endif
00053
00054 #define EOF (-1)
00055
00057 #define BUFSIZ 4096
00058
00059 #define DEBUG(fmt, ...) \
00060 { \
00061 char _buf[256]; \
00062 int _n = snprintf(_buf, sizeof(_buf), fmt, ##__VA_ARGS__); \
00063 if (_n > 0) \
00064 (void) __SYSCALL3(SYS_KLOG, 1, (sysarg_t) _buf, str_size(_buf)); \
00065 }
00066
00067 #ifndef SEEK_SET
00068 #define SEEK_SET 0
00069 #endif
00070
00071 #ifndef SEEK_CUR
00072 #define SEEK_CUR 1
00073 #endif
00074
00075 #ifndef SEEK_END
00076 #define SEEK_END 2
00077 #endif
00078
00079 enum _buffer_type {
00081 _IONBF,
00083 _IOLBF,
00085 _IOFBF
00086 };
00087
00088 enum _buffer_state {
00090 _bs_empty,
00091
00093 _bs_write,
00094
00096 _bs_read
00097 };
00098
00099 typedef struct {
00101 link_t link;
00102
00104 int fd;
00105
00107 int error;
00108
00110 int eof;
00111
00113 int klog;
00114
00116 int phone;
00117
00122 int need_sync;
00123
00125 enum _buffer_type btype;
00126
00128 uint8_t *buf;
00129
00131 size_t buf_size;
00132
00134 enum _buffer_state buf_state;
00135
00137 uint8_t *buf_head;
00138
00140 uint8_t *buf_tail;
00141 } FILE;
00142
00143 extern FILE *stdin;
00144 extern FILE *stdout;
00145 extern FILE *stderr;
00146
00147
00148 extern int fgetc(FILE *);
00149 extern char *fgets(char *, int, FILE *);
00150
00151 extern int getchar(void);
00152 extern char *gets(char *, size_t);
00153
00154
00155 extern int fputc(wchar_t, FILE *);
00156 extern int fputs(const char *, FILE *);
00157
00158 extern int putchar(wchar_t);
00159 extern int puts(const char *);
00160
00161
00162 extern int fprintf(FILE *, const char*, ...)
00163 PRINTF_ATTRIBUTE(2, 3);
00164 extern int vfprintf(FILE *, const char *, va_list);
00165
00166 extern int printf(const char *, ...)
00167 PRINTF_ATTRIBUTE(1, 2);
00168 extern int vprintf(const char *, va_list);
00169
00170 extern int snprintf(char *, size_t , const char *, ...)
00171 PRINTF_ATTRIBUTE(3, 4);
00172 extern int asprintf(char **, const char *, ...)
00173 PRINTF_ATTRIBUTE(2, 3);
00174 extern int vsnprintf(char *, size_t, const char *, va_list);
00175
00176
00177 extern FILE *fopen(const char *, const char *);
00178 extern FILE *fdopen(int, const char *);
00179 extern int fclose(FILE *);
00180
00181 extern size_t fread(void *, size_t, size_t, FILE *);
00182 extern size_t fwrite(const void *, size_t, size_t, FILE *);
00183
00184 extern int fseek(FILE *, off64_t, int);
00185 extern void rewind(FILE *);
00186 extern off64_t ftell(FILE *);
00187 extern int feof(FILE *);
00188 extern int fileno(FILE *);
00189
00190 extern int fflush(FILE *);
00191 extern int ferror(FILE *);
00192 extern void clearerr(FILE *);
00193
00194 extern void setvbuf(FILE *, void *, int, size_t);
00195
00196
00197 extern int rename(const char *, const char *);
00198
00199 #endif
00200