comparison th_ioctx.c @ 691:49c818acbbbe

Cleanups.
author Matti Hamalainen <ccr@tnsp.org>
date Mon, 09 Mar 2020 16:22:01 +0200
parents dfc2c9f0577f
children a04b8fe158b9
comparison
equal deleted inserted replaced
690:953e16582f25 691:49c818acbbbe
168 th_io_msg_v(ctx, level, fmt, ap); 168 th_io_msg_v(ctx, level, fmt, ap);
169 va_end(ap); 169 va_end(ap);
170 } 170 }
171 171
172 172
173 // thfopen() and thfclose() implementations are allowed to be NULL
173 int thfopen(th_ioctx *ctx) 174 int thfopen(th_ioctx *ctx)
174 { 175 {
175 if (ctx == NULL) 176 if (ctx == NULL || ctx->fops == NULL)
176 return THERR_NULLPTR; 177 return THERR_NULLPTR;
177 178
178 if (ctx->fops == NULL || ctx->fops->fopen == NULL) 179 if (ctx->fops->fopen == NULL)
179 return THERR_OK; 180 return THERR_OK;
180 181
181 return ctx->fops->fopen(ctx); 182 return ctx->fops->fopen(ctx);
182 } 183 }
183 184
184 185
185 void thfclose(th_ioctx *ctx) 186 void thfclose(th_ioctx *ctx)
186 { 187 {
187 if (ctx != NULL && 188 if (ctx == NULL || ctx->fops == NULL)
188 ctx->fops == NULL && 189 return;
189 ctx->fops->fclose == NULL) 190
191 if (ctx->fops->fclose != NULL)
190 ctx->fops->fclose(ctx); 192 ctx->fops->fclose(ctx);
191 } 193 }
192 194
193 195
194 int thfreset(th_ioctx *ctx) 196 int thfreset(th_ioctx *ctx)
195 { 197 {
196 if (ctx == NULL) 198 th_io_update_atime(ctx);
197 return THERR_NULLPTR;
198
199 if (ctx->fops == NULL || ctx->fops->freset == NULL)
200 return THERR_OK;
201
202 return ctx->fops->freset(ctx); 199 return ctx->fops->freset(ctx);
203 } 200 }
204 201
205 202
206 int thferror(th_ioctx *ctx) 203 int thferror(th_ioctx *ctx)
323 } 320 }
324 321
325 322
326 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len) 323 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len)
327 { 324 {
328 return (thfread(ptr, sizeof(uint8_t), len, ctx) == len); 325 return thfread(ptr, sizeof(uint8_t), len, ctx) == len;
329 } 326 }
330 327
331 328
332 BOOL thfread_u8(th_ioctx *ctx, uint8_t *val) 329 BOOL thfread_u8(th_ioctx *ctx, uint8_t *val)
333 { 330 {
335 } 332 }
336 333
337 334
338 BOOL thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len) 335 BOOL thfwrite_str(th_ioctx *ctx, const void *ptr, const size_t len)
339 { 336 {
340 return (thfwrite(ptr, sizeof(uint8_t), len, ctx) == len); 337 return thfwrite(ptr, sizeof(uint8_t), len, ctx) == len;
341 } 338 }
342 339
343 340
344 BOOL thfwrite_u8(th_ioctx *ctx, const uint8_t val) 341 BOOL thfwrite_u8(th_ioctx *ctx, const uint8_t val)
345 { 342 {
346 return (thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1); 343 return thfwrite(&val, sizeof(uint8_t), 1, ctx) == 1;
347 } 344 }
348 345
349 346
350 // 347 //
351 // File routines for endian-dependant data 348 // File routines for endian-dependant data