Mercurial > hg > th-libs
comparison th_ioctx.c @ 457:85fa3d333556
Actually, revert the boolean changes .. meh.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 02 Jan 2018 23:09:29 +0200 |
parents | 347bfd3e017e |
children | 0a1a65503e0b |
comparison
equal
deleted
inserted
replaced
456:1bf886fa9db5 | 457:85fa3d333556 |
---|---|
76 th_free(ctx); | 76 th_free(ctx); |
77 } | 77 } |
78 } | 78 } |
79 | 79 |
80 | 80 |
81 bool th_io_set_handlers(th_ioctx *ctx, | 81 BOOL th_io_set_handlers(th_ioctx *ctx, |
82 void (*error)(th_ioctx *, const int, const char *msg), | 82 void (*error)(th_ioctx *, const int, const char *msg), |
83 void (*msg)(th_ioctx *, const int, const char *msg)) | 83 void (*msg)(th_ioctx *, const int, const char *msg)) |
84 { | 84 { |
85 if (ctx == NULL) | 85 if (ctx == NULL) |
86 return false; | 86 return FALSE; |
87 | 87 |
88 ctx->error = error; | 88 ctx->error = error; |
89 ctx->msg = msg; | 89 ctx->msg = msg; |
90 | 90 |
91 return true; | 91 return TRUE; |
92 } | 92 } |
93 | 93 |
94 | 94 |
95 void th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap) | 95 void th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap) |
96 { | 96 { |
174 ctx->atime = time(NULL); | 174 ctx->atime = time(NULL); |
175 return ctx->fops->ftell(ctx); | 175 return ctx->fops->ftell(ctx); |
176 } | 176 } |
177 | 177 |
178 | 178 |
179 bool thfeof(th_ioctx *ctx) | 179 BOOL thfeof(th_ioctx *ctx) |
180 { | 180 { |
181 ctx->atime = time(NULL); | 181 ctx->atime = time(NULL); |
182 return ctx->fops->feof(ctx); | 182 return ctx->fops->feof(ctx); |
183 } | 183 } |
184 | 184 |
266 va_end(ap); | 266 va_end(ap); |
267 return retv; | 267 return retv; |
268 } | 268 } |
269 | 269 |
270 | 270 |
271 bool thfread_str(th_ioctx *ctx, void *ptr, const size_t len) | 271 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len) |
272 { | 272 { |
273 return (thfread(ptr, sizeof(uint8_t), len, ctx) == len); | 273 return (thfread(ptr, sizeof(uint8_t), len, ctx) == len); |
274 } | 274 } |
275 | 275 |
276 | 276 |
277 bool thfread_u8(th_ioctx *ctx, uint8_t *val) | 277 BOOL thfread_u8(th_ioctx *ctx, uint8_t *val) |
278 { | 278 { |
279 return (thfread(val, sizeof(uint8_t), 1, ctx) == 1); | 279 return (thfread(val, sizeof(uint8_t), 1, ctx) == 1); |
280 } | 280 } |
281 | 281 |
282 | 282 |
283 bool thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len) | 283 BOOL thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len) |
284 { | 284 { |
285 return (thfwrite(ptr, sizeof(uint8_t), len, ctx) == len); | 285 return (thfwrite(ptr, sizeof(uint8_t), len, ctx) == len); |
286 } | 286 } |
287 | 287 |
288 | 288 |
289 bool thfwrite_u8(th_ioctx *ctx, const uint8_t val) | 289 BOOL thfwrite_u8(th_ioctx *ctx, const uint8_t val) |
290 { | 290 { |
291 return (thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1); | 291 return (thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1); |
292 } | 292 } |
293 | 293 |
294 | 294 |
295 // | 295 // |
296 // File routines for endian-dependant data | 296 // File routines for endian-dependant data |
297 // | 297 // |
298 #define TH_DEFINE_FUNC(xname, xtype, xmacro) \ | 298 #define TH_DEFINE_FUNC(xname, xtype, xmacro) \ |
299 bool thfread_ ## xname (th_ioctx *ctx, xtype *v) \ | 299 BOOL thfread_ ## xname (th_ioctx *ctx, xtype *v) \ |
300 { \ | 300 { \ |
301 xtype result; \ | 301 xtype result; \ |
302 if (thfread(&result, sizeof( xtype ), 1, ctx) != 1) \ | 302 if (thfread(&result, sizeof( xtype ), 1, ctx) != 1) \ |
303 return false; \ | 303 return FALSE; \ |
304 *v = TH_ ## xmacro ## _TO_NATIVE (result); \ | 304 *v = TH_ ## xmacro ## _TO_NATIVE (result); \ |
305 return true; \ | 305 return TRUE; \ |
306 } \ | 306 } \ |
307 \ | 307 \ |
308 bool thfwrite_ ## xname (th_ioctx *ctx, const xtype v) \ | 308 BOOL thfwrite_ ## xname (th_ioctx *ctx, const xtype v) \ |
309 { \ | 309 { \ |
310 xtype result = TH_NATIVE_TO_ ## xmacro (v); \ | 310 xtype result = TH_NATIVE_TO_ ## xmacro (v); \ |
311 if (thfwrite(&result, sizeof( xtype ), 1, ctx) != 1) \ | 311 if (thfwrite(&result, sizeof( xtype ), 1, ctx) != 1) \ |
312 return false; \ | 312 return FALSE; \ |
313 return true; \ | 313 return TRUE; \ |
314 } | 314 } |
315 | 315 |
316 | 316 |
317 TH_DEFINE_FUNC(le16, uint16_t, LE16) | 317 TH_DEFINE_FUNC(le16, uint16_t, LE16) |
318 TH_DEFINE_FUNC(le32, uint32_t, LE32) | 318 TH_DEFINE_FUNC(le32, uint32_t, LE32) |
403 ctx->size = fileSize; | 403 ctx->size = fileSize; |
404 return fileSize; | 404 return fileSize; |
405 } | 405 } |
406 | 406 |
407 | 407 |
408 static bool th_stdio_feof(th_ioctx *ctx) | 408 static BOOL th_stdio_feof(th_ioctx *ctx) |
409 { | 409 { |
410 return feof(CTX_FH); | 410 return feof(CTX_FH); |
411 } | 411 } |
412 | 412 |
413 | 413 |