changeset 691:49c818acbbbe

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 16:22:01 +0200
parents 953e16582f25
children ea6bcbfb9d18
files th_ioctx.c th_ioctx_stdio.c
diffstat 2 files changed, 12 insertions(+), 18 deletions(-) [+]
line wrap: on
line diff
--- 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;
 }
 
 
--- 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);
 }