From 5762e83f854fb15c9881b720fdef61f367787149 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Sun, 14 Apr 2019 14:42:27 +0200 Subject: Add support for h_errno and getaddrinfo errors MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- internal.h | 2 ++ set_error.c | 19 +++++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/internal.h b/internal.h index db33be9..3e22586 100644 --- a/internal.h +++ b/internal.h @@ -1,10 +1,12 @@ /* See LICENSE file for copyright and license details. */ #include "liberror.h" +#include #include #include #include #include +#include #include #include #include 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); -- cgit v1.2.3-70-g09d2