New upstream version 4.19.0
This commit is contained in:
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/ctype/strchrisascii/strchriscntrl.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRCHRISASCII_STRCHRISCNTRL_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/ctype/strisascii/strisdigit.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISDIGIT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/ctype/strisascii/strisprint.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRISASCII_STRISPRINT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/ctype/strtoascii/strtolower.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRTOASCII_STRTOLOWER_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <ctype.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@@ -7,7 +7,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_MEMSET_MEMZERO_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -16,13 +16,15 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define MEMZERO(arr) memzero(arr, SIZEOF_ARRAY(arr))
|
||||
// memzero_a - memory zero (explicit) array
|
||||
#define memzero_a(arr) memzero(arr, sizeof_a(arr))
|
||||
|
||||
|
||||
inline void *memzero(void *ptr, size_t size);
|
||||
inline char *strzero(char *s);
|
||||
|
||||
|
||||
// memzero - memory zero (explicit)
|
||||
inline void *
|
||||
memzero(void *ptr, size_t size)
|
||||
{
|
||||
@@ -38,6 +40,7 @@ memzero(void *ptr, size_t size)
|
||||
}
|
||||
|
||||
|
||||
// strzero - string zero (explicit)
|
||||
inline char *
|
||||
strzero(char *s)
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/sprintf/aprintf.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_APRINTF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
@@ -14,6 +14,11 @@
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "exit_if_null.h"
|
||||
|
||||
|
||||
// exit-on-error allocate print formatted
|
||||
#define xaprintf(...) exit_if_null(aprintf(__VA_ARGS__))
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/sprintf/snprintf.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_SNPRINTF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
@@ -16,7 +16,8 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define SNPRINTF(s, fmt, ...) \
|
||||
// stprintf_a - string truncate print formatted array
|
||||
#define stprintf_a(s, fmt, ...) \
|
||||
( \
|
||||
snprintf_(s, countof(s), fmt __VA_OPT__(,) __VA_ARGS__) \
|
||||
)
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/sprintf/stpeprintf.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_STPEPRINTF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/sprintf/xaprintf.h"
|
||||
|
||||
#include <stdarg.h>
|
||||
|
||||
|
||||
extern inline char *xaprintf(const char *restrict fmt, ...);
|
||||
extern inline char *xvaprintf(const char *restrict fmt, va_list ap);
|
||||
@@ -1,59 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_SPRINTF_XASPRINTF_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_SPRINTF_XASPRINTF_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "string/sprintf/aprintf.h"
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 2)
|
||||
inline char *xaprintf(const char *restrict fmt, ...);
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
format_attr(printf, 1, 0)
|
||||
inline char *xvaprintf(const char *restrict fmt, va_list ap);
|
||||
|
||||
|
||||
// exit-on-error allocate print formatted
|
||||
inline char *
|
||||
xaprintf(const char *restrict fmt, ...)
|
||||
{
|
||||
char *p;
|
||||
va_list ap;
|
||||
|
||||
va_start(ap, fmt);
|
||||
p = xvaprintf(fmt, ap);
|
||||
va_end(ap);
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
inline char *
|
||||
xvaprintf(const char *restrict fmt, va_list ap)
|
||||
{
|
||||
char *p;
|
||||
|
||||
p = vaprintf(fmt, ap);
|
||||
if (p == NULL) {
|
||||
perror("vaprintf");
|
||||
exit(EXIT_FAILURE);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strchr/strchrcnt.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRCNT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strchr/strchrscnt.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRCHRSCNT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strchr/strnul.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCHR_STRNUL_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -18,7 +18,7 @@
|
||||
#define strnul(s) \
|
||||
({ \
|
||||
__auto_type s_ = s; \
|
||||
\
|
||||
\
|
||||
s_ + strlen(s_); \
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <strings.h>
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcmp/strcaseprefix.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEPREFIX_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -19,9 +19,9 @@
|
||||
#define strcaseprefix(s, prefix) \
|
||||
({ \
|
||||
const char *p_; \
|
||||
\
|
||||
\
|
||||
p_ = strcaseprefix_(s, prefix); \
|
||||
\
|
||||
\
|
||||
_Generic(s, \
|
||||
const char *: p_, \
|
||||
const void *: p_, \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STREQ_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
13
lib/string/strcmp/strneq.c
Normal file
13
lib/string/strcmp/strneq.c
Normal file
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcmp/strneq.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline bool strneq(const char *strn, const char *s, size_t size);
|
||||
37
lib/string/strcmp/strneq.h
Normal file
37
lib/string/strcmp/strneq.h
Normal file
@@ -0,0 +1,37 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STRNEQ_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRNEQ_H_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define strneq_a(strn, s) strneq(strn, s, countof(strn))
|
||||
|
||||
|
||||
ATTR_STRING(2)
|
||||
inline bool strneq(ATTR_NONSTRING const char *strn, const char *s, size_t size);
|
||||
|
||||
|
||||
// nonstring equal
|
||||
/* Return true if the nonstring strn and the string s compare equal. */
|
||||
inline bool
|
||||
strneq(const char *strn, const char *s, size_t size)
|
||||
{
|
||||
if (strlen(s) > size)
|
||||
return false;
|
||||
|
||||
return strncmp(strn, s, size) == 0;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcmp/strprefix.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRPREFIX_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -19,9 +19,9 @@
|
||||
#define strprefix(s, prefix) \
|
||||
({ \
|
||||
const char *p_; \
|
||||
\
|
||||
\
|
||||
p_ = strprefix_(s, prefix); \
|
||||
\
|
||||
\
|
||||
_Generic(s, \
|
||||
const char *: p_, \
|
||||
const void *: p_, \
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcpy/stpecpy.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STPECPY_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcpy/strncat.h"
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRNCAT_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define STRNCAT(dst, src) strncat(dst, src, countof(src))
|
||||
// strncat_a - nonstring catenate-into-string array
|
||||
#define strncat_a(dst, src) strncat(dst, src, countof(src))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strcpy/strncpy.h"
|
||||
|
||||
@@ -6,14 +6,15 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRNCPY_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define STRNCPY(dst, src) strncpy(dst, src, countof(dst))
|
||||
// strncpy_a - nonstring copy array
|
||||
#define strncpy_a(dst, src) strncpy(dst, src, countof(dst))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRCPY_STRTCPY_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stddef.h>
|
||||
@@ -17,34 +17,8 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
/*
|
||||
* SYNOPSIS
|
||||
* [[gnu::null_terminated_string_arg(2)]]
|
||||
* int STRTCPY(char dst[restrict], const char *restrict src);
|
||||
*
|
||||
* ARGUMENTS
|
||||
* dst Destination buffer where to copy a string.
|
||||
* src Source string to be copied into dst.
|
||||
*
|
||||
* DESCRIPTION
|
||||
* This macro copies the string pointed to by src, into a string
|
||||
* at the buffer pointed to by dst. If the destination buffer,
|
||||
* isn't large enough to hold the copy, the resulting string is
|
||||
* truncated. The size of the buffer is calculated internally via
|
||||
* countof().
|
||||
*
|
||||
* RETURN VALUE
|
||||
* -1 If this call truncated the resulting string.
|
||||
*
|
||||
* strlen(dst)
|
||||
* On success.
|
||||
*
|
||||
* ERRORS
|
||||
* This function doesn't set errno.
|
||||
*/
|
||||
|
||||
|
||||
#define STRTCPY(dst, src) strtcpy(dst, src, countof(dst))
|
||||
// strtcpy_a - string truncate copy array
|
||||
#define strtcpy_a(dst, src) strtcpy(dst, src, countof(dst))
|
||||
|
||||
|
||||
ATTR_STRING(2)
|
||||
@@ -52,6 +26,7 @@ inline ssize_t strtcpy(char *restrict dst, const char *restrict src,
|
||||
size_t dsize);
|
||||
|
||||
|
||||
// strtcpy - string truncate copy
|
||||
inline ssize_t
|
||||
strtcpy(char *restrict dst, const char *restrict src, size_t dsize)
|
||||
{
|
||||
|
||||
7
lib/string/strdup/strdup.c
Normal file
7
lib/string/strdup/strdup.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strdup/strdup.h"
|
||||
24
lib/string/strdup/strdup.h
Normal file
24
lib/string/strdup/strdup.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008, Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_STRDUP_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_STRDUP_H_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "exit_if_null.h"
|
||||
|
||||
|
||||
// xstrdup - exit-on-error string duplicate
|
||||
#define xstrdup(s) exit_if_null(strdup(s))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strdup/xstrndup.h"
|
||||
#include "string/strdup/strndup.h"
|
||||
24
lib/string/strdup/strndup.h
Normal file
24
lib/string/strdup/strndup.h
Normal file
@@ -0,0 +1,24 @@
|
||||
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_STRNDUP_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_STRNDUP_H_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "sizeof.h"
|
||||
#include "exit_if_null.h"
|
||||
|
||||
|
||||
// strndup_a - nonstring duplicate-into-string array
|
||||
#define strndup_a(s) strndup(s, countof(s))
|
||||
|
||||
// xstrndup_a - exit-on-error nonstring duplicate-into-string array
|
||||
#define xstrndup_a(s) exit_if_null(strndup_a(s))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strdup/strndupa.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_STRNDUPA_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <alloca.h>
|
||||
#include <string.h>
|
||||
@@ -14,13 +14,14 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
// string n-bounded-read duplicate using-alloca(3)
|
||||
// strndupa - nonstring duplicate-into-string using-alloca(3)
|
||||
#ifndef strndupa
|
||||
# define strndupa(s, n) strncat(strcpy(alloca(n + 1), ""), s, n)
|
||||
#endif
|
||||
|
||||
|
||||
#define STRNDUPA(s) strndupa(s, countof(s))
|
||||
// strndupa_a - nonstring duplicate-into-string using-alloca(3) array
|
||||
#define strndupa_a(s) strndupa(s, countof(s))
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -1,14 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strdup/xstrdup.h"
|
||||
|
||||
|
||||
extern inline char *xstrdup(const char *str);
|
||||
@@ -1,32 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 1990-1994, Julianne Frances Haugh
|
||||
// SPDX-FileCopyrightText: 1996-1998, Marek Michałkiewicz
|
||||
// SPDX-FileCopyrightText: 2003-2006, Tomasz Kłoczko
|
||||
// SPDX-FileCopyrightText: 2008 , Nicolas François
|
||||
// SPDX-FileCopyrightText: 2023-2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRDUP_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "attr.h"
|
||||
|
||||
|
||||
ATTR_MALLOC(free)
|
||||
inline char *xstrdup(const char *str);
|
||||
|
||||
|
||||
inline char *
|
||||
xstrdup(const char *str)
|
||||
{
|
||||
return strcpy(XMALLOC(strlen(str) + 1, char), str);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -1,25 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRNDUP_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRDUP_XSTRNDUP_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#include "alloc/x/xmalloc.h"
|
||||
#include "sizeof.h"
|
||||
#include "string/strcpy/strncat.h"
|
||||
|
||||
|
||||
// Similar to strndup(3), but ensure that 's' is an array, and exit on ENOMEM.
|
||||
#define XSTRNDUP(s) \
|
||||
( \
|
||||
STRNCAT(strcpy(XMALLOC(strnlen(s, countof(s)) + 1, char), ""), s) \
|
||||
)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
7
lib/string/strerrno.c
Normal file
7
lib/string/strerrno.c
Normal file
@@ -0,0 +1,7 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strerrno.h"
|
||||
19
lib/string/strerrno.h
Normal file
19
lib/string/strerrno.h
Normal file
@@ -0,0 +1,19 @@
|
||||
// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRERRNO_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRERRNO_H_
|
||||
|
||||
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// strerrno - string errno
|
||||
#define strerrno() ({(const char *){strerror(errno)};})
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "strftime.h"
|
||||
|
||||
@@ -6,15 +6,15 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRFTIME_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <time.h>
|
||||
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
// string format time
|
||||
#define STRFTIME(dst, fmt, tm) strftime(dst, countof(dst), fmt, tm)
|
||||
// strftime_a - string format time array
|
||||
#define strftime_a(dst, fmt, tm) strftime(dst, countof(dst), fmt, tm)
|
||||
|
||||
|
||||
#endif // include guard
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strspn/stprcspn.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRCSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -17,7 +17,7 @@
|
||||
#define stprcspn(s, reject) \
|
||||
({ \
|
||||
__auto_type s_ = (s); \
|
||||
\
|
||||
\
|
||||
s_ + strrcspn(s_, reject); \
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strspn/stprspn.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPRSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define stprspn(s, accept) \
|
||||
({ \
|
||||
__auto_type s_ = (s); \
|
||||
\
|
||||
\
|
||||
s_ + strrspn_(s_, accept); \
|
||||
})
|
||||
|
||||
|
||||
@@ -2,6 +2,6 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strspn/stpspn.h"
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STPSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
@@ -19,7 +19,7 @@
|
||||
#define stpspn(s, accept) \
|
||||
({ \
|
||||
__auto_type s_ = s; \
|
||||
\
|
||||
\
|
||||
s_ + strspn(s_, accept); \
|
||||
})
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strspn/strrcspn.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRCSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -24,7 +24,7 @@ inline size_t strrcspn(const char *s, const char *reject);
|
||||
inline size_t
|
||||
strrcspn(const char *s, const char *reject)
|
||||
{
|
||||
char *p;
|
||||
const char *p;
|
||||
|
||||
p = strnul(s);
|
||||
while (p > s) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strspn/strrspn.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRSPN_STRRSPN_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
@@ -24,7 +24,7 @@ inline size_t strrspn_(const char *s, const char *accept);
|
||||
inline size_t
|
||||
strrspn_(const char *s, const char *accept)
|
||||
{
|
||||
char *p;
|
||||
const char *p;
|
||||
|
||||
p = strnul(s);
|
||||
while (p > s) {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strtok/astrsep2ls.h"
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
@@ -6,24 +6,28 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_ASTRSEP2LS_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
#include "attr.h"
|
||||
#include "exit_if_null.h"
|
||||
#include "string/strchr/strchrscnt.h"
|
||||
#include "string/strtok/strsep2ls.h"
|
||||
|
||||
|
||||
// xastrsep2ls - exit-on-error allocate string separate to list-of-strings
|
||||
#define xastrsep2ls(s, delim, np) exit_if_null(astrsep2ls(s, delim, np))
|
||||
|
||||
|
||||
ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 3)
|
||||
ATTR_STRING(1) ATTR_STRING(2)
|
||||
inline char **astrsep2ls(char *restrict s, const char *restrict delim,
|
||||
size_t *restrict np);
|
||||
|
||||
|
||||
// allocate string separate to list-of-strings
|
||||
// Like strsep2ls(), but allocate the list array.
|
||||
// astrsep2ls - allocate string separate to list-of-strings
|
||||
inline char **
|
||||
astrsep2ls(char *s, const char *restrict delim, size_t *restrict np)
|
||||
{
|
||||
@@ -32,7 +36,7 @@ astrsep2ls(char *s, const char *restrict delim, size_t *restrict np)
|
||||
|
||||
n = strchrscnt(s, delim) + 2;
|
||||
|
||||
ls = MALLOC(n, char *);
|
||||
ls = malloc_T(n, char *);
|
||||
if (ls == NULL)
|
||||
return NULL;
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strtok/stpsep.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STPSEP_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strtok/strsep2arr.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2ARR_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
@@ -17,7 +17,8 @@
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define STRSEP2ARR(s, delim, a) \
|
||||
// strsep2arr_a - string separate to array-of-strings array
|
||||
#define strsep2arr_a(s, delim, a) \
|
||||
( \
|
||||
strsep2arr(s, delim, countof(a), a) == countof(a) ? 0 : -1 \
|
||||
)
|
||||
@@ -29,9 +30,7 @@ inline ssize_t strsep2arr(char *s, const char *restrict delim,
|
||||
size_t n, char *a[restrict n]);
|
||||
|
||||
|
||||
// string separate to array-of-strings
|
||||
// strsep(3) a string into an array of strings.
|
||||
// Return the number of fields in the string, or -1 on error.
|
||||
// strsep2arr - string separate to array-of-strings
|
||||
inline ssize_t
|
||||
strsep2arr(char *s, const char *restrict delim, size_t n, char *a[restrict n])
|
||||
{
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include "string/strtok/strsep2ls.h"
|
||||
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2LS_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
#include "config.h"
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
@@ -17,7 +17,8 @@
|
||||
#include "string/strtok/strsep2arr.h"
|
||||
|
||||
|
||||
#define STRSEP2LS(s, delim, ls) strsep2ls(s, delim, countof(ls), ls)
|
||||
// strsep2ls_a - string separate to list-of-strings array
|
||||
#define strsep2ls_a(s, delim, ls) strsep2ls(s, delim, countof(ls), ls)
|
||||
|
||||
|
||||
ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4, 3)
|
||||
@@ -26,7 +27,7 @@ inline ssize_t strsep2ls(char *s, const char *restrict delim,
|
||||
size_t n, char *ls[restrict n]);
|
||||
|
||||
|
||||
// string separate to list-of-strings
|
||||
// strsep2ls - string separate to list-of-strings
|
||||
// Like strsep2arr(), but add a NULL terminator.
|
||||
inline ssize_t
|
||||
strsep2ls(char *s, const char *restrict delim, size_t n, char *ls[restrict n])
|
||||
|
||||
@@ -1,13 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strtok/xastrsep2ls.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline char **xastrsep2ls(char *restrict s, const char *restrict delim,
|
||||
size_t *restrict np);
|
||||
@@ -1,46 +0,0 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_XASTRSEP2LS_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_XASTRSEP2LS_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "shadowlog.h"
|
||||
#include "string/strtok/astrsep2ls.h"
|
||||
|
||||
|
||||
ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 3)
|
||||
ATTR_STRING(1) ATTR_STRING(2)
|
||||
inline char **xastrsep2ls(char *restrict s, const char *restrict delim,
|
||||
size_t *restrict np);
|
||||
|
||||
|
||||
// exit-on-error allocate string separate to list-of-strings
|
||||
inline char **
|
||||
xastrsep2ls(char *s, const char *restrict delim, size_t *restrict np)
|
||||
{
|
||||
char **ls;
|
||||
|
||||
ls = astrsep2ls(s, delim, np);
|
||||
if (ls == NULL)
|
||||
goto x;
|
||||
|
||||
return ls;
|
||||
x:
|
||||
fprintf(log_get_logfd(), "%s: %s\n",
|
||||
log_get_progname(), strerror(errno));
|
||||
exit(13);
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
Reference in New Issue
Block a user