Mercurial > hg > th-libs
diff th_ioctx.c @ 771:c17eadc60c3d
Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Mon, 20 Feb 2023 23:33:45 +0200 |
parents | 8eca15bde07d |
children | 1959ba53e9dc |
line wrap: on
line diff
--- a/th_ioctx.c Sun Feb 12 14:08:09 2023 +0200 +++ b/th_ioctx.c Mon Feb 20 23:33:45 2023 +0200 @@ -10,20 +10,20 @@ #include "th_endian.h" -static void th_io_update_atime(th_ioctx *ctx) +static void th_io_update_atime(th_ioctx_t *ctx) { ctx->atime = time(NULL); } -static void th_io_init(th_ioctx *ctx) +static void th_io_init(th_ioctx_t *ctx) { - memset(ctx, 0, sizeof(th_ioctx)); + memset(ctx, 0, sizeof(th_ioctx_t)); ctx->line = 1; } -void th_io_init_stdio(th_ioctx *ctx, FILE *fh) +void th_io_init_stdio(th_ioctx_t *ctx, FILE *fh) { th_io_init(ctx); @@ -32,9 +32,9 @@ } -th_ioctx * th_io_new(const th_ioctx_ops *fops, const char *filename, const char *mode) +th_ioctx_t * th_io_new(const th_ioctx_t_ops *fops, const char *filename, const char *mode) { - th_ioctx *ctx = th_malloc(sizeof(th_ioctx)); + th_ioctx_t *ctx = th_malloc(sizeof(th_ioctx_t)); if (ctx == NULL) return NULL; @@ -61,9 +61,9 @@ } -int th_io_fopen(th_ioctx **pctx, const th_ioctx_ops *fops, const char *filename, const char *mode) +int th_io_fopen(th_ioctx_t **pctx, const th_ioctx_t_ops *fops, const char *filename, const char *mode) { - th_ioctx *ctx; + th_ioctx_t *ctx; int res; if ((*pctx = ctx = th_io_new(fops, filename, mode)) == NULL) @@ -81,7 +81,7 @@ } -int th_io_reopen(th_ioctx *ctx, const char *mode) +int th_io_reopen(th_ioctx_t *ctx, const char *mode) { if (ctx == NULL) return THERR_NULLPTR; @@ -104,7 +104,7 @@ } -void th_io_close(th_ioctx *ctx) +void th_io_close(th_ioctx_t *ctx) { if (ctx != NULL) { @@ -122,9 +122,9 @@ } -bool th_io_set_handlers(th_ioctx *ctx, - void (*error)(th_ioctx *, const int, const char *msg), - void (*msg)(th_ioctx *, const int, const char *msg)) +bool th_io_set_handlers(th_ioctx_t *ctx, + void (*error)(th_ioctx_t *, const int, const char *msg), + void (*msg)(th_ioctx_t *, const int, const char *msg)) { if (ctx == NULL) return false; @@ -136,12 +136,12 @@ } -int th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap) +int th_io_error_v(th_ioctx_t *ctx, const int err, const char *fmt, va_list ap) { char *msg = th_strdup_vprintf(fmt, ap); if (ctx->error != NULL) - ctx->error((struct th_ioctx *) ctx, err, msg); + ctx->error((struct th_ioctx_t *) ctx, err, msg); else THERR("'%s' #%" PRIu_SIZE_T ": %s\n", ctx->filename, ctx->line, msg); @@ -150,7 +150,7 @@ } -int th_io_error(th_ioctx *ctx, const int err, const char *fmt, ...) +int th_io_error(th_ioctx_t *ctx, const int err, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -160,12 +160,12 @@ } -void th_io_msg_v(th_ioctx *ctx, const int level, const char *fmt, va_list ap) +void th_io_msg_v(th_ioctx_t *ctx, const int level, const char *fmt, va_list ap) { if (ctx->msg != NULL) { char *msg = th_strdup_vprintf(fmt, ap); - ctx->msg((struct th_ioctx *) ctx, level, msg); + ctx->msg((struct th_ioctx_t *) ctx, level, msg); th_free(msg); } else @@ -173,7 +173,7 @@ } -void th_io_msg(th_ioctx *ctx, const int level, const char *fmt, ...) +void th_io_msg(th_ioctx_t *ctx, const int level, const char *fmt, ...) { va_list ap; va_start(ap, fmt); @@ -183,7 +183,7 @@ // thfopen() and thfclose() implementations are allowed to be NULL -int thfopen(th_ioctx *ctx) +int thfopen(th_ioctx_t *ctx) { if (ctx == NULL || ctx->fops == NULL) return THERR_NULLPTR; @@ -195,7 +195,7 @@ } -void thfclose(th_ioctx *ctx) +void thfclose(th_ioctx_t *ctx) { if (ctx == NULL || ctx->fops == NULL) return; @@ -205,77 +205,77 @@ } -int thfreset(th_ioctx *ctx) +int thfreset(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->freset(ctx); } -int thferror(th_ioctx *ctx) +int thferror(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->ferror(ctx); } -int thfseek(th_ioctx *ctx, const off_t offset, int whence) +int thfseek(th_ioctx_t *ctx, const off_t offset, int whence) { th_io_update_atime(ctx); return ctx->fops->fseek(ctx, offset, whence); } -off_t thfsize(th_ioctx *ctx) +off_t thfsize(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->fsize(ctx); } -off_t thftell(th_ioctx *ctx) +off_t thftell(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->ftell(ctx); } -bool thfeof(th_ioctx *ctx) +bool thfeof(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->feof(ctx); } -int thfgetc(th_ioctx *ctx) +int thfgetc(th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->fgetc(ctx); } -int thfputc(int v, th_ioctx *ctx) +int thfputc(int v, th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->fputc(v, ctx); } -size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) +size_t thfread(void *ptr, size_t size, size_t nmemb, th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->fread(ptr, size, nmemb, ctx); } -size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) +size_t thfwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx_t *ctx) { th_io_update_atime(ctx); return ctx->fops->fwrite(ptr, size, nmemb, ctx); } -char *thfgets(char *str, int size, th_ioctx *ctx) +char *thfgets(char *str, int size, th_ioctx_t *ctx) { char *ptr = str, *end = str + size - 1; int c; @@ -295,7 +295,7 @@ } -int thfputs(const char *ptr, th_ioctx *ctx) +int thfputs(const char *ptr, th_ioctx_t *ctx) { if (ctx->fops->fputs != NULL) return ctx->fops->fputs(ptr, ctx); @@ -307,7 +307,7 @@ } -int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap) +int thvfprintf(th_ioctx_t *ctx, const char *fmt, va_list ap) { if (ctx->fops->vfprintf != NULL) return ctx->fops->vfprintf(ctx, fmt, ap); @@ -321,7 +321,7 @@ } -int thfprintf(th_ioctx *ctx, const char *fmt, ...) +int thfprintf(th_ioctx_t *ctx, const char *fmt, ...) { int rval; va_list ap; @@ -332,25 +332,25 @@ } -bool thfread_str(th_ioctx *ctx, void *ptr, const size_t len) +bool thfread_str(th_ioctx_t *ctx, void *ptr, const size_t len) { return thfread(ptr, sizeof(uint8_t), len, ctx) == len; } -bool thfread_u8(th_ioctx *ctx, uint8_t *val) +bool thfread_u8(th_ioctx_t *ctx, uint8_t *val) { return (thfread(val, sizeof(uint8_t), 1, ctx) == 1); } -bool thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len) +bool thfwrite_str(th_ioctx_t *ctx, const void *ptr, const size_t len) { return thfwrite(ptr, sizeof(uint8_t), len, ctx) == len; } -bool thfwrite_u8(th_ioctx *ctx, const uint8_t val) +bool thfwrite_u8(th_ioctx_t *ctx, const uint8_t val) { return thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1; } @@ -360,7 +360,7 @@ // File routines for endian-dependant data // #define TH_DEFINE_FUNC(xname, xtype, xmacro) \ -bool thfread_ ## xname (th_ioctx *ctx, xtype *v) \ +bool thfread_ ## xname (th_ioctx_t *ctx, xtype *v) \ { \ xtype result; \ if (thfread(&result, sizeof( xtype ), 1, ctx) != 1) \ @@ -369,7 +369,7 @@ return true; \ } \ \ -bool thfwrite_ ## xname (th_ioctx *ctx, const xtype v) \ +bool thfwrite_ ## xname (th_ioctx_t *ctx, const xtype v) \ { \ xtype result = TH_NATIVE_TO_ ## xmacro (v); \ if (thfwrite(&result, sizeof( xtype ), 1, ctx) != 1) \