diff options
-rw-r--r-- | internal.h | 2 | ||||
-rw-r--r-- | set_error.c | 19 |
2 files changed, 21 insertions, 0 deletions
@@ -1,10 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include "liberror.h" +#include <sys/socket.h> #include <alloca.h> #include <errno.h> #include <inttypes.h> #include <limits.h> +#include <netdb.h> #include <stdlib.h> #include <string.h> #include <unistd.h> 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); |