Convert strdup.c to C++.
This commit is contained in:
@@ -21,7 +21,7 @@ BootMergeObject boot_libroot.o :
|
||||
memchr.c
|
||||
memcmp.c
|
||||
memmove.c
|
||||
strdup.c
|
||||
strdup.cpp
|
||||
strndup.cpp
|
||||
strlen.cpp
|
||||
strnlen.cpp
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
Reference in New Issue
Block a user