changeset 686:dfc2c9f0577f

Add functions thfopen(ctx) and thfclose(ctx) to th_ioctx.
author Matti Hamalainen <ccr@tnsp.org>
date Fri, 06 Mar 2020 00:16:30 +0200
parents 18b7c2c9f838
children 5a7254b78614
files th_ioctx.c th_ioctx.h
diffstat 2 files changed, 26 insertions(+), 4 deletions(-) [+]
line wrap: on
line diff
--- a/th_ioctx.c	Thu Mar 05 00:12:16 2020 +0200
+++ b/th_ioctx.c	Fri Mar 06 00:16:30 2020 +0200
@@ -66,8 +66,7 @@
 
     ctx->mallocated = TRUE;
 
-    if (ctx->fops->fopen != NULL)
-        ctx->status = ctx->fops->fopen(ctx);
+    ctx->status = thfopen(ctx);
 
     return ctx->status;
 }
@@ -97,8 +96,7 @@
 {
     if (ctx != NULL)
     {
-        if (ctx->fops != NULL && ctx->fops->fclose != NULL)
-            ctx->fops->fclose(ctx);
+        thfclose(ctx);
 
         if (ctx->fallocated)
             th_free_r(&ctx->filename);
@@ -172,6 +170,27 @@
 }
 
 
+int thfopen(th_ioctx *ctx)
+{
+    if (ctx == NULL)
+        return THERR_NULLPTR;
+
+    if (ctx->fops == NULL || ctx->fops->fopen == NULL)
+        return THERR_OK;
+
+    return ctx->fops->fopen(ctx);
+}
+
+
+void thfclose(th_ioctx *ctx)
+{
+    if (ctx != NULL &&
+        ctx->fops == NULL &&
+        ctx->fops->fclose == NULL)
+        ctx->fops->fclose(ctx);
+}
+
+
 int thfreset(th_ioctx *ctx)
 {
     if (ctx == NULL)
--- a/th_ioctx.h	Thu Mar 05 00:12:16 2020 +0200
+++ b/th_ioctx.h	Fri Mar 06 00:16:30 2020 +0200
@@ -115,6 +115,9 @@
 //
 // Basic I/O operations
 //
+int          thfopen(th_ioctx *ctx);
+void         thfclose(th_ioctx *ctx);
+
 int          thfreset(th_ioctx *ctx);
 int          thferror(th_ioctx *ctx);
 int          thfseek(th_ioctx *ctx, const off_t, const int whence);