From 344273a7e0a6899451836e6072fecebea4a6ac24 Mon Sep 17 00:00:00 2001 From: Mattias Andrée Date: Wed, 10 Dec 2014 02:58:25 +0100 Subject: add xmemdup macro MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Mattias Andrée --- src/libmdsserver/linked-list.c | 36 +++++------------------------------- 1 file changed, 5 insertions(+), 31 deletions(-) (limited to 'src/libmdsserver/linked-list.c') diff --git a/src/libmdsserver/linked-list.c b/src/libmdsserver/linked-list.c index 1dea87a..602bc03 100644 --- a/src/libmdsserver/linked-list.c +++ b/src/libmdsserver/linked-list.c @@ -113,46 +113,20 @@ void linked_list_destroy(linked_list_t* restrict this) */ int linked_list_clone(const linked_list_t* restrict this, linked_list_t* restrict out) { - size_t n = this->capacity * sizeof(ssize_t); - size_t* restrict new_values = NULL; - ssize_t* restrict new_next = NULL; - ssize_t* restrict new_previous = NULL; - ssize_t* restrict new_reusable; - int saved_errno; - - out->values = NULL; - out->next = NULL; - out->previous = NULL; - out->reusable = NULL; - - fail_if (xbmalloc(new_values, n)); - fail_if (xbmalloc(new_next, n)); - fail_if (xbmalloc(new_previous, n)); - fail_if (xbmalloc(new_reusable, n)); - - out->values = new_values; - out->next = new_next; - out->previous = new_previous; - out->reusable = new_reusable; + fail_if (xmemdup(out->values, this->values, this->capacity, size_t)); + fail_if (xmemdup(out->next, this->next, this->capacity, ssize_t)); + fail_if (xmemdup(out->previous, this->previous, this->capacity, ssize_t)); + fail_if (xmemdup(out->reusable, this->reusable, this->capacity, ssize_t)); out->capacity = this->capacity; out->end = this->end; out->reuse_head = this->reuse_head; out->edge = this->edge; - memcpy(out->values, this->values, n); - memcpy(out->next, this->next, n); - memcpy(out->previous, this->previous, n); - memcpy(out->reusable, this->reusable, n); - return 0; fail: - saved_errno = errno; - free(new_values); - free(new_next); - free(new_previous); - return errno = saved_errno, -1; + return -1; } -- cgit v1.2.3-70-g09d2