diff options
author | Mattias Andrée <maandree@kth.se> | 2019-04-12 22:32:26 +0200 |
---|---|---|
committer | Mattias Andrée <maandree@kth.se> | 2019-04-12 22:32:26 +0200 |
commit | 5012504d2f215002a429b14f238ebfc1d0029c05 (patch) | |
tree | 7d70dbbdef6c93da503683c30b6c6d2e90f36881 /copy_error.c | |
parent | Add readme (diff) | |
download | liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.gz liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.bz2 liberror-5012504d2f215002a429b14f238ebfc1d0029c05.tar.xz |
Add support for extended details
Signed-off-by: Mattias Andrée <maandree@kth.se>
Diffstat (limited to 'copy_error.c')
-rw-r--r-- | copy_error.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/copy_error.c b/copy_error.c index 8d93131..ebf71b4 100644 --- a/copy_error.c +++ b/copy_error.c @@ -2,6 +2,8 @@ #include "internal.h" +#define STRDUP(S) ((S) ? strdup(S) : NULL) + struct liberror_error * liberror_copy_error(struct liberror_error *src) { @@ -16,6 +18,7 @@ liberror_copy_error(struct liberror_error *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) { @@ -25,7 +28,39 @@ liberror_copy_error(struct liberror_error *src) dest = NULL; } } + + switch (dest->details_type) { + case LIBERROR_DETAILS_USER: + dest->details.user.data = dest->details.user.copy_data(dest->details.user.data); + if (!dest->details.user.data) + goto fail; + break; + + case LIBERROR_DETAILS_ONE_FILE: + dest->details.one_file.name = STRDUP(src->details.one_file.name); + if (src->details.one_file.name && !dest->details.one_file.name) + goto fail; + break; + + case LIBERROR_DETAILS_TWO_FILES: + dest->details.two_files.name1 = STRDUP(src->details.two_files.name1); + dest->details.two_files.name2 = STRDUP(src->details.two_files.name2); + if (src->details.two_files.name1 && !dest->details.two_files.name1) + goto fail; + if (src->details.two_files.name2 && !dest->details.two_files.name2) + goto fail; + break; + + case LIBERROR_DETAILS_NONE: + default: + break; + } } errno = saved_errno; return dest; + +fail: + liberror_free_error(dest); + errno = saved_errno; + return NULL; } |