# HG changeset patch # User Matti Hamalainen # Date 1676928825 -7200 # Node ID c17eadc60c3d3749c69f723f730b05ec9a5e3ecf # Parent 79f888e4616f0c32234a7a45ee4a62fb4abe98d6 Rename th_ioctx struct to th_ioctx_t, for consistency. Breaks API. diff -r 79f888e4616f -r c17eadc60c3d tests.c --- a/tests.c Sun Feb 12 14:08:09 2023 +0200 +++ b/tests.c Mon Feb 20 23:33:45 2023 +0200 @@ -51,7 +51,7 @@ int optFlags = TST_ALL; -th_ioctx testio; +th_ioctx_t testio; // Define option arguments @@ -411,7 +411,7 @@ } -void test_ioctx_error(th_ioctx *fh, const int val, const char *msg) +void test_ioctx_error(th_ioctx_t *fh, const int val, const char *msg) { (void) fh; (void) val; @@ -419,7 +419,7 @@ } -void test_ioctx_msg(th_ioctx *fh, const int val, const char *msg) +void test_ioctx_msg(th_ioctx_t *fh, const int val, const char *msg) { (void) fh; (void) val; @@ -442,7 +442,7 @@ void test_config_read(th_cfgitem_t *cfg, const char *filename) { int nsubtest; - th_ioctx *fh = NULL; + th_ioctx_t *fh = NULL; test_ctx ctx; th_cfgitem_t *item; @@ -501,7 +501,7 @@ { static const char *filename = "cfg.temp"; test_ctx ctx; - th_ioctx *fh = NULL; + th_ioctx_t *fh = NULL; th_cfgitem_t *sect1, *sect2, *cfg = NULL, *item; char *v_str1 = NULL; unsigned int v_uint1; diff -r 79f888e4616f -r c17eadc60c3d th_config.c --- a/th_config.c Sun Feb 12 14:08:09 2023 +0200 +++ b/th_config.c Mon Feb 20 23:33:45 2023 +0200 @@ -319,7 +319,7 @@ } -static int th_cfg_read_sect(th_ioctx *fh, th_cfgitem_t *sect, int nesting) +static int th_cfg_read_sect(th_ioctx_t *fh, th_cfgitem_t *sect, int nesting) { th_cfgparserctx_t ctx; th_cfgitem_t *item = NULL; @@ -725,7 +725,7 @@ } -int th_cfg_read(th_ioctx *fh, th_cfgitem_t *cfg) +int th_cfg_read(th_ioctx_t *fh, th_cfgitem_t *cfg) { if (fh == NULL || cfg == NULL) return THERR_NULLPTR; @@ -736,7 +736,7 @@ /* Write a configuration into file */ -static bool th_print_indent_a(th_ioctx *fh, const int nesting, const char *fmt, va_list ap) +static bool th_print_indent_a(th_ioctx_t *fh, const int nesting, const char *fmt, va_list ap) { for (int i = 0; i < nesting * 4; i++) { @@ -748,7 +748,7 @@ } -static bool th_print_indent(th_ioctx *fh, const int nesting, const char *fmt, ...) +static bool th_print_indent(th_ioctx_t *fh, const int nesting, const char *fmt, ...) { bool ret; va_list ap; @@ -785,7 +785,7 @@ } -static bool th_cfg_write_string_escaped(th_ioctx *fh, const char *str, const char delim) +static bool th_cfg_write_string_escaped(th_ioctx_t *fh, const char *str, const char delim) { for (const char *ptr = str; *ptr; ptr++) { @@ -806,7 +806,7 @@ } -static int th_cfg_write_item(th_ioctx *fh, const th_cfgitem_t *item) +static int th_cfg_write_item(th_ioctx_t *fh, const th_cfgitem_t *item) { switch (item->type) { @@ -839,7 +839,7 @@ } -static int th_cfg_write_sect(th_ioctx *fh, const th_cfgitem_t *item, const int nesting) +static int th_cfg_write_sect(th_ioctx_t *fh, const th_cfgitem_t *item, const int nesting) { while (item != NULL) { @@ -939,7 +939,7 @@ } -int th_cfg_write(th_ioctx *fh, const th_cfgitem_t *cfg) +int th_cfg_write(th_ioctx_t *fh, const th_cfgitem_t *cfg) { if (fh == NULL || cfg == NULL) return THERR_NULLPTR; diff -r 79f888e4616f -r c17eadc60c3d th_config.h --- a/th_config.h Sun Feb 12 14:08:09 2023 +0200 +++ b/th_config.h Mon Feb 20 23:33:45 2023 +0200 @@ -62,9 +62,9 @@ // // Functions // -int th_cfg_read(th_ioctx *fh, th_cfgitem_t *cfg /*, TODO XXX const int flags (for controlling things like "error out on unknown items or ignore" etc */); +int th_cfg_read(th_ioctx_t *fh, th_cfgitem_t *cfg /*, TODO XXX const int flags (for controlling things like "error out on unknown items or ignore" etc */); void th_cfg_free(th_cfgitem_t *cfg, void (*freefunc)(th_cfgitem_t *)); -int th_cfg_write(th_ioctx *fh, const th_cfgitem_t *cfg); +int th_cfg_write(th_ioctx_t *fh, const th_cfgitem_t *cfg); int th_cfg_add_comment(th_cfgitem_t **cfg, const char *comment); int th_cfg_add_section(th_cfgitem_t **cfg, const char *name, th_cfgitem_t *sect); diff -r 79f888e4616f -r c17eadc60c3d th_ioctx.c --- 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) \ diff -r 79f888e4616f -r c17eadc60c3d th_ioctx.h --- a/th_ioctx.h Sun Feb 12 14:08:09 2023 +0200 +++ b/th_ioctx.h Mon Feb 20 23:33:45 2023 +0200 @@ -22,13 +22,13 @@ // // Typedefs and structures // -struct th_ioctx; -struct th_ioctx_ops; +struct th_ioctx_t; +struct th_ioctx_t_ops; /** I/O context structure */ -typedef struct th_ioctx +typedef struct th_ioctx_t { char *filename; ///< Context filename, if any. May be NULL. bool fn_allocated; ///< true if filename is allocated, false if "const" @@ -53,118 +53,118 @@ bool memWrite; ///< true = memory can be written to / expanded etc. false = no // Message functions - void (*error)(struct th_ioctx *ctx, const int err, const char *msg); - void (*msg)(struct th_ioctx *ctx, const int level, const char *msg); + void (*error)(struct th_ioctx_t *ctx, const int err, const char *msg); + void (*msg)(struct th_ioctx_t *ctx, const int level, const char *msg); - const struct th_ioctx_ops *fops; ///< Pointer to I/O ops struct to be used with this context -} th_ioctx; + const struct th_ioctx_t_ops *fops; ///< Pointer to I/O ops struct to be used with this context +} th_ioctx_t; -typedef struct th_ioctx_ops +typedef struct th_ioctx_t_ops { char *name; ///< Name of this I/O ops definition - int (*fopen)(th_ioctx *ctx); - void (*fclose)(th_ioctx *ctx); + int (*fopen)(th_ioctx_t *ctx); + void (*fclose)(th_ioctx_t *ctx); - int (*freset)(th_ioctx *ctx); - int (*ferror)(th_ioctx *ctx); - int (*fseek)(th_ioctx *ctx, const off_t, const int whence); - off_t (*fsize)(th_ioctx *ctx); - off_t (*ftell)(th_ioctx *ctx); - bool (*feof)(th_ioctx *ctx); - int (*fgetc)(th_ioctx *ctx); - int (*fputc)(int, th_ioctx *ctx); - size_t (*fread)(void *ptr, const size_t, const size_t, th_ioctx *ctx); - size_t (*fwrite)(const void *ptr, const size_t, const size_t, th_ioctx *ctx); + int (*freset)(th_ioctx_t *ctx); + int (*ferror)(th_ioctx_t *ctx); + int (*fseek)(th_ioctx_t *ctx, const off_t, const int whence); + off_t (*fsize)(th_ioctx_t *ctx); + off_t (*ftell)(th_ioctx_t *ctx); + bool (*feof)(th_ioctx_t *ctx); + int (*fgetc)(th_ioctx_t *ctx); + int (*fputc)(int, th_ioctx_t *ctx); + size_t (*fread)(void *ptr, const size_t, const size_t, th_ioctx_t *ctx); + size_t (*fwrite)(const void *ptr, const size_t, const size_t, th_ioctx_t *ctx); - char * (*fgets)(char *str, int size, th_ioctx *ctx); - int (*fputs)(const char *str, th_ioctx *ctx); - int (*vfprintf)(th_ioctx *ctx, const char *fmt, va_list ap); + char * (*fgets)(char *str, int size, th_ioctx_t *ctx); + int (*fputs)(const char *str, th_ioctx_t *ctx); + int (*vfprintf)(th_ioctx_t *ctx, const char *fmt, va_list ap); -} th_ioctx_ops; +} th_ioctx_t_ops; // // Some basic iops // -extern const th_ioctx_ops th_stdio_io_ops, th_mem_io_ops; +extern const th_ioctx_t_ops th_stdio_io_ops, th_mem_io_ops; // // I/O context management functions // -th_ioctx * th_io_new(const th_ioctx_ops *fops, const char *filename, const char *mode); -int th_io_fopen(th_ioctx **pctx, const th_ioctx_ops *fops, const char *filename, const char *mode); -int th_io_reopen(th_ioctx *ctx, const char *mode); -void th_io_close(th_ioctx *ctx); +th_ioctx_t * th_io_new(const th_ioctx_t_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); +int th_io_reopen(th_ioctx_t *ctx, const char *mode); +void th_io_close(th_ioctx_t *ctx); -void th_io_init_stdio(th_ioctx *ctx, FILE *fh); +void th_io_init_stdio(th_ioctx_t *ctx, FILE *fh); -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)); -int th_io_error_v(th_ioctx *ctx, const int err, const char *fmt, va_list ap); -void th_io_msg_v(th_ioctx *ctx, const int level, const char *fmt, va_list ap); -int th_io_error(th_ioctx *ctx, const int err, const char *fmt, ...) +int th_io_error_v(th_ioctx_t *ctx, const int err, const char *fmt, va_list ap); +void th_io_msg_v(th_ioctx_t *ctx, const int level, const char *fmt, va_list ap); +int th_io_error(th_ioctx_t *ctx, const int err, const char *fmt, ...) TH_ATTR_PRINTF_FMT(3, 4); -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, ...) TH_ATTR_PRINTF_FMT(3, 4); // // Basic I/O operations // -int thfopen(th_ioctx *ctx); -void thfclose(th_ioctx *ctx); +int thfopen(th_ioctx_t *ctx); +void thfclose(th_ioctx_t *ctx); -int thfreset(th_ioctx *ctx); -int thferror(th_ioctx *ctx); -int thfseek(th_ioctx *ctx, const off_t, const int whence); -off_t thfsize(th_ioctx *ctx); -off_t thftell(th_ioctx *ctx); -bool thfeof(th_ioctx *ctx); -int thfgetc(th_ioctx *ctx); -int thfputc(int ch, th_ioctx *ctx); -size_t thfread(void *ptr, const size_t, const size_t, th_ioctx *ctx); -size_t thfwrite(const void *, const size_t, const size_t, th_ioctx *ctx); -char * thfgets(char *ptr, int size, th_ioctx *ctx); -int thfputs(const char *ptr, th_ioctx *ctx); -int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap); -int thfprintf(th_ioctx *ctx, const char *fmt, ...) +int thfreset(th_ioctx_t *ctx); +int thferror(th_ioctx_t *ctx); +int thfseek(th_ioctx_t *ctx, const off_t, const int whence); +off_t thfsize(th_ioctx_t *ctx); +off_t thftell(th_ioctx_t *ctx); +bool thfeof(th_ioctx_t *ctx); +int thfgetc(th_ioctx_t *ctx); +int thfputc(int ch, th_ioctx_t *ctx); +size_t thfread(void *ptr, const size_t, const size_t, th_ioctx_t *ctx); +size_t thfwrite(const void *, const size_t, const size_t, th_ioctx_t *ctx); +char * thfgets(char *ptr, int size, th_ioctx_t *ctx); +int thfputs(const char *ptr, th_ioctx_t *ctx); +int thvfprintf(th_ioctx_t *ctx, const char *fmt, va_list ap); +int thfprintf(th_ioctx_t *ctx, const char *fmt, ...) TH_ATTR_PRINTF_FMT(2, 3); -bool thfread_str(th_ioctx *ctx, void *ptr, const size_t len); -bool thfread_u8(th_ioctx *ctx, uint8_t *); -bool thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len); -bool thfwrite_u8(th_ioctx *ctx, const uint8_t); +bool thfread_str(th_ioctx_t *ctx, void *ptr, const size_t len); +bool thfread_u8(th_ioctx_t *ctx, uint8_t *); +bool thfwrite_str(th_ioctx_t *ctx, const void *ptr, const size_t len); +bool thfwrite_u8(th_ioctx_t *ctx, const uint8_t); // // Endian-handling file read/write routines // -bool thfwrite_ne16(th_ioctx *ctx, const uint16_t v); -bool thfwrite_ne32(th_ioctx *ctx, const uint32_t v); -bool thfwrite_ne64(th_ioctx *ctx, const uint64_t v); -bool thfread_ne16(th_ioctx *ctx, uint16_t *v); -bool thfread_ne32(th_ioctx *ctx, uint32_t *v); -bool thfread_ne64(th_ioctx *ctx, uint64_t *v); +bool thfwrite_ne16(th_ioctx_t *ctx, const uint16_t v); +bool thfwrite_ne32(th_ioctx_t *ctx, const uint32_t v); +bool thfwrite_ne64(th_ioctx_t *ctx, const uint64_t v); +bool thfread_ne16(th_ioctx_t *ctx, uint16_t *v); +bool thfread_ne32(th_ioctx_t *ctx, uint32_t *v); +bool thfread_ne64(th_ioctx_t *ctx, uint64_t *v); -bool thfwrite_le16(th_ioctx *ctx, const uint16_t v); -bool thfwrite_le32(th_ioctx *ctx, const uint32_t v); -bool thfwrite_le64(th_ioctx *ctx, const uint64_t v); -bool thfread_le16(th_ioctx *ctx, uint16_t *v); -bool thfread_le32(th_ioctx *ctx, uint32_t *v); -bool thfread_le64(th_ioctx *ctx, uint64_t *v); +bool thfwrite_le16(th_ioctx_t *ctx, const uint16_t v); +bool thfwrite_le32(th_ioctx_t *ctx, const uint32_t v); +bool thfwrite_le64(th_ioctx_t *ctx, const uint64_t v); +bool thfread_le16(th_ioctx_t *ctx, uint16_t *v); +bool thfread_le32(th_ioctx_t *ctx, uint32_t *v); +bool thfread_le64(th_ioctx_t *ctx, uint64_t *v); -bool thfwrite_be16(th_ioctx *ctx, const uint16_t v); -bool thfwrite_be32(th_ioctx *ctx, const uint32_t v); -bool thfwrite_be64(th_ioctx *ctx, const uint64_t v); -bool thfread_be16(th_ioctx *ctx, uint16_t *v); -bool thfread_be32(th_ioctx *ctx, uint32_t *v); -bool thfread_be64(th_ioctx *ctx, uint64_t *v); +bool thfwrite_be16(th_ioctx_t *ctx, const uint16_t v); +bool thfwrite_be32(th_ioctx_t *ctx, const uint32_t v); +bool thfwrite_be64(th_ioctx_t *ctx, const uint64_t v); +bool thfread_be16(th_ioctx_t *ctx, uint16_t *v); +bool thfread_be32(th_ioctx_t *ctx, uint32_t *v); +bool thfread_be64(th_ioctx_t *ctx, uint64_t *v); #ifdef __cplusplus diff -r 79f888e4616f -r c17eadc60c3d th_ioctx_mem.c --- a/th_ioctx_mem.c Sun Feb 12 14:08:09 2023 +0200 +++ b/th_ioctx_mem.c Mon Feb 20 23:33:45 2023 +0200 @@ -8,7 +8,7 @@ #include "th_ioctx.h" -static int th_mem_fopen(th_ioctx *ctx) +static int th_mem_fopen(th_ioctx_t *ctx) { if (ctx->mode == NULL) return THERR_NULLPTR; @@ -43,7 +43,7 @@ } -static void th_mem_fclose(th_ioctx *ctx) +static void th_mem_fclose(th_ioctx_t *ctx) { if (ctx->memFree) { @@ -54,7 +54,7 @@ } -static bool th_mem_realloc(th_ioctx *ctx, const size_t newSize) +static bool th_mem_realloc(th_ioctx_t *ctx, const size_t newSize) { size_t grow; @@ -105,20 +105,20 @@ } -static int th_mem_freset(th_ioctx *ctx) +static int th_mem_freset(th_ioctx_t *ctx) { ctx->memOffset = 0; return THERR_OK; } -static int th_mem_ferror(th_ioctx *ctx) +static int th_mem_ferror(th_ioctx_t *ctx) { return ctx->status; } -static int th_mem_fseek(th_ioctx *ctx, const off_t offset, const int whence) +static int th_mem_fseek(th_ioctx_t *ctx, const off_t offset, const int whence) { off_t newPos; @@ -159,25 +159,25 @@ } -static off_t th_mem_fsize(th_ioctx *ctx) +static off_t th_mem_fsize(th_ioctx_t *ctx) { return ctx->memSize; } -static off_t th_mem_ftell(th_ioctx *ctx) +static off_t th_mem_ftell(th_ioctx_t *ctx) { return ctx->memOffset; } -static bool th_mem_feof(th_ioctx *ctx) +static bool th_mem_feof(th_ioctx_t *ctx) { return ((size_t) ctx->memOffset) >= ctx->memSize; } -static int th_mem_fgetc(th_ioctx *ctx) +static int th_mem_fgetc(th_ioctx_t *ctx) { // Check for EOF if ((size_t) ctx->memOffset < ctx->memSize) @@ -187,7 +187,7 @@ } -static size_t th_mem_fread(void *buf, size_t size, size_t nmemb, th_ioctx *ctx) +static size_t th_mem_fread(void *buf, size_t size, size_t nmemb, th_ioctx_t *ctx) { size_t length = size * nmemb; @@ -208,7 +208,7 @@ } -static int th_mem_fputc(int ch, th_ioctx *ctx) +static int th_mem_fputc(int ch, th_ioctx_t *ctx) { // Check for EOF if (!th_mem_realloc(ctx, ctx->memOffset + 1)) @@ -219,7 +219,7 @@ } -static size_t th_mem_fwrite(const void *buf, size_t size, size_t nmemb, th_ioctx *ctx) +static size_t th_mem_fwrite(const void *buf, size_t size, size_t nmemb, th_ioctx_t *ctx) { size_t length = size * nmemb; @@ -239,7 +239,7 @@ } -const th_ioctx_ops th_mem_io_ops = +const th_ioctx_t_ops th_mem_io_ops = { "MemIO", diff -r 79f888e4616f -r c17eadc60c3d th_ioctx_stdio.c --- a/th_ioctx_stdio.c Sun Feb 12 14:08:09 2023 +0200 +++ b/th_ioctx_stdio.c Mon Feb 20 23:33:45 2023 +0200 @@ -11,7 +11,7 @@ #define CTX_FH ((FILE *) ctx->data) -static int th_stdio_fopen(th_ioctx *ctx) +static int th_stdio_fopen(th_ioctx_t *ctx) { ctx->data = (void *) fopen(ctx->filename, ctx->mode); ctx->status = th_get_error(); @@ -19,7 +19,7 @@ } -static void th_stdio_fclose(th_ioctx *ctx) +static void th_stdio_fclose(th_ioctx_t *ctx) { if (CTX_FH != NULL) { @@ -29,19 +29,19 @@ } -static int th_stdio_ferror(th_ioctx *ctx) +static int th_stdio_ferror(th_ioctx_t *ctx) { return ctx->status; } -static off_t th_stdio_ftell(th_ioctx *ctx) +static off_t th_stdio_ftell(th_ioctx_t *ctx) { return ftello(CTX_FH); } -static int th_stdio_fseek(th_ioctx *ctx, const off_t pos, const int whence) +static int th_stdio_fseek(th_ioctx_t *ctx, const off_t pos, const int whence) { int ret = fseeko(CTX_FH, pos, whence); ctx->status = th_get_error(); @@ -49,13 +49,13 @@ } -static int th_stdio_freset(th_ioctx *ctx) +static int th_stdio_freset(th_ioctx_t *ctx) { return th_stdio_fseek(ctx, 0, SEEK_SET); } -static off_t th_stdio_fsize(th_ioctx *ctx) +static off_t th_stdio_fsize(th_ioctx_t *ctx) { off_t savePos, fileSize; @@ -81,13 +81,13 @@ } -static bool th_stdio_feof(th_ioctx *ctx) +static bool th_stdio_feof(th_ioctx_t *ctx) { return feof(CTX_FH); } -static int th_stdio_fgetc(th_ioctx *ctx) +static int th_stdio_fgetc(th_ioctx_t *ctx) { int ret = fgetc(CTX_FH); ctx->status = th_get_error(); @@ -95,7 +95,7 @@ } -static int th_stdio_fputc(int v, th_ioctx *ctx) +static int th_stdio_fputc(int v, th_ioctx_t *ctx) { int ret = fputc(v, CTX_FH); ctx->status = th_get_error(); @@ -103,7 +103,7 @@ } -static size_t th_stdio_fread(void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) +static size_t th_stdio_fread(void *ptr, size_t size, size_t nmemb, th_ioctx_t *ctx) { size_t ret = fread(ptr, size, nmemb, CTX_FH); ctx->status = th_get_error(); @@ -111,7 +111,7 @@ } -static size_t th_stdio_fwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx *ctx) +static size_t th_stdio_fwrite(const void *ptr, size_t size, size_t nmemb, th_ioctx_t *ctx) { size_t ret = fwrite(ptr, size, nmemb, CTX_FH); ctx->status = th_get_error(); @@ -119,7 +119,7 @@ } -static char * th_stdio_fgets(char *str, int size, th_ioctx *ctx) +static char * th_stdio_fgets(char *str, int size, th_ioctx_t *ctx) { char *ret = fgets(str, size, CTX_FH); ctx->status = th_get_error(); @@ -127,7 +127,7 @@ } -static int th_stdio_fputs(const char *str, th_ioctx *ctx) +static int th_stdio_fputs(const char *str, th_ioctx_t *ctx) { int ret = fputs(str, CTX_FH); ctx->status = th_get_error(); @@ -135,7 +135,7 @@ } -static int th_stdio_vfprintf(th_ioctx *ctx, const char *fmt, va_list ap) +static int th_stdio_vfprintf(th_ioctx_t *ctx, const char *fmt, va_list ap) { int ret = vfprintf(CTX_FH, fmt, ap); ctx->status = th_get_error(); @@ -143,7 +143,7 @@ } -const th_ioctx_ops th_stdio_io_ops = +const th_ioctx_t_ops th_stdio_io_ops = { "stdio", diff -r 79f888e4616f -r c17eadc60c3d th_regex.c --- a/th_regex.c Sun Feb 12 14:08:09 2023 +0200 +++ b/th_regex.c Mon Feb 20 23:33:45 2023 +0200 @@ -9,7 +9,7 @@ #ifdef TH_EXPERIMENTAL_REGEX_DEBUG -th_ioctx *th_dbg_fh = NULL; +th_ioctx_t *th_dbg_fh = NULL; # define DBG_RE_PRINT(...) do { \ if (th_dbg_fh != NULL) \ @@ -752,14 +752,14 @@ } -static void th_regex_dump_indent(th_ioctx *fh, const int level) +static void th_regex_dump_indent(th_ioctx_t *fh, const int level) { for (int indent = 0; indent < level; indent++) thfputs(" ", fh); } -static void th_regex_dump_node(th_ioctx *fh, const th_regex_node_t *node) +static void th_regex_dump_node(th_ioctx_t *fh, const th_regex_node_t *node) { thfprintf(fh, "%s %s ", @@ -810,14 +810,14 @@ /** * Print out the contents of given regular expression structure @p expr - * in "human-readable" format to specified @c th_ioctx context. Typically + * in "human-readable" format to specified @c th_ioctx_t context. Typically * useful for debugging purposes only. * - * @param[in,out] fh th_ioctx handle to be used for output, must be writable. + * @param[in,out] fh th_ioctx.handle to be used for output, must be writable. * @param[in] level starting whitespace indentation level * @param[in] expr regular expression structure to be "dumped" */ -void th_regex_dump(th_ioctx *fh, const int level, const th_regex_t *expr) +void th_regex_dump(th_ioctx_t *fh, const int level, const th_regex_t *expr) { if (expr != NULL) { diff -r 79f888e4616f -r c17eadc60c3d th_regex.h --- a/th_regex.h Sun Feb 12 14:08:09 2023 +0200 +++ b/th_regex.h Mon Feb 20 23:33:45 2023 +0200 @@ -68,7 +68,7 @@ #ifdef TH_EXPERIMENTAL_REGEX_DEBUG -extern th_ioctx *th_dbg_fh; +extern th_ioctx_t *th_dbg_fh; #endif @@ -77,7 +77,7 @@ // int th_regex_compile(th_regex_t **pexpr, const th_char_t *pattern); void th_regex_free(th_regex_t *expr); -void th_regex_dump(th_ioctx *fh, const int level, const th_regex_t *expr); +void th_regex_dump(th_ioctx_t *fh, const int level, const th_regex_t *expr); int th_regex_match(const th_regex_t *expr, const th_char_t *haystack, size_t *pnmatches, th_regex_match_t **pmatches, const size_t maxmatches,