Mercurial > hg > th-libs
diff th_ioctx.c @ 72:43df05a632cb
Break I/O context API, add function pointers to init/open/new functions.
author | Matti Hamalainen <ccr@tnsp.org> |
---|---|
date | Thu, 15 Nov 2012 19:52:09 +0200 |
parents | ce49160d2599 |
children | 3882efea2640 |
line wrap: on
line diff
--- a/th_ioctx.c Thu Nov 15 19:44:59 2012 +0200 +++ b/th_ioctx.c Thu Nov 15 19:52:09 2012 +0200 @@ -10,12 +10,17 @@ /* Simple STD I/O contexts */ -BOOL th_ioctx_init(th_ioctx_t *ctx, const char *filename) +BOOL th_ioctx_init(th_ioctx_t *ctx, const char *filename, + void (*error)(struct _th_ioctx_t *, const int, const char *msg), + void (*msg)(struct _th_ioctx_t *, const char *msg)) + { if (ctx == NULL || filename == NULL) return FALSE; th_memset(ctx, 0, sizeof(ctx)); + ctx->error = error; + ctx->msg = msg; if ((ctx->filename = th_strdup(filename)) == NULL) return FALSE; @@ -24,9 +29,11 @@ } -BOOL th_ioctx_open(th_ioctx_t *ctx, const char *filename, const char *mode) +BOOL th_ioctx_open(th_ioctx_t *ctx, const char *filename, const char *mode, + void (*error)(struct _th_ioctx_t *, const int, const char *msg), + void (*msg)(struct _th_ioctx_t *, const char *msg)) { - if (!th_ioctx_init(ctx, filename) || mode == NULL) + if (!th_ioctx_init(ctx, filename, error, msg) || mode == NULL) return FALSE; if ((ctx->fp = fopen(filename, mode)) == NULL) @@ -68,13 +75,15 @@ } -th_ioctx_t *th_ioctx_new(const char *filename) +th_ioctx_t *th_ioctx_new(const char *filename, + void (*error)(struct _th_ioctx_t *, const int, const char *msg), + void (*msg)(struct _th_ioctx_t *, const char *msg)) { th_ioctx_t *ctx = th_malloc0(sizeof(th_ioctx_t)); if (ctx == NULL) return NULL; - th_ioctx_init(ctx, filename); + th_ioctx_init(ctx, filename, error, msg); ctx->allocated = TRUE; return ctx; }