From 5e36a367d7edc677c0183c7a6fc6b6ec5bb40cf1 Mon Sep 17 00:00:00 2001 From: Adrien Destugues Date: Fri, 23 May 2014 18:30:26 +0200 Subject: [PATCH] Convert strdup.c to C++. --- src/system/boot/Jamfile | 2 +- src/system/kernel/lib/Jamfile | 2 +- src/system/libroot/posix/string/Jamfile | 8 ++++++- src/system/libroot/posix/string/strdup.c | 29 ------------------------ 4 files changed, 9 insertions(+), 32 deletions(-) delete mode 100644 src/system/libroot/posix/string/strdup.c diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 3c704f9650..46aecb6823 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -21,7 +21,7 @@ BootMergeObject boot_libroot.o : memchr.c memcmp.c memmove.c - strdup.c + strdup.cpp strndup.cpp strlen.cpp strnlen.cpp diff --git a/src/system/kernel/lib/Jamfile b/src/system/kernel/lib/Jamfile index bcaa986205..5d0319dca5 100644 --- a/src/system/kernel/lib/Jamfile +++ b/src/system/kernel/lib/Jamfile @@ -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 diff --git a/src/system/libroot/posix/string/Jamfile b/src/system/libroot/posix/string/Jamfile index a8d53bc097..609c0fdb4c 100644 --- a/src/system/libroot/posix/string/Jamfile +++ b/src/system/libroot/posix/string/Jamfile @@ -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 diff --git a/src/system/libroot/posix/string/strdup.c b/src/system/libroot/posix/string/strdup.c deleted file mode 100644 index a4306f0899..0000000000 --- a/src/system/libroot/posix/string/strdup.c +++ /dev/null @@ -1,29 +0,0 @@ -/* - * Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved. - * Distributed under the terms of the MIT 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; -}