changeset 695:a04b8fe158b9

Add helper function th_io_reopen().
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 19:05:58 +0200
parents 0fc5ddaccc57
children 9bbacd72df3d
files th_ioctx.c th_ioctx.h
diffstat 2 files changed, 14 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/th_ioctx.c	Mon Mar 09 18:55:54 2020 +0200
+++ b/th_ioctx.c	Mon Mar 09 19:05:58 2020 +0200
@@ -92,6 +92,19 @@
 }
 
 
+int th_io_reopen(th_ioctx *ctx, const char *mode)
+{
+    if (ctx == NULL)
+        return THERR_NULLPTR;
+
+    thfclose(ctx);
+
+    th_pstr_cpy(&ctx->mode, mode);
+
+    return (ctx->status = thfopen(ctx));
+}
+
+
 void th_io_close(th_ioctx *ctx)
 {
     if (ctx != NULL)
--- a/th_ioctx.h	Mon Mar 09 18:55:54 2020 +0200
+++ b/th_ioctx.h	Mon Mar 09 19:05:58 2020 +0200
@@ -98,6 +98,7 @@
 th_ioctx *   th_io_new(const th_ioctx_ops *fops, const char *filename);
 int          th_io_open(th_ioctx *ctx, 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);
 
 void         th_io_init_stdio(th_ioctx *ctx, FILE *fh);