Rev 8464 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
145 | halyavin | 1 | #ifndef stdio_h |
2 | #define stdio_h |
||
647 | andrew_pro | 3 | |
4 | #include "kolibrisys.h" |
||
8536 | superturbo | 5 | #include |
6424 | siemargl | 6 | #include |
7 | /* use stdarg.h |
||
647 | andrew_pro | 8 | typedef char *va_list; |
9 | #define _roundsize(n) ( (sizeof(n) + 3) & ~3 ) |
||
10 | #define va_start(ap,v) (ap = (va_list)&v+_roundsize(v)) |
||
11 | #define va_arg(ap,t) ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) ) |
||
12 | #define va_end(ap) (ap = (va_list)0) |
||
6424 | siemargl | 13 | */ |
14 | #ifndef NULL |
||
15 | # define NULL ((void*)0) |
||
16 | #endif |
||
647 | andrew_pro | 17 | |
6433 | siemargl | 18 | typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit |
19 | typedef unsigned int size_t; |
||
20 | |||
6412 | siemargl | 21 | int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp); |
647 | andrew_pro | 22 | |
145 | halyavin | 23 | typedef struct { |
611 | andrew_pro | 24 | char* buffer; |
25 | dword buffersize; |
||
6433 | siemargl | 26 | dword filesize; // too small |
7184 | siemargl | 27 | int filepos; // too small, may be -1 |
611 | andrew_pro | 28 | char* filename; |
29 | int mode; |
||
7184 | siemargl | 30 | int ungetc_buf; |
31 | dword buffer_start; // 1st byte position |
||
32 | dword buffer_end; // points after last buffered data |
||
145 | halyavin | 33 | } FILE; |
647 | andrew_pro | 34 | |
7172 | siemargl | 35 | #define stderr ((FILE*)3) /* works only for fprintf!!! */ |
6424 | siemargl | 36 | |
145 | halyavin | 37 | #define FILE_OPEN_READ 0 |
38 | #define FILE_OPEN_WRITE 1 |
||
39 | #define FILE_OPEN_APPEND 2 |
||
40 | #define FILE_OPEN_TEXT 4 |
||
41 | #define FILE_OPEN_PLUS 8 |
||
6433 | siemargl | 42 | #define EOF (-1) |
7184 | siemargl | 43 | #define BUFSIZ (4096) |
6433 | siemargl | 44 | #define FILENAME_MAX (0x400) |
647 | andrew_pro | 45 | |
145 | halyavin | 46 | extern FILE* fopen(const char* filename, const char *mode); |
6433 | siemargl | 47 | extern int fclose(FILE* file); |
145 | halyavin | 48 | extern int feof(FILE* file); |
49 | extern int fflush(FILE* file); |
||
50 | extern int fgetc(FILE* file); |
||
51 | extern int fgetpos(FILE* file,fpos_t* pos); |
||
52 | extern int fsetpos(FILE* file,const fpos_t* pos); |
||
53 | extern int fputc(int c,FILE* file); |
||
54 | extern int fread(void* buffer,int size,int count,FILE* file); |
||
611 | andrew_pro | 55 | extern int fwrite(void *buffer,int size,int count,FILE* file); |
145 | halyavin | 56 | extern long ftell(FILE* file); |
57 | #define SEEK_CUR 0 |
||
58 | #define SEEK_END 1 |
||
59 | #define SEEK_SET 2 |
||
60 | extern int fseek(FILE* file,long offset,int origin); |
||
61 | extern void rewind(FILE* file); |
||
647 | andrew_pro | 62 | extern int cdecl fprintf(FILE* file, const char* format,...); |
63 | extern int fscanf(FILE* file,const char* format,...); |
||
145 | halyavin | 64 | extern int ungetc(int c,FILE* file); |
647 | andrew_pro | 65 | |
8464 | superturbo | 66 | extern int cdecl printf(const char *format,...); |
67 | |||
647 | andrew_pro | 68 | extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap); |
69 | extern int cdecl snprintf(char *dest, size_t size, const char *format,...); |
||
70 | extern int cdecl sprintf(char *dest,const char *format,...); |
||
71 | |||
6412 | siemargl | 72 | #define getc(a) fgetc(a) |
6433 | siemargl | 73 | #define putc(a, b) fputc(a, b) |
6429 | siemargl | 74 | char * fgets (char * str, int num, FILE * stream); |
75 | int putchar (int ch); |
||
76 | int getchar (void); |
||
77 | int puts (const char * str); |
||
78 | char * gets (char * str); |
||
6412 | siemargl | 79 | |
6431 | siemargl | 80 | typedef int (*virtual_getc)(void *sp, const void *obj); |
81 | typedef void (*virtual_ungetc)(void *sp, int c, const void *obj); |
||
82 | int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc); |
||
6432 | siemargl | 83 | int vscanf ( const char * format, va_list arg ); |
84 | int scanf ( const char * format, ...); |
||
85 | int vsscanf ( const char * s, const char * format, va_list arg ); |
||
86 | int sscanf ( const char * s, const char * format, ...); |
||
87 | int vfscanf ( FILE * stream, const char * format, va_list arg ); |
||
6433 | siemargl | 88 | int fputs ( const char * str, FILE * file ); |
89 | void clearerr ( FILE * stream ); |
||
90 | int ferror ( FILE * stream ); |
||
91 | void perror ( const char * str ); |
||
92 | int vprintf ( const char * format, va_list arg ); |
||
93 | int vsprintf (char * s, const char * format, va_list arg ); |
||
94 | int vfprintf ( FILE * stream, const char * format, va_list arg ); |
||
6431 | siemargl | 95 | |
8464 | superturbo | 96 | //debug |
97 | void debug_printf(const char *format,...); |
||
6443 | siemargl | 98 | |
99 | int tiny_sprintf (char * s, const char * format, ... ); |
||
100 | int tiny_snprintf (char * s, size_t n, const char * format, ... ); |
||
101 | int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args ); |
||
102 | // support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align |
||
103 | // always zero-ended |
||
6441 | siemargl | 104 | #endif |
6432 | siemargl | 105 |