libroot: Replace strcspn and strchrnul with musl versions.
Removes the last BSD advertising clause from the "string" directory.
This commit is contained in:
parent
bc328a435b
commit
46a6070b57
@ -51,6 +51,9 @@ local muslSources =
|
||||
ffs.c
|
||||
rand.c
|
||||
rand_r.c
|
||||
|
||||
strchrnul.c
|
||||
strcspn.c
|
||||
;
|
||||
|
||||
SourceHdrs $(muslSources) :
|
||||
@ -122,7 +125,6 @@ KernelMergeObject kernel_lib_posix.o :
|
||||
strchr.c
|
||||
strcmp.c
|
||||
strcpy.c
|
||||
strcspn.c
|
||||
strdup.cpp
|
||||
strerror.c
|
||||
strlcat.c
|
||||
@ -147,6 +149,7 @@ KernelMergeObject kernel_lib_posix.o :
|
||||
|
||||
SEARCH on [ FGristFiles $(muslSources) ] += [ FDirName $(posixSources) musl misc ] ;
|
||||
SEARCH on [ FGristFiles $(muslSources) ] += [ FDirName $(posixSources) musl prng ] ;
|
||||
SEARCH on [ FGristFiles $(muslSources) ] += [ FDirName $(posixSources) musl string ] ;
|
||||
|
||||
# misc
|
||||
|
||||
|
@ -10,6 +10,8 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
|
||||
MergeObject <$(architecture)>posix_musl_string.o :
|
||||
memrchr.c
|
||||
strchrnul.c
|
||||
strcspn.c
|
||||
swab.c
|
||||
;
|
||||
}
|
||||
|
27
src/system/libroot/posix/musl/string/strchrnul.c
Normal file
27
src/system/libroot/posix/musl/string/strchrnul.c
Normal file
@ -0,0 +1,27 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
#include <stdint.h>
|
||||
#include <limits.h>
|
||||
|
||||
#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)
|
||||
|
||||
char *strchrnul(const char *s, int c)
|
||||
{
|
||||
c = (unsigned char)c;
|
||||
if (!c) return (char *)s + strlen(s);
|
||||
|
||||
#if 0
|
||||
typedef size_t __attribute__((__may_alias__)) word;
|
||||
const word *w;
|
||||
for (; (uintptr_t)s % ALIGN; s++)
|
||||
if (!*s || *(unsigned char *)s == c) return (char *)s;
|
||||
size_t k = ONES * c;
|
||||
for (w = (void *)s; !HASZERO(*w) && !HASZERO(*w^k); w++);
|
||||
s = (void *)w;
|
||||
#endif
|
||||
for (; *s && *(unsigned char *)s != c; s++);
|
||||
return (char *)s;
|
||||
}
|
18
src/system/libroot/posix/musl/string/strcspn.c
Normal file
18
src/system/libroot/posix/musl/string/strcspn.c
Normal file
@ -0,0 +1,18 @@
|
||||
#define _GNU_SOURCE
|
||||
#include <string.h>
|
||||
|
||||
#define BITOP(a,b,op) \
|
||||
((a)[(size_t)(b)/(8*sizeof *(a))] op (size_t)1<<((size_t)(b)%(8*sizeof *(a))))
|
||||
|
||||
size_t strcspn(const char *s, const char *c)
|
||||
{
|
||||
const char *a = s;
|
||||
size_t byteset[32/sizeof(size_t)];
|
||||
|
||||
if (!c[0] || !c[1]) return strchrnul(s, *c)-a;
|
||||
|
||||
memset(byteset, 0, sizeof byteset);
|
||||
for (; *c && BITOP(byteset, *(unsigned char *)c, |=); c++);
|
||||
for (; *s && !BITOP(byteset, *(unsigned char *)s, &); s++);
|
||||
return s-a;
|
||||
}
|
@ -29,11 +29,9 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
strcasestr.c
|
||||
strcat.c
|
||||
strchr.c
|
||||
strchrnul.c
|
||||
strcmp.c
|
||||
strcoll.cpp
|
||||
strcpy.c
|
||||
strcspn.c
|
||||
strdup.cpp
|
||||
strerror.c
|
||||
strlcat.c
|
||||
|
@ -1,18 +0,0 @@
|
||||
/*
|
||||
* Copyright 2003-2007, Axel Dörfler, axeld@pinc-software.de. All rights reserved.
|
||||
* Distributed under the terms of the MIT License.
|
||||
*/
|
||||
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
char*
|
||||
strchrnul(const char* string, int c)
|
||||
{
|
||||
while (string[0] != (char)c && string[0])
|
||||
string++;
|
||||
|
||||
return (char*)string;
|
||||
}
|
@ -1,64 +0,0 @@
|
||||
/*-
|
||||
* Copyright (c) 1990, 1993
|
||||
* The Regents of the University of California. All rights reserved.
|
||||
*
|
||||
* This code is derived from software contributed to Berkeley by
|
||||
* Chris Torek.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by the University of
|
||||
* California, Berkeley and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
/*
|
||||
* Span the complement of string s2.
|
||||
*/
|
||||
|
||||
size_t
|
||||
strcspn(const char *s1, const char *s2)
|
||||
{
|
||||
const char *p, *spanp;
|
||||
char c, sc;
|
||||
|
||||
/*
|
||||
* Stop as soon as we find any character from s2. Note that there
|
||||
* must be a NUL in s2; it suffices to stop when we find that, too.
|
||||
*/
|
||||
for (p = s1;;) {
|
||||
c = *p++;
|
||||
spanp = s2;
|
||||
do {
|
||||
if ((sc = *spanp++) == c)
|
||||
return (p - 1 - s1);
|
||||
} while (sc != 0);
|
||||
}
|
||||
/* NOTREACHED */
|
||||
}
|
||||
|
@ -54,6 +54,9 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
<src!system!libroot!posix!locale!$(architecture)>ctype_loc.o
|
||||
<src!system!libroot!posix!locale!$(architecture)>LocaleData.o
|
||||
|
||||
<src!system!libroot!posix!musl!string!$(architecture)>strchrnul.o
|
||||
<src!system!libroot!posix!musl!string!$(architecture)>strcspn.o
|
||||
|
||||
<src!system!libroot!posix!string!$(architecture)>memchr.o
|
||||
<src!system!libroot!posix!string!$(architecture)>memcmp.o
|
||||
<src!system!libroot!posix!string!$(architecture)>memmove.o
|
||||
@ -62,7 +65,6 @@ for architectureObject in [ MultiArchSubDirSetup ] {
|
||||
<src!system!libroot!posix!string!$(architecture)>strchr.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strcmp.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strcpy.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strcspn.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strdup.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strerror.o
|
||||
<src!system!libroot!posix!string!$(architecture)>strlcat.o
|
||||
|
Loading…
x
Reference in New Issue
Block a user