From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1Mz48g-0005kH-82 for qemu-devel@nongnu.org; Sat, 17 Oct 2009 03:55:46 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1Mz48b-0005ig-4q for qemu-devel@nongnu.org; Sat, 17 Oct 2009 03:55:45 -0400 Received: from [199.232.76.173] (port=40191 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mz48a-0005id-RU for qemu-devel@nongnu.org; Sat, 17 Oct 2009 03:55:40 -0400 Received: from mx1.redhat.com ([209.132.183.28]:51128) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1Mz48a-0001xH-Cx for qemu-devel@nongnu.org; Sat, 17 Oct 2009 03:55:40 -0400 Received: from int-mx04.intmail.prod.int.phx2.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.17]) by mx1.redhat.com (8.13.8/8.13.8) with ESMTP id n9H7tdr1030745 for ; Sat, 17 Oct 2009 03:55:39 -0400 From: Paolo Bonzini Date: Sat, 17 Oct 2009 09:55:30 +0200 Message-Id: <1255766136-3028-2-git-send-email-pbonzini@redhat.com> In-Reply-To: <1255766136-3028-1-git-send-email-pbonzini@redhat.com> References: <1255766136-3028-1-git-send-email-pbonzini@redhat.com> Subject: [Qemu-devel] [PATCH 1/7] add qemu_memdup List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org Cc: Luiz Capitulino A nice-to-have utility function, it helps avoiding useless strlen+strdup pairs. Cc: Luiz Capitulino Signed-off-by: Paolo Bonzini --- qemu-common.h | 1 + qemu-malloc.c | 8 ++++++++ 2 files changed, 9 insertions(+), 0 deletions(-) diff --git a/qemu-common.h b/qemu-common.h index 820dd37..351f1ac 100644 --- a/qemu-common.h +++ b/qemu-common.h @@ -141,6 +141,7 @@ void *qemu_realloc(void *ptr, size_t size); void *qemu_mallocz(size_t size); void qemu_free(void *ptr); char *qemu_strdup(const char *str); +void *qemu_memdup(const void *str, size_t size); char *qemu_strndup(const char *str, size_t size); void *get_mmap_addr(unsigned long size); diff --git a/qemu-malloc.c b/qemu-malloc.c index 295d185..9e11e4b 100644 --- a/qemu-malloc.c +++ b/qemu-malloc.c @@ -70,6 +70,14 @@ void *qemu_mallocz(size_t size) return ptr; } +void *qemu_memdup(const void *str, size_t n) +{ + char *ptr; + ptr = qemu_malloc(n); + memcpy(ptr, str, n); + return ptr; +} + char *qemu_strdup(const char *str) { char *ptr; -- 1.6.2.5