diff options
author | Mattias Andrée <maandree@kth.se> | 2019-04-14 14:42:27 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-04-14 14:42:27 +0200 |
commit | 5762e83f854fb15c9881b720fdef61f367787149 (patch) | |
tree | 7cdff2c12dd68001e47b5209ddbbd02a2b761248 /set_error.c | |
parent | Add liberror.h.0 (diff) | |
download | liberror-1.0.tar.gz liberror-1.0.tar.bz2 liberror-1.0.tar.xz |
Add support for h_errno and getaddrinfo errors1.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to '')
-rw-r--r-- | set_error.c | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/set_error.c b/set_error.c index a44aac6..e7a16ac 100644 --- a/set_error.c +++ b/set_error.c @@ -8,6 +8,7 @@ liberror_set_error(const char description[256], const char source[64], const cha struct liberror_error *cause = NULL, *old; struct liberror_error *error; int have_cause = 0, saved_errno; + const char *errstr; old = liberror_get_error(); if (old) { @@ -29,6 +30,24 @@ liberror_set_error(const char description[256], const char source[64], const cha } else if (!strcmp(code_group, "errno")) { if (code >= (long long int)INT_MIN && code <= (long long int)INT_MAX) strerror_r((int)code, error->description, sizeof(error->description)); + } else if (!strcmp(code_group, "h_errno")) { + if (code >= (long long int)INT_MIN && code <= (long long int)INT_MAX) { + saved_errno = errno; + errstr = hstrerror(code); + if (errstr) + strncpy(error->description, errstr, sizeof(error->description)); + errno = saved_errno; + } + } else if (!strcmp(code_group, "addrinfo")) { + if (code == (long long int)EAI_SYSTEM) { + strerror_r(errno, error->description, sizeof(error->description)); + } else if (code >= (long long int)INT_MIN && code <= (long long int)INT_MAX) { + saved_errno = errno; + errstr = gai_strerror(code); + if (errstr) + strncpy(error->description, errstr, sizeof(error->description)); + errno = saved_errno; + } } stpcpy(error->source, source); stpcpy(error->code_group, code_group); |