# HG changeset patch # User Matti Hamalainen # Date 1583763721 -7200 # Node ID 49c818acbbbef276104417f5b70ea5c8e4be76f7 # Parent 953e16582f257dc4468a99dd382d64e665a22786 Cleanups. diff -r 953e16582f25 -r 49c818acbbbe th_ioctx.c --- a/th_ioctx.c Mon Mar 09 15:46:01 2020 +0200 +++ b/th_ioctx.c Mon Mar 09 16:22:01 2020 +0200 @@ -170,12 +170,13 @@ } +// thfopen() and thfclose() implementations are allowed to be NULL int thfopen(th_ioctx *ctx) { - if (ctx == NULL) + if (ctx == NULL || ctx->fops == NULL) return THERR_NULLPTR; - if (ctx->fops == NULL || ctx->fops->fopen == NULL) + if (ctx->fops->fopen == NULL) return THERR_OK; return ctx->fops->fopen(ctx); @@ -184,21 +185,17 @@ void thfclose(th_ioctx *ctx) { - if (ctx != NULL && - ctx->fops == NULL && - ctx->fops->fclose == NULL) + if (ctx == NULL || ctx->fops == NULL) + return; + + if (ctx->fops->fclose != NULL) ctx->fops->fclose(ctx); } int thfreset(th_ioctx *ctx) { - if (ctx == NULL) - return THERR_NULLPTR; - - if (ctx->fops == NULL || ctx->fops->freset == NULL) - return THERR_OK; - + th_io_update_atime(ctx); return ctx->fops->freset(ctx); } @@ -325,7 +322,7 @@ BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len) { - return (thfread(ptr, sizeof(uint8_t), len, ctx) == len); + return thfread(ptr, sizeof(uint8_t), len, ctx) == len; } @@ -337,13 +334,13 @@ BOOL thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len) { - return (thfwrite(ptr, sizeof(uint8_t), len, ctx) == len); + return thfwrite(ptr, sizeof(uint8_t), len, ctx) == len; } BOOL thfwrite_u8(th_ioctx *ctx, const uint8_t val) { - return (thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1); + return thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1; } diff -r 953e16582f25 -r 49c818acbbbe th_ioctx_stdio.c --- a/th_ioctx_stdio.c Mon Mar 09 15:46:01 2020 +0200 +++ b/th_ioctx_stdio.c Mon Mar 09 16:22:01 2020 +0200 @@ -51,10 +51,7 @@ static int th_stdio_freset(th_ioctx *ctx) { - if (CTX_FH != NULL) - return th_stdio_fseek(ctx, 0, SEEK_SET); - else - return THERR_OK; + return th_stdio_fseek(ctx, 0, SEEK_SET); }