Added a BeOS compatible strdup() implementation; unlike other strdup()

implementations (and against its standard behaviour), it does now
handle a NULL string parameter gracefully.


git-svn-id: file:///srv/svn/repos/haiku/trunk/current@3485 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
Axel Dörfler
2003-06-12 19:35:33 +00:00
parent 0c6fce04e6
commit f3df767f76
+30
View File
@@ -0,0 +1,30 @@
/*
** Copyright 2003, Axel Dörfler, [email protected]. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
#include <string.h>
#include <stdlib.h>
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;
}