diff options
| author | Simon Glass <[email protected]> | 2021-09-25 07:03:06 -0600 |
|---|---|---|
| committer | Tom Rini <[email protected]> | 2021-10-08 15:53:26 -0400 |
| commit | 930c887e0fb88dcf1907f268960330c17999b5a3 (patch) | |
| tree | 9f1bdfd36187f27d0c70b9a981974391b61014bd /lib/string.c | |
| parent | 0caf37e973015255a3c5b9439ddb8c6aef1b5001 (diff) | |
lib: Add memdup()
Add a function to duplicate a memory region, a little like strdup().
Signed-off-by: Simon Glass <[email protected]>
Diffstat (limited to 'lib/string.c')
| -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 ba176fb08f7..78bd65c4136 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 |
