diff options
| author | Mattias Andrée <maandree@kth.se> | 2016-03-04 23:50:00 +0100 |
|---|---|---|
| committer | Mattias Andrée <maandree@kth.se> | 2016-03-04 23:50:00 +0100 |
| commit | 76d0af5599554d11f104d582cdac8fbaa8569fcc (patch) | |
| tree | 0ed9889a86d52ebd208382f2fd49dad0570d1f8c /src/internals.h | |
| parent | Clean up, fix a few bugs, and add a test (diff) | |
| download | libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.gz libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.bz2 libzahl-76d0af5599554d11f104d582cdac8fbaa8569fcc.tar.xz | |
Clean up, add zerror and zperror, fix bugs and add more tests
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'src/internals.h')
| -rw-r--r-- | src/internals.h | 10 |
1 files changed, 7 insertions, 3 deletions
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; } |
