'memdup' function in C?
There is void *xmemdup (void const *p, size_t s)
in GNU Gnulib's xalloc.h
.
Note that it calls xalloc_die
in case of insufficient memory.
You can implement it whith a simple function:
void* memdup(const void* mem, size_t size) {
void* out = malloc(size);
if(out != NULL)
memcpy(out, mem, size);
return out;
}