lib: Add memdup()

Add a function to duplicate a memory region, a little like strdup().

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass
2021-09-25 07:03:06 -06:00
committed by Tom Rini
parent 0caf37e973
commit 930c887e0f
3 changed files with 58 additions and 0 deletions

View File

@@ -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