comparison th_ioctx.c @ 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 7e207f1023d9
children 49c818acbbbe
comparison
equal deleted inserted replaced
685:18b7c2c9f838 686:dfc2c9f0577f
64 if (mode != NULL && (ctx->mode = th_strdup(mode)) == NULL) 64 if (mode != NULL && (ctx->mode = th_strdup(mode)) == NULL)
65 return THERR_MALLOC; 65 return THERR_MALLOC;
66 66
67 ctx->mallocated = TRUE; 67 ctx->mallocated = TRUE;
68 68
69 if (ctx->fops->fopen != NULL) 69 ctx->status = thfopen(ctx);
70 ctx->status = ctx->fops->fopen(ctx);
71 70
72 return ctx->status; 71 return ctx->status;
73 } 72 }
74 73
75 74
95 94
96 void th_io_close(th_ioctx *ctx) 95 void th_io_close(th_ioctx *ctx)
97 { 96 {
98 if (ctx != NULL) 97 if (ctx != NULL)
99 { 98 {
100 if (ctx->fops != NULL && ctx->fops->fclose != NULL) 99 thfclose(ctx);
101 ctx->fops->fclose(ctx);
102 100
103 if (ctx->fallocated) 101 if (ctx->fallocated)
104 th_free_r(&ctx->filename); 102 th_free_r(&ctx->filename);
105 103
106 if (ctx->mallocated) 104 if (ctx->mallocated)
167 { 165 {
168 va_list ap; 166 va_list ap;
169 va_start(ap, fmt); 167 va_start(ap, fmt);
170 th_io_msg_v(ctx, level, fmt, ap); 168 th_io_msg_v(ctx, level, fmt, ap);
171 va_end(ap); 169 va_end(ap);
170 }
171
172
173 int thfopen(th_ioctx *ctx)
174 {
175 if (ctx == NULL)
176 return THERR_NULLPTR;
177
178 if (ctx->fops == NULL || ctx->fops->fopen == NULL)
179 return THERR_OK;
180
181 return ctx->fops->fopen(ctx);
182 }
183
184
185 void thfclose(th_ioctx *ctx)
186 {
187 if (ctx != NULL &&
188 ctx->fops == NULL &&
189 ctx->fops->fclose == NULL)
190 ctx->fops->fclose(ctx);
172 } 191 }
173 192
174 193
175 int thfreset(th_ioctx *ctx) 194 int thfreset(th_ioctx *ctx)
176 { 195 {