diff options
author | Simon Glass <sjg@chromium.org> | 2021-09-25 16:03:06 +0300 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2021-10-08 22:53:26 +0300 |
commit | 930c887e0fb88dcf1907f268960330c17999b5a3 (patch) | |
tree | 9f1bdfd36187f27d0c70b9a981974391b61014bd /lib | |
parent | 0caf37e973015255a3c5b9439ddb8c6aef1b5001 (diff) | |
download | u-boot-930c887e0fb88dcf1907f268960330c17999b5a3.tar.xz |
lib: Add memdup()
Add a function to duplicate a memory region, a little like strdup().
Signed-off-by: Simon Glass <sjg@chromium.org>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/string.c | 13 |
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c index ba176fb08f..78bd65c413 100644 --- a/lib/string.c +++ b/lib/string.c @@ -659,6 +659,19 @@ void * memscan(void * addr, int c, size_t size) } #endif +char *memdup(const void *src, size_t len) +{ + char *p; + + p = malloc(len); + if (!p) + return NULL; + + memcpy(p, src, len); + + return p; +} + #ifndef __HAVE_ARCH_STRSTR /** * strstr - Find the first substring in a %NUL terminated string |