#ifndef LIBIO_H #define LIBIO_H #include #include #include #include #include #include #include #define BUFSIZE 4096*32 struct file_t; struct file_t { ssize_t cur, /* Index of the current symbol. */ end; /* Index of the last symbols. */ /* off_t offset;*/ /* File offset of the last reading/writing. * Can be changed by file_seek ( I don't need it ). */ unsigned char *buf; /* Buffer. Allocated while I/O. Need to be void*? */ int fd; /* Fire Destory. */ }; typedef struct file_t FILE_T; extern FILE_T std_streams[3]; #define STDINF (&std_streams[0]) #define STDOUTF (&std_streams[1]) #define STDERRF (&std_streams[2]) FILE_T *file_open( const char* path, int flags ); int file_close( FILE_T* file ); int file_fd( FILE_T *file ); ssize_t file_read( FILE_T *file, char *buf, size_t size, size_t nmem ); void file_fresh( FILE_T *file ); int fgetchr( FILE_T *file ); int wgetchr( struct file_t *file, char *bytes); void perrnum( const char* src ); /* No buffer. No more. */ int fprint( int fd, const char* fmt, ... ); #define print( fmt,... ) fprint( STDOUT_FILENO, fmt, __VA_ARGS__ ) #define eprint( fmt,... ) fprint( STDERR_FILENO, fmt, __VA_ARGS__ ) #define puts( msg ) fprint( STDOUT_FILENO, msg ) #define eputs( msg ) fprint( STDERR_FILENO, msg ) int putstr( int fd, const char* str ); int putchr( int fd, char c ); ssize_t getstr( int fd, char *buf, size_t len ); #endif /* LIBIO_H*/