aboutsummaryrefslogtreecommitdiffstats
path: root/copy_error.c
blob: 8d931311ba5f37f67a04c21aa0e055854c8f9e3d (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
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;
}