aboutsummaryrefslogtreecommitdiff
path: root/lib/string.c
diff options
context:
space:
mode:
authorSimon Glass <sjg@chromium.org>2021-09-25 07:03:06 -0600
committerTom Rini <trini@konsulko.com>2021-10-08 15:53:26 -0400
commit930c887e0fb88dcf1907f268960330c17999b5a3 (patch)
tree9f1bdfd36187f27d0c70b9a981974391b61014bd /lib/string.c
parent0caf37e973015255a3c5b9439ddb8c6aef1b5001 (diff)
downloadu-boot-930c887e0fb88dcf1907f268960330c17999b5a3.zip
u-boot-930c887e0fb88dcf1907f268960330c17999b5a3.tar.gz
u-boot-930c887e0fb88dcf1907f268960330c17999b5a3.tar.bz2
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/string.c')
-rw-r--r--lib/string.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/lib/string.c b/lib/string.c
index ba176fb..78bd65c 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