New upstream version 4.17.3
This commit is contained in:
12
lib/string/ctype/strisascii/strisdigit.c
Normal file
12
lib/string/ctype/strisascii/strisdigit.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/ctype/strisascii/strisdigit.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
extern inline bool strisdigit(const char *s);
|
||||
32
lib/string/ctype/strisascii/strisdigit.h
Normal file
32
lib/string/ctype/strisascii/strisdigit.h
Normal file
@@ -0,0 +1,32 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISDIGIT_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISDIGIT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "string/strcmp/streq.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
|
||||
|
||||
inline bool strisdigit(const char *s);
|
||||
|
||||
|
||||
// string is [:digit:]
|
||||
// Like isdigit(3), but check all characters in the string.
|
||||
inline bool
|
||||
strisdigit(const char *s)
|
||||
{
|
||||
if (streq(s, ""))
|
||||
return false;
|
||||
|
||||
return streq(stpspn(s, "0123456789"), "");
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -18,6 +18,7 @@ ATTR_STRING(1)
|
||||
inline size_t strchrcnt(const char *s, char c);
|
||||
|
||||
|
||||
// string character count
|
||||
inline size_t
|
||||
strchrcnt(const char *s, char c)
|
||||
{
|
||||
|
||||
12
lib/string/strchr/strchrscnt.c
Normal file
12
lib/string/strchr/strchrscnt.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strchr/strchrscnt.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline size_t strchrscnt(const char *s, const char *c);
|
||||
37
lib/string/strchr/strchrscnt.h
Normal file
37
lib/string/strchr/strchrscnt.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRSCNT_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRSCNT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "string/strchr/strchrcnt.h"
|
||||
#include "string/strcmp/streq.h"
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
ATTR_STRING(2)
|
||||
inline size_t strchrscnt(const char *s, const char *c);
|
||||
|
||||
|
||||
// string characters count
|
||||
// Similar to strchrcnt(), but search for multiple characters.
|
||||
inline size_t
|
||||
strchrscnt(const char *s, const char *c)
|
||||
{
|
||||
size_t n = 0;
|
||||
|
||||
for (; !streq(c, ""); c++)
|
||||
n += strchrcnt(s, *c);
|
||||
|
||||
return n;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
// string null-byte
|
||||
// Similar to strlen(3), but return a pointer instead of an offset.
|
||||
#define strnul(s) \
|
||||
({ \
|
||||
|
||||
@@ -1,38 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRRSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "string/strchr/strnul.h"
|
||||
|
||||
|
||||
ATTR_STRING(2)
|
||||
inline char *strrspn(char *restrict s, const char *restrict accept);
|
||||
|
||||
|
||||
// Available in Oracle Solaris: strrspn(3GEN).
|
||||
// <https://docs.oracle.com/cd/E36784_01/html/E36877/strrspn-3gen.html>
|
||||
inline char *
|
||||
strrspn(char *restrict s, const char *restrict accept)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strnul(s);
|
||||
while (p > s) {
|
||||
p--;
|
||||
if (strchr(accept, *p) == NULL)
|
||||
return p + 1;
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
12
lib/string/strcmp/strcaseeq.c
Normal file
12
lib/string/strcmp/strcaseeq.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#include "string/strcmp/strcaseeq.h"
|
||||
|
||||
|
||||
extern inline bool strcaseeq(const char *s1, const char *s2);
|
||||
30
lib/string/strcmp/strcaseeq.h
Normal file
30
lib/string/strcmp/strcaseeq.h
Normal file
@@ -0,0 +1,30 @@
|
||||
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <strings.h>
|
||||
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_STRING(1) ATTR_STRING(2)
|
||||
inline bool strcaseeq(const char *s1, const char *s2);
|
||||
|
||||
|
||||
// strings case-insensitive equal
|
||||
// streq(), but case-insensitive.
|
||||
inline bool
|
||||
strcaseeq(const char *s1, const char *s2)
|
||||
{
|
||||
return strcasecmp(s1, s2) == 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -19,6 +19,7 @@ ATTR_STRING(2)
|
||||
inline bool streq(const char *s1, const char *s2);
|
||||
|
||||
|
||||
// strings equal
|
||||
/* Return true if s1 and s2 compare equal. */
|
||||
inline bool
|
||||
streq(const char *s1, const char *s2)
|
||||
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
// string format time
|
||||
#define STRFTIME(dst, fmt, tm) strftime(dst, NITEMS(dst), fmt, tm)
|
||||
|
||||
|
||||
|
||||
@@ -4,7 +4,4 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strchr/strrspn.h"
|
||||
|
||||
|
||||
extern inline char *strrspn(char *restrict s, const char *restrict accept);
|
||||
#include "string/strspn/stprcspn.h"
|
||||
25
lib/string/strspn/stprcspn.h
Normal file
25
lib/string/strspn/stprcspn.h
Normal file
@@ -0,0 +1,25 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRCSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRCSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "string/strspn/strrcspn.h"
|
||||
|
||||
|
||||
// string returns-pointer rear complement substring prefix length
|
||||
#define stprcspn(s, reject) \
|
||||
({ \
|
||||
__auto_type s_ = (s); \
|
||||
\
|
||||
s_ + strrcspn(s_, reject); \
|
||||
})
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/string/strspn/stprspn.c
Normal file
7
lib/string/strspn/stprspn.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strspn/stprspn.h"
|
||||
27
lib/string/strspn/stprspn.h
Normal file
27
lib/string/strspn/stprspn.h
Normal file
@@ -0,0 +1,27 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "string/strspn/strrspn.h"
|
||||
|
||||
|
||||
// string returns-pointer rear substring prefix length
|
||||
// Available in Oracle Solaris as strrspn(3GEN).
|
||||
// <https://docs.oracle.com/cd/E36784_01/html/E36877/strrspn-3gen.html>
|
||||
#define stprspn(s, accept) \
|
||||
({ \
|
||||
__auto_type s_ = (s); \
|
||||
\
|
||||
s_ + strrspn_(s_, accept); \
|
||||
})
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -4,4 +4,4 @@
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strchr/stpspn.h"
|
||||
#include "string/strspn/stpspn.h"
|
||||
@@ -2,8 +2,8 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCHR_STPSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STPSPN_H_
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STPSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
@@ -13,6 +13,7 @@
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
// string returns-pointer substring prefix length
|
||||
// Similar to strspn(3), but return a pointer instead of an offset.
|
||||
// Similar to strchrnul(3), but search for any bytes not in 'accept'.
|
||||
#define stpspn(s, accept) \
|
||||
12
lib/string/strspn/strrcspn.c
Normal file
12
lib/string/strspn/strrcspn.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strspn/strrcspn.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline size_t strrcspn(const char *s, const char *reject);
|
||||
39
lib/string/strspn/strrcspn.h
Normal file
39
lib/string/strspn/strrcspn.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRCSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRCSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "string/strchr/strnul.h"
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
ATTR_STRING(2)
|
||||
inline size_t strrcspn(const char *s, const char *reject);
|
||||
|
||||
|
||||
// string rear complement substring prefix length
|
||||
inline size_t
|
||||
strrcspn(const char *s, const char *reject)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strnul(s);
|
||||
while (p > s) {
|
||||
p--;
|
||||
if (strchr(reject, *p) != NULL)
|
||||
return p + 1 - s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
12
lib/string/strspn/strrspn.c
Normal file
12
lib/string/strspn/strrspn.c
Normal file
@@ -0,0 +1,12 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strspn/strrspn.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline size_t strrspn_(const char *s, const char *accept);
|
||||
39
lib/string/strspn/strrspn.h
Normal file
39
lib/string/strspn/strrspn.h
Normal file
@@ -0,0 +1,39 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRSPN_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "string/strchr/strnul.h"
|
||||
|
||||
|
||||
ATTR_STRING(1)
|
||||
ATTR_STRING(2)
|
||||
inline size_t strrspn_(const char *s, const char *accept);
|
||||
|
||||
|
||||
// string rear substring prefix length
|
||||
inline size_t
|
||||
strrspn_(const char *s, const char *accept)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = strnul(s);
|
||||
while (p > s) {
|
||||
p--;
|
||||
if (strchr(accept, *p) == NULL)
|
||||
return p + 1 - s;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -17,6 +17,7 @@ ATTR_STRING(1) ATTR_STRING(2)
|
||||
inline char *stpsep(char *s, const char *delim);
|
||||
|
||||
|
||||
// string returns-pointer separate
|
||||
// Similar to strsep(3),
|
||||
// but return the next token, and don't update the input pointer.
|
||||
// Similar to strtok(3),
|
||||
|
||||
Reference in New Issue
Block a user