Mercurial > hg > th-libs
diff th_ioctx.c @ 700:ec8fe89576ff
Adjust th_ioctx API. Breakage.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Tue, 10 Mar 2020 17:01:10 +0200 |
parents | 3707a823aa02 |
children | 4ca6a3b30fe8 |
line wrap: on
line diff
--- a/th_ioctx.c Tue Mar 10 16:51:55 2020 +0200 +++ b/th_ioctx.c Tue Mar 10 17:01:10 2020 +0200 @@ -32,7 +32,7 @@ } -th_ioctx * th_io_new(const th_ioctx_ops *fops, const char *filename) +th_ioctx * th_io_new(const th_ioctx_ops *fops, const char *filename, const char *mode) { th_ioctx *ctx = th_malloc(sizeof(th_ioctx)); if (ctx == NULL) @@ -48,6 +48,11 @@ if (filename != NULL && ctx->filename == NULL) goto err; + if (mode != NULL && (ctx->mode = th_strdup(mode)) == NULL) + goto err; + + ctx->mallocated = TRUE; + return ctx; err: @@ -56,31 +61,15 @@ } -int th_io_open(th_ioctx *ctx, const char *mode) -{ - if (ctx == NULL) - return THERR_NULLPTR; - - if (mode != NULL && (ctx->mode = th_strdup(mode)) == NULL) - return THERR_MALLOC; - - ctx->mallocated = TRUE; - - ctx->status = thfopen(ctx); - - return ctx->status; -} - - int th_io_fopen(th_ioctx **pctx, const th_ioctx_ops *fops, const char *filename, const char *mode) { th_ioctx *ctx; int res; - if ((*pctx = ctx = th_io_new(fops, filename)) == NULL) + if ((*pctx = ctx = th_io_new(fops, filename, mode)) == NULL) return THERR_MALLOC; - if ((res = th_io_open(ctx, mode)) != THERR_OK) + if ((res = thfopen(ctx)) != THERR_OK) goto err; return THERR_OK;