# HG changeset patch # User Matti Hamalainen # Date 1583446590 -7200 # Node ID dfc2c9f0577ff392e97e377dd1a0b54ce26ef310 # Parent 18b7c2c9f8388927a4681f722c9322dc1a053bce Add functions thfopen(ctx) and thfclose(ctx) to th_ioctx. diff -r 18b7c2c9f838 -r dfc2c9f0577f th_ioctx.c --- 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) diff -r 18b7c2c9f838 -r dfc2c9f0577f th_ioctx.h --- 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);