ZEDA  1.6.18
zeda_stream.h
Go to the documentation of this file.
1 /* ZEDA - Elementary Data and Algorithms
2  * Copyright (C) 1998 Tomomichi Sugihara (Zhidao)
3  */
12 #ifndef __ZEDA_STREAM_H__
13 #define __ZEDA_STREAM_H__
14 
15 #include <zeda/zeda_misc.h>
16 
17 #ifndef __KERNEL__
18 
20 
21 /* ********************************************************** *//* ************************************************** */
24 
25 /* ********************************************************** *//* ******************************************************* */
33 
34 typedef struct __zstream{
35  union{
36  FILE *fp;
37  struct{
38  byte *buf, *cur;
39  size_t size;
40  } mem;
41  } src;
42  void (* rewind)(struct __zstream *str);
43  int (* seek)(struct __zstream *str, long offset);
44  long (* tell)(struct __zstream *str);
45  size_t (* read)(struct __zstream *str, byte *dest, size_t size, size_t nmemb);
46  size_t (* write)(struct __zstream *str, byte *src, size_t size, size_t nmemb);
47  int (* close)(struct __zstream *str);
48 } zStream;
49 
55 __EXPORT void zStreamAttachFile(zStream *str, FILE *fp);
56 
63 __EXPORT void zStreamAttachMem(zStream *str, byte *mem, size_t size);
64 
73 __EXPORT zStream *zStreamOpenFile(zStream *str, char filename[], char *mode);
74 
84 
102 #define zStreamRewind(s) (*(s)->rewind)( (s) )
103 #define zStreamSeek(s,p) (*(s)->seek)( (s), (p) )
104 #define zStreamTell(s) (*(s)->tell)( (s) )
105 #define zStreamRead(s,d,u,n) (*(s)->read)( (s), (d), (u), (n) )
106 #define zStreamWrite(s,m,u,n) (*(s)->write)( (s), (m), (u), (n) )
107 #define zStreamClose(s) (*(s)->close)( (s) )
108 
112 
113 #endif /* __KERNEL__ */
114 
115 #endif /* __ZEDA_STREAM_H__ */
union __zstream::@1 src
int8_t byte
Definition: zeda_defs.h:92
struct __zstream::@1::@2 mem
#define __END_DECLS
Definition: zeda_defs.h:30
int(* seek)(struct __zstream *str, long offset)
Definition: zeda_stream.h:43
size_t size
Definition: zeda_stream.h:39
miscellanies.
struct __zstream zStream
Definition: zeda_stream.h:34
void zStreamAttachFile(zStream *str, FILE *fp)
attach a file to a stream.
FILE * fp
Definition: zeda_stream.h:36
abstracted stream manipulation class.
int(* close)(struct __zstream *str)
Definition: zeda_stream.h:47
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
byte * buf
Definition: zeda_stream.h:38
size_t(* write)(struct __zstream *str, byte *src, size_t size, size_t nmemb)
Definition: zeda_stream.h:46
void zStreamAttachMem(zStream *str, byte *mem, size_t size)
attach a memory space to a stream.
zStream * zStreamOpenFile(zStream *str, char filename[], char *mode)
open a file and attach to a stream.
zStream * zStreamOpenMem(zStream *str, size_t size)
allocate a memory space and attach to a stream.
#define __EXPORT
Definition: zeda_compat.h:32
long(* tell)(struct __zstream *str)
Definition: zeda_stream.h:44
size_t(* read)(struct __zstream *str, byte *dest, size_t size, size_t nmemb)
Definition: zeda_stream.h:45
byte * cur
Definition: zeda_stream.h:38
void(* rewind)(struct __zstream *str)
Definition: zeda_stream.h:42