Rev 6443 | Go to most recent revision | Only display areas with differences | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 6443 | Rev 7172 | ||
---|---|---|---|
1 | #ifndef stdio_h |
1 | #ifndef stdio_h |
2 | #define stdio_h |
2 | #define stdio_h |
3 | 3 | ||
4 | #include "kolibrisys.h" |
4 | #include "kolibrisys.h" |
5 | #include |
5 | #include |
6 | /* use stdarg.h |
6 | /* use stdarg.h |
7 | typedef char *va_list; |
7 | typedef char *va_list; |
8 | #define _roundsize(n) ( (sizeof(n) + 3) & ~3 ) |
8 | #define _roundsize(n) ( (sizeof(n) + 3) & ~3 ) |
9 | #define va_start(ap,v) (ap = (va_list)&v+_roundsize(v)) |
9 | #define va_start(ap,v) (ap = (va_list)&v+_roundsize(v)) |
10 | #define va_arg(ap,t) ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) ) |
10 | #define va_arg(ap,t) ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) ) |
11 | #define va_end(ap) (ap = (va_list)0) |
11 | #define va_end(ap) (ap = (va_list)0) |
12 | */ |
12 | */ |
13 | #ifndef NULL |
13 | #ifndef NULL |
14 | # define NULL ((void*)0) |
14 | # define NULL ((void*)0) |
15 | #endif |
15 | #endif |
16 | 16 | ||
17 | typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit |
17 | typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit |
18 | typedef unsigned int size_t; |
18 | typedef unsigned int size_t; |
19 | 19 | ||
20 | int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp); |
20 | int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp); |
21 | 21 | ||
22 | typedef struct { |
22 | typedef struct { |
23 | char* buffer; |
23 | char* buffer; |
24 | dword buffersize; |
24 | dword buffersize; |
25 | dword filesize; // too small |
25 | dword filesize; // too small |
26 | dword filepos; // too small |
26 | dword filepos; // too small |
27 | char* filename; |
27 | char* filename; |
28 | int mode; |
28 | int mode; |
29 | } FILE; |
29 | } FILE; |
30 | 30 | ||
31 | #define stderr ((FILE*)3) /* works inly for fprintf!!! */ |
31 | #define stderr ((FILE*)3) /* works only for fprintf!!! */ |
32 | 32 | ||
33 | 33 | ||
34 | #define FILE_OPEN_READ 0 |
34 | #define FILE_OPEN_READ 0 |
35 | #define FILE_OPEN_WRITE 1 |
35 | #define FILE_OPEN_WRITE 1 |
36 | #define FILE_OPEN_APPEND 2 |
36 | #define FILE_OPEN_APPEND 2 |
37 | #define FILE_OPEN_TEXT 4 |
37 | #define FILE_OPEN_TEXT 4 |
38 | #define FILE_OPEN_PLUS 8 |
38 | #define FILE_OPEN_PLUS 8 |
39 | #define EOF (-1) |
39 | #define EOF (-1) |
40 | #define BUFSIZ (256) |
40 | #define BUFSIZ (256) |
41 | #define FILENAME_MAX (0x400) |
41 | #define FILENAME_MAX (0x400) |
42 | 42 | ||
43 | extern FILE* fopen(const char* filename, const char *mode); |
43 | extern FILE* fopen(const char* filename, const char *mode); |
44 | extern int fclose(FILE* file); |
44 | extern int fclose(FILE* file); |
45 | extern int feof(FILE* file); |
45 | extern int feof(FILE* file); |
46 | extern int fflush(FILE* file); |
46 | extern int fflush(FILE* file); |
47 | extern int fgetc(FILE* file); |
47 | extern int fgetc(FILE* file); |
48 | extern int fgetpos(FILE* file,fpos_t* pos); |
48 | extern int fgetpos(FILE* file,fpos_t* pos); |
49 | extern int fsetpos(FILE* file,const fpos_t* pos); |
49 | extern int fsetpos(FILE* file,const fpos_t* pos); |
50 | extern int fputc(int c,FILE* file); |
50 | extern int fputc(int c,FILE* file); |
51 | extern int fread(void* buffer,int size,int count,FILE* file); |
51 | extern int fread(void* buffer,int size,int count,FILE* file); |
52 | extern int fwrite(void *buffer,int size,int count,FILE* file); |
52 | extern int fwrite(void *buffer,int size,int count,FILE* file); |
53 | extern long ftell(FILE* file); |
53 | extern long ftell(FILE* file); |
54 | #define SEEK_CUR 0 |
54 | #define SEEK_CUR 0 |
55 | #define SEEK_END 1 |
55 | #define SEEK_END 1 |
56 | #define SEEK_SET 2 |
56 | #define SEEK_SET 2 |
57 | extern int fseek(FILE* file,long offset,int origin); |
57 | extern int fseek(FILE* file,long offset,int origin); |
58 | extern void rewind(FILE* file); |
58 | extern void rewind(FILE* file); |
59 | extern int cdecl fprintf(FILE* file, const char* format,...); |
59 | extern int cdecl fprintf(FILE* file, const char* format,...); |
60 | extern int fscanf(FILE* file,const char* format,...); |
60 | extern int fscanf(FILE* file,const char* format,...); |
61 | extern int ungetc(int c,FILE* file); |
61 | extern int ungetc(int c,FILE* file); |
62 | 62 | ||
63 | extern int cdecl printf(const char *format,...); |
63 | extern int cdecl printf(const char *format,...); |
64 | 64 | ||
65 | extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap); |
65 | extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap); |
66 | extern int cdecl snprintf(char *dest, size_t size, const char *format,...); |
66 | extern int cdecl snprintf(char *dest, size_t size, const char *format,...); |
67 | extern int cdecl sprintf(char *dest,const char *format,...); |
67 | extern int cdecl sprintf(char *dest,const char *format,...); |
68 | 68 | ||
69 | #define getc(a) fgetc(a) |
69 | #define getc(a) fgetc(a) |
70 | #define putc(a, b) fputc(a, b) |
70 | #define putc(a, b) fputc(a, b) |
71 | char * fgets (char * str, int num, FILE * stream); |
71 | char * fgets (char * str, int num, FILE * stream); |
72 | int putchar (int ch); |
72 | int putchar (int ch); |
73 | int getchar (void); |
73 | int getchar (void); |
74 | int puts (const char * str); |
74 | int puts (const char * str); |
75 | char * gets (char * str); |
75 | char * gets (char * str); |
76 | 76 | ||
77 | typedef int (*virtual_getc)(void *sp, const void *obj); |
77 | typedef int (*virtual_getc)(void *sp, const void *obj); |
78 | typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); |
78 | typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); |
79 | int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc); |
79 | int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc); |
80 | int vscanf ( const char * format, va_list arg ); |
80 | int vscanf ( const char * format, va_list arg ); |
81 | int scanf ( const char * format, ...); |
81 | int scanf ( const char * format, ...); |
82 | int vsscanf ( const char * s, const char * format, va_list arg ); |
82 | int vsscanf ( const char * s, const char * format, va_list arg ); |
83 | int sscanf ( const char * s, const char * format, ...); |
83 | int sscanf ( const char * s, const char * format, ...); |
84 | int vfscanf ( FILE * stream, const char * format, va_list arg ); |
84 | int vfscanf ( FILE * stream, const char * format, va_list arg ); |
85 | int fputs ( const char * str, FILE * file ); |
85 | int fputs ( const char * str, FILE * file ); |
86 | void clearerr ( FILE * stream ); |
86 | void clearerr ( FILE * stream ); |
87 | int ferror ( FILE * stream ); |
87 | int ferror ( FILE * stream ); |
88 | void perror ( const char * str ); |
88 | void perror ( const char * str ); |
89 | int vprintf ( const char * format, va_list arg ); |
89 | int vprintf ( const char * format, va_list arg ); |
90 | int vsprintf (char * s, const char * format, va_list arg ); |
90 | int vsprintf (char * s, const char * format, va_list arg ); |
91 | int vfprintf ( FILE * stream, const char * format, va_list arg ); |
91 | int vfprintf ( FILE * stream, const char * format, va_list arg ); |
92 | 92 | ||
93 | 93 | ||
94 | int tiny_sprintf (char * s, const char * format, ... ); |
94 | int tiny_sprintf (char * s, const char * format, ... ); |
95 | int tiny_snprintf (char * s, size_t n, const char * format, ... ); |
95 | int tiny_snprintf (char * s, size_t n, const char * format, ... ); |
96 | int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args ); |
96 | int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args ); |
97 | // support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align |
97 | // support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align |
98 | // always zero-ended |
98 | // always zero-ended |
99 | 99 | ||
100 | extern int errno; |
100 | extern int errno; |
101 | /* errors codes from KOS, but minus */ |
101 | /* errors codes from KOS, but minus */ |
102 | #ifndef E_SUCCESS |
102 | #ifndef E_SUCCESS |
103 | 103 | ||
104 | # define E_SUCCESS (0) |
104 | # define E_SUCCESS (0) |
105 | # define E_UNSUPPORTED (-2) |
105 | # define E_UNSUPPORTED (-2) |
106 | # define E_UNKNOWNFS (-3) |
106 | # define E_UNKNOWNFS (-3) |
107 | # define E_NOTFOUND (-5) |
107 | # define E_NOTFOUND (-5) |
108 | # define E_EOF (-6) |
108 | # define E_EOF (-6) |
109 | # define E_INVALIDPTR (-7) |
109 | # define E_INVALIDPTR (-7) |
110 | # define E_DISKFULL (-8) |
110 | # define E_DISKFULL (-8) |
111 | # define E_FSYSERROR (-9) |
111 | # define E_FSYSERROR (-9) |
112 | # define E_ACCESS (-10) |
112 | # define E_ACCESS (-10) |
113 | # define E_HARDWARE (-11) |
113 | # define E_HARDWARE (-11) |
114 | # define E_NOMEM (-12) |
114 | # define E_NOMEM (-12) |
115 | /* conversion errors */ |
115 | /* conversion errors */ |
116 | # define ERANGE (-20) |
116 | # define ERANGE (-20) |
117 | # define EINVAL (-21) |
117 | # define EINVAL (-21) |
118 | /* program run and pipe errors */ |
118 | /* program run and pipe errors */ |
119 | # define E_NOMEM2 (-30) |
119 | # define E_NOMEM2 (-30) |
120 | # define E_FILEFMT (-31) |
120 | # define E_FILEFMT (-31) |
121 | # define E_TOOMANY (-32) |
121 | # define E_TOOMANY (-32) |
122 | # define E_PARAM (-33) |
122 | # define E_PARAM (-33) |
123 | #endif |
123 | #endif |
124 | 124 | ||
125 | #endif |
125 | #endif |