00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef __STREAM_STREAM_H__
00011 #define __STREAM_STREAM_H__ 1
00012 #include <libc.h>
00013
00014 # ifndef EOF
00015 # define EOF (-1)
00016 # endif
00017
00018 # define BUFFER_SIZE 512
00019
00020 # define MODE_READ 1
00021 # define MODE_WRITE 2
00022 # define MODE_RDWR 3
00023 # define MODE_APPEND 4
00024 # define MODE_CREATE 8
00025 # define MODE_TRUNC 16
00026 # define MODE_EOF 32
00027
00028 #define TEST_READ(f) (0 != (MODE_READ & stream->mode))
00029 #define TEST_WRITE(f) (0 != (MODE_WRITE & stream->mode))
00030 #define TEST_WRITING(f) (~0 == (f)->offset)
00031 #define TEST_READING(f) ((f)->offset < (f)->size)
00032 #define TEST_APPEND(f) (0 != (MODE_APPEND & (f)->mode))
00033 #define TEST_EOF(f) (0 != (MODE_EOF & (f)->mode))
00034
00035 typedef struct s_stream
00036 {
00037 int fd;
00038 u_int mode;
00039 u_char buffer[BUFFER_SIZE];
00040 u_int offset;
00041 u_int size;
00042 } t_stream;
00043
00044
00045
00046 int stream_fclose(t_stream *stream);
00047
00048 int stream_fgetc(t_stream *stream);
00049
00050 t_stream *stream_fopen(char const *path, char const *mode);
00051
00052 int stream_fputs(char *str, t_stream *stream);
00053
00054 int stream_fsetpos(t_stream *stream, off_t *pos);
00055
00056 size_t stream_fwrite(void const *ptr, size_t size, size_t nmemb, t_stream *stream);
00057
00058 int stream_fflush(t_stream *stream);
00059
00060 int stream_fgetpos(t_stream *stream, fpos_t *pos);
00061
00062 int stream_fput(int c, t_stream *stream);
00063
00064 size_t stream_fread(void *ptr, size_t size, size_t nmemb, t_stream *stream);
00065
00066 long stream_ftell(t_stream *stream);
00067
00068 void stream_rewind(t_stream *stream);
00069
00070 int stream_fget(t_stream *stream);
00071
00072 char *stream_fgets(char *str, int size, t_stream *stream);
00073
00074 int stream_fputc(int c, t_stream *stream);
00075
00076 int stream_fseek(t_stream *stream, long offset, int whence);
00077
00078 int stream_fungetc(t_stream *stream, int c);
00079 #endif