From 76d0af5599554d11f104d582cdac8fbaa8569fcc Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Fri, 4 Mar 2016 23:50:00 +0100 Subject: Clean up, add zerror and zperror, fix bugs and add more tests MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/internals.h | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) (limited to 'src/internals.h') diff --git a/src/internals.h b/src/internals.h index 5b1f9c3..9f276db 100644 --- a/src/internals.h +++ b/src/internals.h @@ -54,8 +54,9 @@ LIST_CONSTS extern z_t libzahl_tmp_divmod_ds[BITS_PER_CHAR]; extern jmp_buf libzahl_jmp_buf; extern int libzahl_set_up; +extern int libzahl_error; -#define FAILURE_JUMP() longjmp(libzahl_jmp_buf, 1) +#define FAILURE(error) (libzahl_error = (error), longjmp(libzahl_jmp_buf, 1)) #define zmemcpy(d, s, n) memcpy(d, s, (n) * sizeof(zahl_char_t)) #define zmemmove(d, s, n) memmove(d, s, (n) * sizeof(zahl_char_t)) #define zmemset(a, v, n) memset(a, v, (n) * sizeof(zahl_char_t)) @@ -72,7 +73,10 @@ static inline void zahl_realloc(z_t p, size_t n) { p->chars = realloc(p->chars, n * sizeof(zahl_char_t)); - if (!p->chars) - FAILURE_JUMP(); + if (!p->chars) { + if (!errno) /* sigh... */ + errno = ENOMEM; + FAILURE(errno); + } p->alloced = n; } -- cgit v1.2.3-70-g09d2