It doesn't make sense to restrict memdup() to only return char*
pointers, especially when it is already defined to accept void*. This
makes it uglier to use to e.g. duplicate a struct.
Make it return void*, just as kmemdup() does in the kernel (and which
our kmemdup() in fact also does).
While in here, make a small optimization: memcpy() is defined to
return the destination register, so we write this in a way that the
compiler may do a tail call.
Reviewed-by: Simon Glass <sjg@chromium.org>
Signed-off-by: Rasmus Villemoes <ravi@prevas.dk>
* memory is available
*
*/
-char *memdup(const void *src, size_t len);
+void *memdup(const void *src, size_t len);
unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
}
#endif
-char *memdup(const void *src, size_t len)
+void *memdup(const void *src, size_t len)
{
- char *p;
+ void *p;
p = malloc(len);
if (!p)
return NULL;
- memcpy(p, src, len);
-
- return p;
+ return memcpy(p, src, len);
}
#ifndef __HAVE_ARCH_STRNSTR