diff --git a/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile b/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile index 2e5c97ddaa..76ceb63363 100644 --- a/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile +++ b/src/add-ons/kernel/network/ppp/shared/libppp/Jamfile @@ -8,7 +8,6 @@ UseHeaders [ FDirName $(HAIKU_TOP) src add-ons kernel network ppp shared libkernelppp headers ] : true ; StaticLibrary libppp.a : - strlcat.c driver_settings.cpp settings_tools.cpp KPPPUtils.cpp @@ -20,8 +19,6 @@ StaticLibrary libppp.a : : libnetwork.so libbnetapi.so ; -SEARCH on [ FGristFiles strlcat.c ] = [ FDirName $(HAIKU_TOP) src system - libroot posix string ] ; SEARCH on [ FGristFiles driver_settings.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ; SEARCH on [ FGristFiles settings_tools.cpp ] = [ FDirName $(HAIKU_TOP) src diff --git a/src/build/libroot/Jamfile b/src/build/libroot/Jamfile index 3f4334f14f..58e70a8f80 100644 --- a/src/build/libroot/Jamfile +++ b/src/build/libroot/Jamfile @@ -41,10 +41,6 @@ if $(HOST_PLATFORM) != darwin && $(HOST_PLATFORM) != haiku_host { strlSources = strlcpy.c strlcat.c ; } -if $(HOST_PLATFORM) = mingw { - strlSources += stpcpy.c strcasestr.c ; -} - local hostPlatformSources ; if $(HOST_PLATFORM) = freebsd { hostPlatformSources = fs_freebsd.cpp ; @@ -72,7 +68,7 @@ local librootSources = driver_settings.cpp $(strlSources) - strnlen.cpp + strnlen.c KMessage.cpp ; @@ -108,8 +104,8 @@ BuildPlatformStaticLibraryPIC libroot_build_function_remapper.a : SEARCH on [ FGristFiles driver_settings.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ; -SEARCH on [ FGristFiles $(strlSources) strnlen.cpp ] - = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; +SEARCH on [ FGristFiles $(strlSources) strnlen.c ] + = [ FDirName $(HAIKU_TOP) src system libroot posix musl string ] ; SEARCH on [ FGristFiles SHA256.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot posix crypt ] ; SEARCH on [ FGristFiles KMessage.cpp ] diff --git a/src/system/boot/Jamfile b/src/system/boot/Jamfile index 50a57e6c47..d2d8bcb830 100644 --- a/src/system/boot/Jamfile +++ b/src/system/boot/Jamfile @@ -318,8 +318,8 @@ for platform in [ MultiBootSubDirSetup ] { memmove.c strdup.cpp strndup.cpp - strlen.cpp - strnlen.cpp + strlen.c + strnlen.c strcmp.c strcasecmp.c strncmp.c diff --git a/src/system/kernel/lib/Jamfile b/src/system/kernel/lib/Jamfile index 339dc87eff..34fba0ab4f 100644 --- a/src/system/kernel/lib/Jamfile +++ b/src/system/kernel/lib/Jamfile @@ -135,12 +135,12 @@ KernelMergeObject kernel_lib_posix.o : strerror.c strlcat.c strlcpy.c - strlen.cpp + strlen.c strncat.c strncmp.c strncpy.cpp strndup.cpp - strnlen.cpp + strnlen.c strpbrk.c strrchr.c strspn.c diff --git a/src/system/libroot/posix/musl/string/Jamfile b/src/system/libroot/posix/musl/string/Jamfile index dcf84a9dac..4ef9c52b80 100644 --- a/src/system/libroot/posix/musl/string/Jamfile +++ b/src/system/libroot/posix/musl/string/Jamfile @@ -10,13 +10,20 @@ for architectureObject in [ MultiArchSubDirSetup ] { MergeObject <$(architecture)>posix_musl_string.o : memccpy.c + memchr.c memmem.c memmove.c memrchr.c stpcpy.c stpncpy.c + strcat.c strchrnul.c strcspn.c + strlcat.c + strlcpy.c + strlen.c + strncat.c + strnlen.c strpbrk.c strspn.c strstr.c diff --git a/src/system/libroot/posix/musl/string/memchr.c b/src/system/libroot/posix/musl/string/memchr.c new file mode 100644 index 0000000000..16c6ee2a4a --- /dev/null +++ b/src/system/libroot/posix/musl/string/memchr.c @@ -0,0 +1,27 @@ +#include +#include +#include + +#define SS (sizeof(size_t)) +#define ALIGN (sizeof(size_t)-1) +#define ONES ((size_t)-1/UCHAR_MAX) +#define HIGHS (ONES * (UCHAR_MAX/2+1)) +#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS) + +void *memchr(const void *src, int c, size_t n) +{ + const unsigned char *s = src; + c = (unsigned char)c; +#if defined(__GNUC__) && __GNUC__ >= 4 + for (; ((uintptr_t)s & ALIGN) && n && *s != c; s++, n--); + if (n && *s != c) { + typedef size_t __attribute__((__may_alias__)) word; + const word *w; + size_t k = ONES * c; + for (w = (const void *)s; n>=SS && !HASZERO(*w^k); w++, n-=SS); + s = (const void *)w; + } +#endif + for (; n && *s != c; s++, n--); + return n ? (void *)s : 0; +} diff --git a/src/system/libroot/posix/musl/string/strcat.c b/src/system/libroot/posix/musl/string/strcat.c new file mode 100644 index 0000000000..33f749b1d2 --- /dev/null +++ b/src/system/libroot/posix/musl/string/strcat.c @@ -0,0 +1,7 @@ +#include + +char *strcat(char *restrict dest, const char *restrict src) +{ + strcpy(dest + strlen(dest), src); + return dest; +} diff --git a/src/system/libroot/posix/musl/string/strlcat.c b/src/system/libroot/posix/musl/string/strlcat.c new file mode 100644 index 0000000000..ef81209e35 --- /dev/null +++ b/src/system/libroot/posix/musl/string/strlcat.c @@ -0,0 +1,9 @@ +#define _BSD_SOURCE +#include + +size_t strlcat(char *d, const char *s, size_t n) +{ + size_t l = strnlen(d, n); + if (l == n) return l + strlen(s); + return l + strlcpy(d+l, s, n-l); +} diff --git a/src/system/libroot/posix/musl/string/strlcpy.c b/src/system/libroot/posix/musl/string/strlcpy.c new file mode 100644 index 0000000000..83209b2218 --- /dev/null +++ b/src/system/libroot/posix/musl/string/strlcpy.c @@ -0,0 +1,34 @@ +#define _BSD_SOURCE +#include +#include +#include + +#define ALIGN (sizeof(size_t)-1) +#define ONES ((size_t)-1/UCHAR_MAX) +#define HIGHS (ONES * (UCHAR_MAX/2+1)) +#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS) + +size_t strlcpy(char *d, const char *s, size_t n) +{ + char *d0 = d; + size_t *wd; + + if (!n--) goto finish; +#if defined(__GNUC__) && __GNUC__ >= 4 + typedef size_t __attribute__((__may_alias__)) word; + const word *ws; + if (((uintptr_t)s & ALIGN) == ((uintptr_t)d & ALIGN)) { + for (; ((uintptr_t)s & ALIGN) && n && (*d=*s); n--, s++, d++); + if (n && *s) { + wd=(void *)d; ws=(const void *)s; + for (; n>=sizeof(size_t) && !HASZERO(*ws); + n-=sizeof(size_t), ws++, wd++) *wd = *ws; + d=(void *)wd; s=(const void *)ws; + } + } +#endif + for (; n && (*d=*s); n--, s++, d++); + *d = 0; +finish: + return d-d0 + strlen(s); +} diff --git a/src/system/libroot/posix/musl/string/strlen.c b/src/system/libroot/posix/musl/string/strlen.c new file mode 100644 index 0000000000..dff0f4b40d --- /dev/null +++ b/src/system/libroot/posix/musl/string/strlen.c @@ -0,0 +1,22 @@ +#include +#include +#include + +#define ALIGN (sizeof(size_t)) +#define ONES ((size_t)-1/UCHAR_MAX) +#define HIGHS (ONES * (UCHAR_MAX/2+1)) +#define HASZERO(x) (((x)-ONES) & ~(x) & HIGHS) + +size_t strlen(const char *s) +{ + const char *a = s; +#if defined(__GNUC__) && __GNUC__ >= 4 + typedef size_t __attribute__((__may_alias__)) word; + const word *w; + for (; (uintptr_t)s % ALIGN; s++) if (!*s) return s-a; + for (w = (const void *)s; !HASZERO(*w); w++); + s = (const void *)w; +#endif + for (; *s; s++); + return s-a; +} diff --git a/src/system/libroot/posix/musl/string/strncat.c b/src/system/libroot/posix/musl/string/strncat.c new file mode 100644 index 0000000000..01ca2a2317 --- /dev/null +++ b/src/system/libroot/posix/musl/string/strncat.c @@ -0,0 +1,10 @@ +#include + +char *strncat(char *restrict d, const char *restrict s, size_t n) +{ + char *a = d; + d += strlen(d); + while (n && *s) n--, *d++ = *s++; + *d++ = 0; + return a; +} diff --git a/src/system/libroot/posix/musl/string/strnlen.c b/src/system/libroot/posix/musl/string/strnlen.c new file mode 100644 index 0000000000..12db36a51c --- /dev/null +++ b/src/system/libroot/posix/musl/string/strnlen.c @@ -0,0 +1,7 @@ +#include + +size_t strnlen(const char *s, size_t n) +{ + const char *p = memchr(s, 0, n); + return p ? (size_t)(p-s) : n; +} diff --git a/src/system/libroot/posix/string/Jamfile b/src/system/libroot/posix/string/Jamfile index ce6af35138..3f41a5b9c5 100644 --- a/src/system/libroot/posix/string/Jamfile +++ b/src/system/libroot/posix/string/Jamfile @@ -20,26 +20,19 @@ for architectureObject in [ MultiArchSubDirSetup ] { bcmp.c bcopy.c bzero.c - memchr.c memcmp.c strcasecmp.c strcasestr.c - strcat.c strchr.c strcmp.c strcoll.cpp strcpy.c strdup.cpp strerror.c - strlcat.c - strlcpy.c - strlen.cpp strlwr.c - strncat.c strncmp.c strncpy.cpp strndup.cpp - strnlen.cpp strrchr.c strtok.c strupr.c diff --git a/src/system/libroot/posix/string/memchr.c b/src/system/libroot/posix/string/memchr.c deleted file mode 100644 index 442b026556..0000000000 --- a/src/system/libroot/posix/string/memchr.c +++ /dev/null @@ -1,24 +0,0 @@ -/* -** Copyright 2001, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -void * -memchr(void const *buf, int c, size_t len) -{ - unsigned char const *b = buf; - unsigned char x = (c&0xff); - size_t i; - - for (i = 0; i < len; i++) { - if (b[i] == x) - return (void*)(b + i); - } - - return NULL; -} - diff --git a/src/system/libroot/posix/string/strcat.c b/src/system/libroot/posix/string/strcat.c deleted file mode 100644 index 3323583156..0000000000 --- a/src/system/libroot/posix/string/strcat.c +++ /dev/null @@ -1,22 +0,0 @@ -/* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -char * -strcat(char *dest, char const*src) -{ - char *tmp = dest; - - while(*dest) - dest++; - while((*dest++ = *src++) != '\0') - ; - - return tmp; -} - diff --git a/src/system/libroot/posix/string/strlcat.c b/src/system/libroot/posix/string/strlcat.c deleted file mode 100644 index 3704120309..0000000000 --- a/src/system/libroot/posix/string/strlcat.c +++ /dev/null @@ -1,38 +0,0 @@ -/* -** Copyright 2002, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -/** Concatenates the source string to the destination, writes - * as much as "maxLength" bytes to the dest string. - * Always null terminates the string as long as maxLength is - * larger than the dest string. - * Returns the length of the string that it tried to create - * to be able to easily detect string truncation. - */ - -size_t -strlcat(char *dest, const char *source, size_t maxLength) -{ - size_t destLength = strnlen(dest, maxLength), i; - - // This returns the wrong size, but it's all we can do - if (maxLength == destLength) - return destLength + strlen(source); - - dest += destLength; - maxLength -= destLength; - - for (i = 0; i < maxLength - 1 && source[i]; i++) { - dest[i] = source[i]; - } - - dest[i] = '\0'; - - return destLength + i + strlen(source + i); -} - diff --git a/src/system/libroot/posix/string/strlcpy.c b/src/system/libroot/posix/string/strlcpy.c deleted file mode 100644 index 04e387b2c2..0000000000 --- a/src/system/libroot/posix/string/strlcpy.c +++ /dev/null @@ -1,25 +0,0 @@ -/* -** Copyright 2002, Manuel J. Petit. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -size_t -strlcpy(char *dst, char const *src, size_t s) -{ - size_t i= 0; - - if (!s) - return strlen(src); - - for (i = 0; ((i < s - 1) && src[i]); i++) { - dst[i] = src[i]; - } - - dst[i] = 0; - - return i + strlen(src + i); -} diff --git a/src/system/libroot/posix/string/strlen.cpp b/src/system/libroot/posix/string/strlen.cpp deleted file mode 100644 index 9c88a35e75..0000000000 --- a/src/system/libroot/posix/string/strlen.cpp +++ /dev/null @@ -1,38 +0,0 @@ -/* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -/* From Bit twiddling hacks: - http://graphics.stanford.edu/~seander/bithacks.html */ -#define LACKS_ZERO_BYTE(value) \ - (((value - 0x01010101) & ~value & 0x80808080) == 0) - - -size_t -strlen(const char* string) -{ - size_t length = 0; - - /* Align access for four byte reads */ - for (; (((addr_t)string + length) & 3) != 0; length++) { - if (string[length] == '\0') - return length; - } - - /* Check four bytes for zero char */ - uint32* valuePointer = (uint32*)(string + length); - for (; LACKS_ZERO_BYTE(*valuePointer); valuePointer++) - ; - - /* Find the exact length */ - for (length = ((char*)valuePointer) - string; string[length] != '\0'; - length++) - ; - - return length; -} diff --git a/src/system/libroot/posix/string/strncat.c b/src/system/libroot/posix/string/strncat.c deleted file mode 100644 index ae4b757fb9..0000000000 --- a/src/system/libroot/posix/string/strncat.c +++ /dev/null @@ -1,28 +0,0 @@ -/* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -char * -strncat(char *dest, char const *src, size_t count) -{ - char *tmp = dest; - - if (count > 0) { - while (*dest) - dest++; - while ((*dest++ = *src++)) { - if (--count == 0) { - *dest = '\0'; - break; - } - } - } - - return tmp; -} - diff --git a/src/system/libroot/posix/string/strnlen.cpp b/src/system/libroot/posix/string/strnlen.cpp deleted file mode 100644 index 9b22ccbbe1..0000000000 --- a/src/system/libroot/posix/string/strnlen.cpp +++ /dev/null @@ -1,39 +0,0 @@ -/* -** Copyright 2001, Travis Geiselbrecht. All rights reserved. -** Distributed under the terms of the NewOS License. -*/ - -#include -#include - - -/* From Bit twiddling hacks: - http://graphics.stanford.edu/~seander/bithacks.html */ -#define LACKS_ZERO_BYTE(value) \ - (((value - 0x01010101) & ~value & 0x80808080) == 0) - - -size_t -strnlen(const char* string, size_t count) -{ - size_t length = 0; - /* Align access for four byte reads */ - for (; (((addr_t)string + length) & 3) != 0; length++) { - if (length == count || string[length] == '\0') - return length; - } - - /* Check four bytes for zero char */ - const uint32* kMaxScanPosition = (uint32*)(string + count - 4); - uint32* valuePointer = (uint32*)(string + length); - for (; valuePointer <= kMaxScanPosition && LACKS_ZERO_BYTE(*valuePointer); - valuePointer++) - ; - - /* Find the exact length */ - for (length = ((char*)valuePointer) - string; length < count - && string[length] != '\0'; length++) - ; - - return length; -} diff --git a/src/system/runtime_loader/Jamfile b/src/system/runtime_loader/Jamfile index 3e0ddf9f16..e6538326a9 100644 --- a/src/system/runtime_loader/Jamfile +++ b/src/system/runtime_loader/Jamfile @@ -52,27 +52,27 @@ for architectureObject in [ MultiArchSubDirSetup ] { ctype_loc.o LocaleData.o + memchr.o memmove.o + strcat.o strchrnul.o strcspn.o + strlcat.o + strlcpy.o + strlen.o + strnlen.o strpbrk.o strspn.o strstr.o - memchr.o memcmp.o strcasecmp.o - strcat.o strchr.o strcmp.o strcpy.o strdup.o strerror.o - strlcat.o - strlcpy.o - strlen.o strncmp.o - strnlen.o strrchr.o ; diff --git a/src/tests/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile b/src/tests/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile index 6748240c1e..6c6c275d49 100644 --- a/src/tests/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile +++ b/src/tests/add-ons/kernel/network/ppp/shared/libkernelppp/Jamfile @@ -25,9 +25,7 @@ StaticLibrary libkernelppp.a : _KPPPPFCHandler.cpp # for driver_settings - strlcat.c driver_settings.cpp ; -SEARCH on [ FGristFiles strlcat.c ] = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; SEARCH on [ FGristFiles driver_settings.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ; diff --git a/src/tests/system/boot/loader/Jamfile b/src/tests/system/boot/loader/Jamfile index 5b78322b03..372ce280eb 100644 --- a/src/tests/system/boot/loader/Jamfile +++ b/src/tests/system/boot/loader/Jamfile @@ -131,9 +131,6 @@ SEARCH on [ FGristFiles list.cpp ring_buffer.cpp ] SEARCH on [ FGristFiles KMessage.cpp ] = [ FDirName $(HAIKU_TOP) src system kernel messaging ] ; -SEARCH on [ FGristFiles strlcat.c strlcpy.c ] - = [ FDirName $(HAIKU_TOP) src system libroot posix string ] ; - SEARCH on [ FGristFiles driver_settings.cpp ] = [ FDirName $(HAIKU_TOP) src system libroot os ] ;