diff options
Diffstat (limited to '')
-rw-r--r-- | copy_error.c | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/copy_error.c b/copy_error.c new file mode 100644 index 0000000..8d93131 --- /dev/null +++ b/copy_error.c @@ -0,0 +1,31 @@ +/* See LICENSE file for copyright and license details. */ +#include "internal.h" + + +struct liberror_error * +liberror_copy_error(struct liberror_error *src) +{ + struct liberror_error *dest; + int saved_errno; + if (!src) + return NULL; + saved_errno = errno; + dest = malloc(sizeof(*dest)); + if (dest) { + memcpy(dest, src, sizeof(*src)); + if (dest->backtrace) + dest->backtrace->refcount += 1; + dest->dynamically_allocated = 1; + if (src->cause) { + dest->cause = liberror_copy_error(src->cause); + if (!dest->cause) { + if (dest->backtrace) + dest->backtrace->refcount -= 1; + free(dest); + dest = NULL; + } + } + } + errno = saved_errno; + return dest; +} |