Subversion Repositories Kolibri OS

Rev

Rev 8464 | 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 <errno.h>
  6. #include <stdarg.h>
  7. /* use stdarg.h
  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)
  13. */
  14. #ifndef NULL
  15. # define NULL ((void*)0)
  16. #endif
  17.  
  18. typedef unsigned int fpos_t;  // 32bit is not enough! 4Gb limit
  19. typedef unsigned int size_t;
  20.  
  21. int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
  22.  
  23. typedef struct {
  24.   char*   buffer;
  25.   dword   buffersize;
  26.   dword   filesize;     // too small
  27.   int     filepos;      // too small, may be -1
  28.   char*   filename;
  29.   int     mode;
  30.   int     ungetc_buf;
  31.   dword   buffer_start;  // 1st byte position
  32.   dword   buffer_end;    // points after last buffered data
  33. } FILE;
  34.  
  35. #define stderr ((FILE*)3) /* works only for fprintf!!! */
  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. //debug
  97. void debug_printf(const char *format,...);
  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
  104. #endif
  105.  
  106.