ZEDA  1.6.18
zeda_binfile.h
Go to the documentation of this file.
1 /* ZEDA - Elementary Data and Algorithms
2  * Copyright (C) 1998 Tomomichi Sugihara (Zhidao)
3  */
9 #ifndef __ZEDA_BINFILE_H__
10 #define __ZEDA_BINFILE_H__
11 
12 #include <zeda/zeda_bit.h>
13 
15 
16 /* endian-conversion-friendly I/O functions */
17 
18 #define ZEDA_BINFILE_DEF_FREAD_PROTOTYPE( bit ) \
19  size_t fread_int##bit(FILE *fp, int##bit##_t *val)
20 #define ZEDA_BINFILE_DEF_FREAD_REV_PROTOTYPE( bit ) \
21  size_t fread_int##bit##_rev(FILE *fp, int##bit##_t *val)
22 #define ZEDA_BINFILE_DEF_FWRITE_PROTOTYPE( bit ) \
23  size_t fwrite_int##bit(FILE *fp, int##bit##_t *val)
24 #define ZEDA_BINFILE_DEF_FWRITE_REV_PROTOTYPE( bit ) \
25  size_t fwrite_int##bit##_rev(FILE *fp, int##bit##_t *val)
26 
29 
34 
39 
44 
45 #define ZEDA_BINFILE_DEF_FREAD_TYPE_PROTOTYPE( type ) \
46  type fread_##type(FILE *fp)
47 #define ZEDA_BINFILE_DEF_FREAD_REV_TYPE_PROTOTYPE( type ) \
48  type fread_##type##_rev(FILE *fp)
49 #define ZEDA_BINFILE_DEF_FWRITE_TYPE_PROTOTYPE( type ) \
50  size_t fwrite_##type(FILE *fp, type val)
51 #define ZEDA_BINFILE_DEF_FWRITE_REV_TYPE_PROTOTYPE( type ) \
52  size_t fwrite_##type##_rev(FILE *fp, type val)
53 
56 
61 
66 
71 
76 
77 /* binary-file manipulator */
78 
79 #define ZBINFILE_CURRENT_VERSION 0x00000001
80 
81 #define ZBINFILE_ID "ZBD "
82 #define ZBINFILE_ENDIAN_CHECKER 0xaabbccdd
83 
84 #define Z_ENDIAN_LITTLE 1234
85 #define Z_ENDIAN_BIG 4321
86 #define Z_ENDIAN_UNKNOWN 9999
87 
88 typedef struct _zBinFile{
91  int16_t _endian_type; /* endian type */
92  int16_t _size_int; /* byte size of int */
93  int16_t _size_long; /* byte size of long */
94  FILE *_fp; /* file stream */
95  /* I/O methods */
96  size_t (* _fread_int16)(FILE*,int16_t*);
97  size_t (* _fread_int32)(FILE*,int32_t*);
98  size_t (* _fread_int64)(FILE*,int64_t*);
99  int (* _fread_int)(struct _zBinFile*);
100  long (* _fread_long)(struct _zBinFile*);
101 
102  size_t (* _fwrite_int16)(FILE*,int16_t*);
103  size_t (* _fwrite_int32)(FILE*,int32_t*);
104  size_t (* _fwrite_int64)(FILE*,int64_t*);
105  size_t (* _fwrite_int)(struct _zBinFile*,int);
106  size_t (* _fwrite_long)(struct _zBinFile*,long);
108 } zBinFile;
109 
110 __EXPORT bool zBinFileOpen(zBinFile *bf, char filename[], const char *mode);
112 
114 __EXPORT size_t zBinFileByteFWrite(zBinFile *bf, byte val);
115 
118 
119 __EXPORT void zBinFileInfoSet(zBinFile *bf, int16_t version, int16_t endian_type, int16_t size_int, int16_t size_long);
121 
122 #define zBinFileIntFRead(bf) ( (bf)->_fread_int( (bf) ) )
123 #define zBinFileIntFWrite(bf,val) ( (bf)->_fwrite_int( (bf), (val) ) )
124 
125 #define zBinFileLongFRead(bf) ( (bf)->_fread_long( (bf) ) )
126 #define zBinFileLongFWrite(bf,val) ( (bf)->_fwrite_long( (bf), (val) ) )
127 
129 __EXPORT size_t zBinFileFloatFWrite(zBinFile *bf, float val);
131 __EXPORT size_t zBinFileDoubleFWrite(zBinFile *bf, double val);
132 
134 
135 #endif /* __ZEDA_BINFILE_H__ */
int zBinFileClose(zBinFile *bf)
int8_t byte
Definition: zeda_defs.h:92
int16_t word
Definition: zeda_defs.h:93
struct _zBinFile zBinFile
int int32_t
Definition: zeda_defs.h:72
#define __END_DECLS
Definition: zeda_defs.h:30
short int int16_t
Definition: zeda_defs.h:71
size_t zBinFileHeaderFWrite(zBinFile *bf)
Definition: zeda_binfile.h:88
size_t zBinFileDoubleFWrite(zBinFile *bf, double val)
size_t zBinFileFloatFWrite(zBinFile *bf, float val)
#define ZEDA_BINFILE_DEF_FREAD_REV_TYPE_PROTOTYPE(type)
Definition: zeda_binfile.h:47
int32_t dword
Definition: zeda_defs.h:94
#define ZEDA_BINFILE_DEF_FREAD_TYPE_PROTOTYPE(type)
Definition: zeda_binfile.h:45
#define ZEDA_BINFILE_DEF_FREAD_PROTOTYPE(bit)
Definition: zeda_binfile.h:18
byte zBinFileByteFRead(zBinFile *bf)
int16_t version
Definition: zeda_binfile.h:89
bool zBinFileOpen(zBinFile *bf, char filename[], const char *mode)
bit operations.
bool zBinFileHeaderFRead(zBinFile *bf)
#define ZEDA_BINFILE_DEF_FWRITE_REV_PROTOTYPE(bit)
Definition: zeda_binfile.h:24
void zBinFileInfoSetThis(zBinFile *bf)
#define ZEDA_BINFILE_DEF_FWRITE_TYPE_PROTOTYPE(type)
Definition: zeda_binfile.h:49
float zBinFileFloatFRead(zBinFile *bf)
#define __BEGIN_DECLS
Definition: zeda_defs.h:26
double zBinFileDoubleFRead(zBinFile *bf)
size_t zBinFileByteFWrite(zBinFile *bf, byte val)
#define __EXPORT
Definition: zeda_compat.h:32
#define ZEDA_BINFILE_DEF_FWRITE_REV_TYPE_PROTOTYPE(type)
Definition: zeda_binfile.h:51
#define ZEDA_BINFILE_DEF_FWRITE_PROTOTYPE(bit)
Definition: zeda_binfile.h:22
long long int int64_t
Definition: zeda_defs.h:76
#define ZEDA_BINFILE_DEF_FREAD_REV_PROTOTYPE(bit)
Definition: zeda_binfile.h:20
void zBinFileInfoSet(zBinFile *bf, int16_t version, int16_t endian_type, int16_t size_int, int16_t size_long)