diff options
Diffstat (limited to 'set_error.c')
-rw-r--r-- | set_error.c | 16 |
1 files changed, 11 insertions, 5 deletions
diff --git a/set_error.c b/set_error.c index 5ee54ce..fa65141 100644 --- a/set_error.c +++ b/set_error.c @@ -5,13 +5,19 @@ void liberror_set_error(const char description[256], const char source[64], const char code_group[64], long long int code) { - struct liberror_error *cause; + struct liberror_error *cause = NULL, *old; struct liberror_error *error; - int have_cause; + int have_cause = 0, saved_errno; - cause = liberror_get_error(); - have_cause = !!cause; - cause = liberror_copy_error(cause); + old = liberror_get_error(); + if (old) { + have_cause = 1; + saved_errno = errno; + cause = malloc(sizeof(*cause)); + errno = saved_errno; + if (cause) + memcpy(cause, old, sizeof(*cause)); + } error = &liberror_error_; liberror_have_error_ = 1; |