From 85b0af8123c0eec0d472c304e3fee440beb7d2b9 Mon Sep 17 00:00:00 2001 From: Darren Salt Date: Wed, 19 Dec 2007 01:20:10 +0000 Subject: Add and use new functions for malloc+memcpy(+NUL-term) fragments. --- src/xine-utils/utils.c | 13 +++++++++++++ src/xine-utils/xineutils.h | 6 ++++++ 2 files changed, 19 insertions(+) (limited to 'src/xine-utils') diff --git a/src/xine-utils/utils.c b/src/xine-utils/utils.c index d9eb7fb3f..e6e997341 100644 --- a/src/xine-utils/utils.c +++ b/src/xine-utils/utils.c @@ -286,6 +286,19 @@ void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) { return ptr; } +void *xine_memdup (const void *src, size_t length) +{ + void *dst = malloc (length); + return xine_fast_memcpy (dst, src, length); +} + +void *xine_memdup0 (const void *src, size_t length) +{ + char *dst = xine_xmalloc (length + 1); + dst[length] = 0; + return xine_fast_memcpy (dst, src, length); +} + #ifdef WIN32 /* * Parse command line with Windows XP syntax and copy the command (argv[0]). diff --git a/src/xine-utils/xineutils.h b/src/xine-utils/xineutils.h index 4ff87e87c..89c62676b 100644 --- a/src/xine-utils/xineutils.h +++ b/src/xine-utils/xineutils.h @@ -632,6 +632,12 @@ void *xine_xcalloc(size_t nmemb, size_t size) XINE_MALLOC XINE_PROTECTED; */ void *xine_xmalloc_aligned(size_t alignment, size_t size, void **base) XINE_PROTECTED; +/* + * Copy blocks of memory. + */ +void *xine_memdup (const void *src, size_t length) XINE_MALLOC XINE_PROTECTED; +void *xine_memdup0 (const void *src, size_t length) XINE_MALLOC XINE_PROTECTED; + /* * Get user home directory. */ -- cgit v1.2.3