char * strdup(const char * s)
{
size_t len = 1+strlen(s);
char *p = malloc(len);
return p ? memcpy(p, s, len) : NULL;
}
Maybe the code is a bit faster than with strcpy()
as the \0
char doesn't need to be searched again (It already was with strlen()
).