Mercurial > hg > th-libs
comparison th_ioctx.c @ 208:3635415a2d03
More work on th_ioctx stuff and wrappers.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Fri, 12 Feb 2016 02:49:21 +0200 |
parents | c2193323736d |
children | 462b837ea492 |
comparison
equal
deleted
inserted
replaced
207:75dbac8f2f59 | 208:3635415a2d03 |
---|---|
226 break; | 226 break; |
227 } | 227 } |
228 *ptr = 0; | 228 *ptr = 0; |
229 | 229 |
230 return (ptr > str) ? str : NULL; | 230 return (ptr > str) ? str : NULL; |
231 } | |
232 | |
233 | |
234 int thfputs(const char *ptr, th_ioctx *ctx) | |
235 { | |
236 if (ctx->fops->fputs != NULL) | |
237 return ctx->fops->fputs(ptr, ctx); | |
238 | |
239 const char *p = ptr; | |
240 int retv = 0; | |
241 while (*p && (retv = ctx->fops->fputc(*p, ctx)) != EOF) p++; | |
242 return retv; | |
243 } | |
244 | |
245 | |
246 int thvfprintf(th_ioctx *ctx, const char *fmt, va_list ap) | |
247 { | |
248 if (ctx->fops->vfprintf != NULL) | |
249 return ctx->fops->vfprintf(ctx, fmt, ap); | |
250 else | |
251 { | |
252 char *msg = th_strdup_printf(fmt, ap); | |
253 int rval = thfputs(msg, ctx); | |
254 th_free(msg); | |
255 return rval; | |
256 } | |
257 } | |
258 | |
259 | |
260 int thfprintf(th_ioctx *ctx, const char *fmt, ...) | |
261 { | |
262 int retv; | |
263 va_list ap; | |
264 va_start(ap, fmt); | |
265 retv = thvfprintf(ctx, fmt, ap); | |
266 va_end(ap); | |
267 return retv; | |
231 } | 268 } |
232 | 269 |
233 | 270 |
234 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len) | 271 BOOL thfread_str(th_ioctx *ctx, void *ptr, const size_t len) |
235 { | 272 { |
406 ctx->errno = th_get_error(); | 443 ctx->errno = th_get_error(); |
407 return ret; | 444 return ret; |
408 } | 445 } |
409 | 446 |
410 | 447 |
411 static int th_stdio_vfprintf(th_ioctx *ctx, const char *format, va_list ap) | 448 static char * th_stdio_fgets(char *str, int size, th_ioctx *ctx) |
412 { | 449 { |
413 int ret = vfprintf(CTX_FH, format, ap); | 450 char *ret = fgets(str, size, CTX_FH); |
451 ctx->errno = th_get_error(); | |
452 return ret; | |
453 } | |
454 | |
455 | |
456 static int th_stdio_fputs(const char *str, th_ioctx *ctx) | |
457 { | |
458 int ret = fputs(str, CTX_FH); | |
459 ctx->errno = th_get_error(); | |
460 return ret; | |
461 } | |
462 | |
463 | |
464 static int th_stdio_vfprintf(th_ioctx *ctx, const char *fmt, va_list ap) | |
465 { | |
466 int ret = vfprintf(CTX_FH, fmt, ap); | |
414 ctx->errno = th_get_error(); | 467 ctx->errno = th_get_error(); |
415 return ret; | 468 return ret; |
416 } | 469 } |
417 | 470 |
418 | 471 |
432 th_stdio_fgetc, | 485 th_stdio_fgetc, |
433 th_stdio_fputc, | 486 th_stdio_fputc, |
434 th_stdio_fread, | 487 th_stdio_fread, |
435 th_stdio_fwrite, | 488 th_stdio_fwrite, |
436 | 489 |
490 th_stdio_fgets, | |
491 th_stdio_fputs, | |
437 th_stdio_vfprintf, | 492 th_stdio_vfprintf, |
438 }; | 493 }; |
439 | 494 |