2006-09-07 18:14:53 +04:00
|
|
|
#ifndef stdio_h
|
|
|
|
#define stdio_h
|
2007-10-15 13:42:17 +04:00
|
|
|
|
|
|
|
#include "kolibrisys.h"
|
2016-05-11 17:53:54 +03:00
|
|
|
#include <stdarg.h>
|
|
|
|
/* use stdarg.h
|
2007-10-15 13:42:17 +04:00
|
|
|
typedef char *va_list;
|
|
|
|
#define _roundsize(n) ( (sizeof(n) + 3) & ~3 )
|
|
|
|
#define va_start(ap,v) (ap = (va_list)&v+_roundsize(v))
|
|
|
|
#define va_arg(ap,t) ( *(t *)((ap += _roundsize(t)) - _roundsize(t)) )
|
|
|
|
#define va_end(ap) (ap = (va_list)0)
|
2016-05-11 17:53:54 +03:00
|
|
|
*/
|
|
|
|
#ifndef NULL
|
|
|
|
# define NULL ((void*)0)
|
|
|
|
#endif
|
2007-10-15 13:42:17 +04:00
|
|
|
|
2016-05-19 15:15:22 +03:00
|
|
|
typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit
|
|
|
|
typedef unsigned int size_t;
|
|
|
|
|
2016-04-30 16:50:04 +03:00
|
|
|
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
|
2007-10-15 13:42:17 +04:00
|
|
|
|
2006-09-07 18:14:53 +04:00
|
|
|
typedef struct {
|
2007-08-24 23:52:54 +04:00
|
|
|
char* buffer;
|
|
|
|
dword buffersize;
|
2016-05-19 15:15:22 +03:00
|
|
|
dword filesize; // too small
|
2018-03-12 23:41:06 +03:00
|
|
|
int filepos; // too small, may be -1
|
2007-08-24 23:52:54 +04:00
|
|
|
char* filename;
|
|
|
|
int mode;
|
2018-03-12 23:41:06 +03:00
|
|
|
int ungetc_buf;
|
|
|
|
dword buffer_start; // 1st byte position
|
|
|
|
dword buffer_end; // points after last buffered data
|
2006-09-07 18:14:53 +04:00
|
|
|
} FILE;
|
2007-10-15 13:42:17 +04:00
|
|
|
|
2018-03-05 20:53:31 +03:00
|
|
|
#define stderr ((FILE*)3) /* works only for fprintf!!! */
|
2016-05-11 17:53:54 +03:00
|
|
|
|
|
|
|
|
2006-09-07 18:14:53 +04:00
|
|
|
#define FILE_OPEN_READ 0
|
|
|
|
#define FILE_OPEN_WRITE 1
|
|
|
|
#define FILE_OPEN_APPEND 2
|
|
|
|
#define FILE_OPEN_TEXT 4
|
|
|
|
#define FILE_OPEN_PLUS 8
|
2016-05-19 15:15:22 +03:00
|
|
|
#define EOF (-1)
|
2018-03-12 23:41:06 +03:00
|
|
|
#define BUFSIZ (4096)
|
2016-05-19 15:15:22 +03:00
|
|
|
#define FILENAME_MAX (0x400)
|
2007-10-15 13:42:17 +04:00
|
|
|
|
2006-09-07 18:14:53 +04:00
|
|
|
extern FILE* fopen(const char* filename, const char *mode);
|
2016-05-19 15:15:22 +03:00
|
|
|
extern int fclose(FILE* file);
|
2006-09-07 18:14:53 +04:00
|
|
|
extern int feof(FILE* file);
|
|
|
|
extern int fflush(FILE* file);
|
|
|
|
extern int fgetc(FILE* file);
|
|
|
|
extern int fgetpos(FILE* file,fpos_t* pos);
|
|
|
|
extern int fsetpos(FILE* file,const fpos_t* pos);
|
|
|
|
extern int fputc(int c,FILE* file);
|
|
|
|
extern int fread(void* buffer,int size,int count,FILE* file);
|
2007-08-24 23:52:54 +04:00
|
|
|
extern int fwrite(void *buffer,int size,int count,FILE* file);
|
2006-09-07 18:14:53 +04:00
|
|
|
extern long ftell(FILE* file);
|
|
|
|
#define SEEK_CUR 0
|
|
|
|
#define SEEK_END 1
|
|
|
|
#define SEEK_SET 2
|
|
|
|
extern int fseek(FILE* file,long offset,int origin);
|
|
|
|
extern void rewind(FILE* file);
|
2007-10-15 13:42:17 +04:00
|
|
|
extern int cdecl fprintf(FILE* file, const char* format,...);
|
|
|
|
extern int fscanf(FILE* file,const char* format,...);
|
2006-09-07 18:14:53 +04:00
|
|
|
extern int ungetc(int c,FILE* file);
|
2007-10-15 13:42:17 +04:00
|
|
|
|
|
|
|
extern int cdecl printf(const char *format,...);
|
|
|
|
|
|
|
|
extern int vsnprintf(char *dest, size_t size,const char *format,va_list ap);
|
|
|
|
extern int cdecl snprintf(char *dest, size_t size, const char *format,...);
|
|
|
|
extern int cdecl sprintf(char *dest,const char *format,...);
|
|
|
|
|
2016-04-30 16:50:04 +03:00
|
|
|
#define getc(a) fgetc(a)
|
2016-05-19 15:15:22 +03:00
|
|
|
#define putc(a, b) fputc(a, b)
|
2016-05-14 11:56:15 +03:00
|
|
|
char * fgets (char * str, int num, FILE * stream);
|
|
|
|
int putchar (int ch);
|
|
|
|
int getchar (void);
|
|
|
|
int puts (const char * str);
|
|
|
|
char * gets (char * str);
|
2016-04-30 16:50:04 +03:00
|
|
|
|
2016-05-15 22:19:22 +03:00
|
|
|
typedef int (*virtual_getc)(void *sp, const void *obj);
|
|
|
|
typedef void (*virtual_ungetc)(void *sp, int c, const void *obj);
|
|
|
|
int format_scan(const void *src, const char *fmt, va_list argp, virtual_getc vgetc, virtual_ungetc vungetc);
|
2016-05-16 14:03:59 +03:00
|
|
|
int vscanf ( const char * format, va_list arg );
|
|
|
|
int scanf ( const char * format, ...);
|
|
|
|
int vsscanf ( const char * s, const char * format, va_list arg );
|
|
|
|
int sscanf ( const char * s, const char * format, ...);
|
|
|
|
int vfscanf ( FILE * stream, const char * format, va_list arg );
|
2016-05-19 15:15:22 +03:00
|
|
|
int fputs ( const char * str, FILE * file );
|
|
|
|
void clearerr ( FILE * stream );
|
|
|
|
int ferror ( FILE * stream );
|
|
|
|
void perror ( const char * str );
|
|
|
|
int vprintf ( const char * format, va_list arg );
|
|
|
|
int vsprintf (char * s, const char * format, va_list arg );
|
|
|
|
int vfprintf ( FILE * stream, const char * format, va_list arg );
|
2016-05-16 14:03:59 +03:00
|
|
|
|
2016-06-10 14:10:52 +03:00
|
|
|
|
|
|
|
int tiny_sprintf (char * s, const char * format, ... );
|
|
|
|
int tiny_snprintf (char * s, size_t n, const char * format, ... );
|
|
|
|
int tiny_vsnprintf (char * s, size_t n, const char * format, va_list args );
|
|
|
|
// support %c, %s, %d, %x, %u, %% for 32-bit values only. no width specs, left align
|
|
|
|
// always zero-ended
|
|
|
|
|
2016-05-19 15:15:22 +03:00
|
|
|
extern int errno;
|
|
|
|
/* errors codes from KOS, but minus */
|
2016-06-05 20:15:52 +03:00
|
|
|
#ifndef E_SUCCESS
|
|
|
|
|
|
|
|
# define E_SUCCESS (0)
|
|
|
|
# define E_UNSUPPORTED (-2)
|
|
|
|
# define E_UNKNOWNFS (-3)
|
|
|
|
# define E_NOTFOUND (-5)
|
|
|
|
# define E_EOF (-6)
|
|
|
|
# define E_INVALIDPTR (-7)
|
|
|
|
# define E_DISKFULL (-8)
|
|
|
|
# define E_FSYSERROR (-9)
|
|
|
|
# define E_ACCESS (-10)
|
|
|
|
# define E_HARDWARE (-11)
|
|
|
|
# define E_NOMEM (-12)
|
2016-05-19 15:15:22 +03:00
|
|
|
/* conversion errors */
|
2016-06-05 20:15:52 +03:00
|
|
|
# define ERANGE (-20)
|
|
|
|
# define EINVAL (-21)
|
|
|
|
/* program run and pipe errors */
|
|
|
|
# define E_NOMEM2 (-30)
|
|
|
|
# define E_FILEFMT (-31)
|
|
|
|
# define E_TOOMANY (-32)
|
|
|
|
# define E_PARAM (-33)
|
|
|
|
#endif
|
2016-05-15 22:19:22 +03:00
|
|
|
|
2006-09-07 18:14:53 +04:00
|
|
|
#endif
|