Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1. #ifndef stdio_h
  2. #define stdio_h
  3.  
  4. #include "kolibrisys.h"
  5. #include <stdarg.h>
  6. /* use stdarg.h
  7. typedef char *va_list;
  8. #define _roundsize(n)    ( (sizeof(n) + 3) & ~3 )
  9. #define va_start(ap,v) (ap = (va_list)&v+_roundsize(v))
  10. #define va_arg(ap,t)    ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) )
  11. #define va_end(ap) (ap = (va_list)0)
  12. */
  13. #ifndef NULL
  14. # define NULL ((void*)0)
  15. #endif
  16.  
  17. typedef unsigned int fpos_t;  // 32bit is not enough! 4Gb limit
  18. typedef unsigned int size_t;
  19.  
  20. int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
  21.  
  22. typedef struct {
  23.   char*   buffer;
  24.   dword   buffersize;
  25.   dword   filesize;     // too small
  26.   int     filepos;      // too small, may be -1
  27.   char*   filename;
  28.   int     mode;
  29.   int     ungetc_buf;
  30.   dword   buffer_start;  // 1st byte position
  31.   dword   buffer_end;    // points after last buffered data
  32. } FILE;
  33.  
  34. #define stderr ((FILE*)3) /* works only for fprintf!!! */
  35.  
  36.  
  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
  42. #define EOF (-1)
  43. #define BUFSIZ (4096)
  44. #define FILENAME_MAX (0x400)
  45.  
  46. extern FILE* fopen(const char* filename, const char *mode);
  47. extern int fclose(FILE* file);
  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);
  55. extern int fwrite(void *buffer,int size,int count,FILE* file);
  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);
  62. extern int cdecl fprintf(FILE* file, const char* format,...);
  63. extern int fscanf(FILE* file,const char* format,...);
  64. extern int ungetc(int c,FILE* file);
  65.  
  66. extern int cdecl printf(const char *format,...);
  67.  
  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.  
  72. #define getc(a) fgetc(a)
  73. #define putc(a, b) fputc(a, b)
  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);
  79.  
  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);
  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 );
  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 );
  95.  
  96.  
  97. int tiny_sprintf (char * s, const char * format, ... );
  98. int tiny_snprintf (char * s, size_t n, const char * format, ... );
  99. int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args );
  100. // support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align
  101. // always zero-ended
  102.  
  103. extern int errno;
  104. /* errors codes from KOS, but minus */
  105. #ifndef E_SUCCESS
  106.  
  107. # define E_SUCCESS (0)
  108. # define E_UNSUPPORTED (-2)
  109. # define E_UNKNOWNFS  (-3)
  110. # define E_NOTFOUND (-5)
  111. # define E_EOF  (-6)
  112. # define E_INVALIDPTR (-7)
  113. # define E_DISKFULL  (-8)
  114. # define E_FSYSERROR  (-9)
  115. # define E_ACCESS  (-10)
  116. # define E_HARDWARE  (-11)
  117. # define E_NOMEM  (-12)
  118. /* conversion errors */
  119. # define ERANGE (-20)
  120. # define EINVAL (-21)
  121. /* program run and pipe errors */
  122. # define E_NOMEM2 (-30)
  123. # define E_FILEFMT (-31)
  124. # define E_TOOMANY (-32)
  125. # define E_PARAM (-33)
  126. #endif
  127.  
  128. #endif
  129.