2006-09-07 16:14:53 +02:00
|
|
|
#ifndef stdio_h
|
|
|
|
#define stdio_h
|
2007-10-15 11:42:17 +02:00
|
|
|
|
|
|
|
#include "kolibrisys.h"
|
2021-01-15 22:48:24 +01:00
|
|
|
#include <errno.h>
|
2016-05-11 16:53:54 +02:00
|
|
|
#include <stdarg.h>
|
|
|
|
/* use stdarg.h
|
2007-10-15 11:42:17 +02: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 16:53:54 +02:00
|
|
|
*/
|
|
|
|
#ifndef NULL
|
|
|
|
# define NULL ((void*)0)
|
|
|
|
#endif
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2016-05-19 14:15:22 +02:00
|
|
|
typedef unsigned int fpos_t; // 32bit is not enough! 4Gb limit
|
|
|
|
typedef unsigned int size_t;
|
|
|
|
|
2016-04-30 15:50:04 +02:00
|
|
|
int format_print(char *dest, size_t maxlen,const char *fmt0, va_list argp);
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2006-09-07 16:14:53 +02:00
|
|
|
typedef struct {
|
2007-08-24 21:52:54 +02:00
|
|
|
char* buffer;
|
|
|
|
dword buffersize;
|
2016-05-19 14:15:22 +02:00
|
|
|
dword filesize; // too small
|
2018-03-12 21:41:06 +01:00
|
|
|
int filepos; // too small, may be -1
|
2007-08-24 21:52:54 +02:00
|
|
|
char* filename;
|
|
|
|
int mode;
|
2018-03-12 21:41:06 +01:00
|
|
|
int ungetc_buf;
|
|
|
|
dword buffer_start; // 1st byte position
|
|
|
|
dword buffer_end; // points after last buffered data
|
2006-09-07 16:14:53 +02:00
|
|
|
} FILE;
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2018-03-05 18:53:31 +01:00
|
|
|
#define stderr ((FILE*)3) /* works only for fprintf!!! */
|
2016-05-11 16:53:54 +02:00
|
|
|
|
2006-09-07 16:14:53 +02: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 14:15:22 +02:00
|
|
|
#define EOF (-1)
|
2018-03-12 21:41:06 +01:00
|
|
|
#define BUFSIZ (4096)
|
2016-05-19 14:15:22 +02:00
|
|
|
#define FILENAME_MAX (0x400)
|
2007-10-15 11:42:17 +02:00
|
|
|
|
2006-09-07 16:14:53 +02:00
|
|
|
extern FILE* fopen(const char* filename, const char *mode);
|
2016-05-19 14:15:22 +02:00
|
|
|
extern int fclose(FILE* file);
|
2006-09-07 16:14:53 +02: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 21:52:54 +02:00
|
|
|
extern int fwrite(void *buffer,int size,int count,FILE* file);
|
2006-09-07 16:14:53 +02: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 11:42:17 +02:00
|
|
|
extern int cdecl fprintf(FILE* file, const char* format,...);
|
|
|
|
extern int fscanf(FILE* file,const char* format,...);
|
2006-09-07 16:14:53 +02:00
|
|
|
extern int ungetc(int c,FILE* file);
|
2020-12-21 19:08:02 +01:00
|
|
|
|
|
|
|
extern int cdecl printf(const char *format,...);
|
2007-10-15 11:42:17 +02:00
|
|
|
|
|
|
|
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 15:50:04 +02:00
|
|
|
#define getc(a) fgetc(a)
|
2016-05-19 14:15:22 +02:00
|
|
|
#define putc(a, b) fputc(a, b)
|
2016-05-14 10:56:15 +02: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 15:50:04 +02:00
|
|
|
|
2016-05-15 21:19:22 +02: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 13:03:59 +02: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 14:15:22 +02: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 13:03:59 +02:00
|
|
|
|
2020-12-21 19:08:02 +01:00
|
|
|
//debug
|
|
|
|
void debug_printf(const char *format,...);
|
2016-06-10 13:10:52 +02: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-06-05 19:15:52 +02:00
|
|
|
#endif
|
2016-05-15 21:19:22 +02:00
|
|
|
|