Convert strdup.c to C++.

This commit is contained in:
Adrien Destugues
2014-05-23 18:30:26 +02:00
parent 5710ad967d
commit 5e36a367d7
4 changed files with 9 additions and 32 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ BootMergeObject boot_libroot.o :
memchr.c
memcmp.c
memmove.c
strdup.c
strdup.cpp
strndup.cpp
strlen.cpp
strnlen.cpp
+1 -1
View File
@@ -107,7 +107,7 @@ KernelMergeObject kernel_lib_posix.o :
strcmp.c
strcpy.c
strcspn.c
strdup.c
strdup.cpp
strerror.c
strlcat.c
strlcpy.c
+7 -1
View File
@@ -5,6 +5,12 @@ UsePrivateHeaders
[ FDirName libroot locale ]
;
# Our versions of strdup and strndup check for NULL parameters (for BeOS
# compatibility), but GCC optimizes this away as its builtins don't handle
# it.
C++FLAGS += -fno-builtin-strdup -fno-builtin-strndup ;
local architectureObject ;
for architectureObject in [ MultiArchSubDirSetup ] {
on $(architectureObject) {
@@ -29,7 +35,7 @@ for architectureObject in [ MultiArchSubDirSetup ] {
strcoll.cpp
strcpy.c
strcspn.c
strdup.c
strdup.cpp
strerror.c
strlcat.c
strlcpy.c
-29
View File
@@ -1,29 +0,0 @@
/*
* Copyright 2003-2007, Axel Dörfler, [email protected]. All rights reserved.
* Distributed under the terms of the MIT 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;
}