diff --git a/src/kernel/libroot/posix/string/strdup.c b/src/kernel/libroot/posix/string/strdup.c new file mode 100644 index 0000000000..7ab28a6baa --- /dev/null +++ b/src/kernel/libroot/posix/string/strdup.c @@ -0,0 +1,30 @@ +/* +** Copyright 2003, Axel Dörfler, axeld@pinc-software.de. All rights reserved. +** Distributed under the terms of the OpenBeOS License. +*/ + + +#include +#include + + +char * +strdup(const char *string) +{ + char *copied; + size_t length; + + // unlike the standard strdup() function, the BeOS implementation + // handles NULL strings gracefully + if (string == NULL) + return NULL; + + length = strlen(string) + 1; + + if ((copied = (char *)malloc(length)) == NULL) + return NULL; + + memcpy(copied, string, length); + return copied; +} +