summaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
authorRasmus Villemoes <[email protected]>2026-04-21 09:54:31 +0200
committerTom Rini <[email protected]>2026-05-12 15:38:00 -0600
commitca1c292d2ee6bcb06be71400d25ae37e9dc2c1aa (patch)
tree23832b238f7c65f9d8de787e8b7afcef9c6417a8 /lib/string.c
parentbbc04206b5cb358e1482d06c74f2801c9ef97751 (diff)
string: fix prototype of memdup()
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 <[email protected]> Signed-off-by: Rasmus Villemoes <[email protected]>
Diffstat (limited to 'lib/string.c')
-rw-r--r--lib/string.c8
1 files changed, 3 insertions, 5 deletions
diff --git a/lib/string.c b/lib/string.c
index d56f88d4a84..c2813e0f854 100644
--- a/lib/string.c
+++ b/lib/string.c
@@ -667,17 +667,15 @@ void * memscan(void * addr, int c, size_t size)
}
#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