Mercurial > hg > th-libs
comparison th_ioctx.h @ 735:31bc1ed07cf5
Renaming BOOL->bool and TRUE/FALSE to true/false, and using stdbool.h if available.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Wed, 07 Dec 2022 12:14:39 +0200 |
parents | 29e44a58bc73 |
children | 8eca15bde07d |
comparison
equal
deleted
inserted
replaced
734:2ae1045f6c18 | 735:31bc1ed07cf5 |
---|---|
29 /** I/O context structure | 29 /** I/O context structure |
30 */ | 30 */ |
31 typedef struct th_ioctx | 31 typedef struct th_ioctx |
32 { | 32 { |
33 char *filename; ///< Context filename, if any. May be NULL. | 33 char *filename; ///< Context filename, if any. May be NULL. |
34 BOOL fallocated; ///< TRUE if filename is allocated, FALSE if "const" | 34 bool fallocated; ///< true if filename is allocated, false if "const" |
35 char *mode; ///< Context's stdio open "mode", may also be NULL. | 35 char *mode; ///< Context's stdio open "mode", may also be NULL. |
36 BOOL mallocated; ///< TRUE if mode string is allocated, FALSE if "const" | 36 bool mallocated; ///< true if mode string is allocated, false if "const" |
37 BOOL allocated; ///< TRUE if this structure has been allocated | 37 bool allocated; ///< true if this structure has been allocated |
38 | 38 |
39 void *data; ///< Internal data | 39 void *data; ///< Internal data |
40 time_t atime; ///< Last access time | 40 time_t atime; ///< Last access time |
41 int64_t size; ///< Size in bytes | 41 int64_t size; ///< Size in bytes |
42 int status; ///< Status | 42 int status; ///< Status |
47 size_t memSize; ///< Current size of data "used" | 47 size_t memSize; ///< Current size of data "used" |
48 size_t memAlloc; ///< Amount actually allocated for data (>= memSize) | 48 size_t memAlloc; ///< Amount actually allocated for data (>= memSize) |
49 size_t minAlloc; ///< Minimum allocation increase (0 = default) | 49 size_t minAlloc; ///< Minimum allocation increase (0 = default) |
50 off_t memOffset; ///< Current offset in data | 50 off_t memOffset; ///< Current offset in data |
51 uint8_t *memData; ///< Pointer to data | 51 uint8_t *memData; ///< Pointer to data |
52 BOOL memFree; ///< TRUE = free the allocated memory on thfclose(), FALSE = no | 52 bool memFree; ///< true = free the allocated memory on thfclose(), false = no |
53 BOOL memWrite; ///< TRUE = memory can be written to / expanded etc. FALSE = no | 53 bool memWrite; ///< true = memory can be written to / expanded etc. false = no |
54 | 54 |
55 // Message functions | 55 // Message functions |
56 void (*error)(struct th_ioctx *ctx, const int err, const char *msg); | 56 void (*error)(struct th_ioctx *ctx, const int err, const char *msg); |
57 void (*msg)(struct th_ioctx *ctx, const int level, const char *msg); | 57 void (*msg)(struct th_ioctx *ctx, const int level, const char *msg); |
58 | 58 |
70 int (*freset)(th_ioctx *ctx); | 70 int (*freset)(th_ioctx *ctx); |
71 int (*ferror)(th_ioctx *ctx); | 71 int (*ferror)(th_ioctx *ctx); |
72 int (*fseek)(th_ioctx *ctx, const off_t, const int whence); | 72 int (*fseek)(th_ioctx *ctx, const off_t, const int whence); |
73 off_t (*fsize)(th_ioctx *ctx); | 73 off_t (*fsize)(th_ioctx *ctx); |
74 off_t (*ftell)(th_ioctx *ctx); | 74 off_t (*ftell)(th_ioctx *ctx); |
75 BOOL (*feof)(th_ioctx *ctx); | 75 bool (*feof)(th_ioctx *ctx); |
76 int (*fgetc)(th_ioctx *ctx); | 76 int (*fgetc)(th_ioctx *ctx); |
77 int (*fputc)(int, th_ioctx *ctx); | 77 int (*fputc)(int, th_ioctx *ctx); |
78 size_t (*fread)(void *ptr, const size_t, const size_t, th_ioctx *ctx); | 78 size_t (*fread)(void *ptr, const size_t, const size_t, th_ioctx *ctx); |
79 size_t (*fwrite)(const void *ptr, const size_t, const size_t, th_ioctx *ctx); | 79 size_t (*fwrite)(const void *ptr, const size_t, const size_t, th_ioctx *ctx); |
80 | 80 |
100 int th_io_reopen(th_ioctx *ctx, const char *mode); | 100 int th_io_reopen(th_ioctx *ctx, const char *mode); |
101 void th_io_close(th_ioctx *ctx); | 101 void th_io_close(th_ioctx *ctx); |
102 | 102 |
103 void th_io_init_stdio(th_ioctx *ctx, FILE *fh); | 103 void th_io_init_stdio(th_ioctx *ctx, FILE *fh); |
104 | 104 |
105 BOOL th_io_set_handlers(th_ioctx *ctx, | 105 bool th_io_set_handlers(th_ioctx *ctx, |
106 void (*error)(th_ioctx *, const int, const char *msg), | 106 void (*error)(th_ioctx *, const int, const char *msg), |
107 void (*msg)(th_ioctx *, const int, const char *msg)); | 107 void (*msg)(th_ioctx *, const int, const char *msg)); |
108 | 108 |
109 int th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap); | 109 int th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap); |
110 void th_io_msg_v(th_ioctx *ctx, const int level, const char *fmt, va_list ap); | 110 void th_io_msg_v(th_ioctx *ctx, const int level, const char *fmt, va_list ap); |
123 int thfreset(th_ioctx *ctx); | 123 int thfreset(th_ioctx *ctx); |
124 int thferror(th_ioctx *ctx); | 124 int thferror(th_ioctx *ctx); |
125 int thfseek(th_ioctx *ctx, const off_t, const int whence); | 125 int thfseek(th_ioctx *ctx, const off_t, const int whence); |
126 off_t thfsize(th_ioctx *ctx); | 126 off_t thfsize(th_ioctx *ctx); |
127 off_t thftell(th_ioctx *ctx); | 127 off_t thftell(th_ioctx *ctx); |
128 BOOL thfeof(th_ioctx *ctx); | 128 bool thfeof(th_ioctx *ctx); |
129 int thfgetc(th_ioctx *ctx); | 129 int thfgetc(th_ioctx *ctx); |
130 int thfputc(int ch, th_ioctx *ctx); | 130 int thfputc(int ch, th_ioctx *ctx); |
131 size_t thfread(void *ptr, const size_t, const size_t, th_ioctx *ctx); | 131 size_t thfread(void *ptr, const size_t, const size_t, th_ioctx *ctx); |
132 size_t thfwrite(const void *, const size_t, const size_t, th_ioctx *ctx); | 132 size_t thfwrite(const void *, const size_t, const size_t, th_ioctx *ctx); |
133 char * thfgets(char *ptr, int size, th_ioctx *ctx); | 133 char * thfgets(char *ptr, int size, th_ioctx *ctx); |
134 int thfputs(const char *ptr, th_ioctx *ctx); | 134 int thfputs(const char *ptr, th_ioctx *ctx); |
135 int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap); | 135 int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap); |
136 int thfprintf(th_ioctx *ctx, const char *fmt, ...) | 136 int thfprintf(th_ioctx *ctx, const char *fmt, ...) |
137 TH_ATTR_PRINTF_FMT(2, 3); | 137 TH_ATTR_PRINTF_FMT(2, 3); |
138 | 138 |
139 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len); | 139 bool thfread_str(th_ioctx *ctx, void *ptr, const size_t len); |
140 BOOL thfread_u8(th_ioctx *ctx, uint8_t *); | 140 bool thfread_u8(th_ioctx *ctx, uint8_t *); |
141 BOOL thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len); | 141 bool thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len); |
142 BOOL thfwrite_u8(th_ioctx *ctx, const uint8_t); | 142 bool thfwrite_u8(th_ioctx *ctx, const uint8_t); |
143 | 143 |
144 | 144 |
145 // | 145 // |
146 // Endian-handling file read/write routines | 146 // Endian-handling file read/write routines |
147 // | 147 // |
148 BOOL thfwrite_ne16(th_ioctx *ctx, const uint16_t v); | 148 bool thfwrite_ne16(th_ioctx *ctx, const uint16_t v); |
149 BOOL thfwrite_ne32(th_ioctx *ctx, const uint32_t v); | 149 bool thfwrite_ne32(th_ioctx *ctx, const uint32_t v); |
150 BOOL thfwrite_ne64(th_ioctx *ctx, const uint64_t v); | 150 bool thfwrite_ne64(th_ioctx *ctx, const uint64_t v); |
151 BOOL thfread_ne16(th_ioctx *ctx, uint16_t *v); | 151 bool thfread_ne16(th_ioctx *ctx, uint16_t *v); |
152 BOOL thfread_ne32(th_ioctx *ctx, uint32_t *v); | 152 bool thfread_ne32(th_ioctx *ctx, uint32_t *v); |
153 BOOL thfread_ne64(th_ioctx *ctx, uint64_t *v); | 153 bool thfread_ne64(th_ioctx *ctx, uint64_t *v); |
154 | 154 |
155 BOOL thfwrite_le16(th_ioctx *ctx, const uint16_t v); | 155 bool thfwrite_le16(th_ioctx *ctx, const uint16_t v); |
156 BOOL thfwrite_le32(th_ioctx *ctx, const uint32_t v); | 156 bool thfwrite_le32(th_ioctx *ctx, const uint32_t v); |
157 BOOL thfwrite_le64(th_ioctx *ctx, const uint64_t v); | 157 bool thfwrite_le64(th_ioctx *ctx, const uint64_t v); |
158 BOOL thfread_le16(th_ioctx *ctx, uint16_t *v); | 158 bool thfread_le16(th_ioctx *ctx, uint16_t *v); |
159 BOOL thfread_le32(th_ioctx *ctx, uint32_t *v); | 159 bool thfread_le32(th_ioctx *ctx, uint32_t *v); |
160 BOOL thfread_le64(th_ioctx *ctx, uint64_t *v); | 160 bool thfread_le64(th_ioctx *ctx, uint64_t *v); |
161 | 161 |
162 BOOL thfwrite_be16(th_ioctx *ctx, const uint16_t v); | 162 bool thfwrite_be16(th_ioctx *ctx, const uint16_t v); |
163 BOOL thfwrite_be32(th_ioctx *ctx, const uint32_t v); | 163 bool thfwrite_be32(th_ioctx *ctx, const uint32_t v); |
164 BOOL thfwrite_be64(th_ioctx *ctx, const uint64_t v); | 164 bool thfwrite_be64(th_ioctx *ctx, const uint64_t v); |
165 BOOL thfread_be16(th_ioctx *ctx, uint16_t *v); | 165 bool thfread_be16(th_ioctx *ctx, uint16_t *v); |
166 BOOL thfread_be32(th_ioctx *ctx, uint32_t *v); | 166 bool thfread_be32(th_ioctx *ctx, uint32_t *v); |
167 BOOL thfread_be64(th_ioctx *ctx, uint64_t *v); | 167 bool thfread_be64(th_ioctx *ctx, uint64_t *v); |
168 | 168 |
169 | 169 |
170 #ifdef __cplusplus | 170 #ifdef __cplusplus |
171 } | 171 } |
172 #endif | 172 #endif |