aboutsummaryrefslogtreecommitdiffstats
path: root/set_error.c
diff options
context:
space:
mode:
authorMattias Andrée <maandree@kth.se>2019-04-14 14:42:27 +0200
committerMattias Andrée <maandree@kth.se>2019-04-14 14:42:27 +0200
commit5762e83f854fb15c9881b720fdef61f367787149 (patch)
tree7cdff2c12dd68001e47b5209ddbbd02a2b761248 /set_error.c
parentAdd liberror.h.0 (diff)
downloadliberror-5762e83f854fb15c9881b720fdef61f367787149.tar.gz
liberror-5762e83f854fb15c9881b720fdef61f367787149.tar.bz2
liberror-5762e83f854fb15c9881b720fdef61f367787149.tar.xz
Add support for h_errno and getaddrinfo errors1.0
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'set_error.c')
-rw-r--r--set_error.c19
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);