diff th_ioctx.c @ 691:49c818acbbbe

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 16:22:01 +0200
parents dfc2c9f0577f
children a04b8fe158b9
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;
 }