New upstream version 4.18.0
This commit is contained in:
@@ -0,0 +1,13 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strtok/astrsep2ls.h"
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
|
||||
extern inline char **astrsep2ls(char *restrict s, const char *restrict delim,
|
||||
size_t *restrict np);
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_ASTRSEP2LS_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_ASTRSEP2LS_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <stddef.h>
|
||||
|
||||
#include "alloc/malloc.h"
|
||||
#include "attr.h"
|
||||
#include "string/strchr/strchrscnt.h"
|
||||
#include "string/strtok/strsep2ls.h"
|
||||
|
||||
|
||||
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.
|
||||
inline char **
|
||||
astrsep2ls(char *s, const char *restrict delim, size_t *restrict np)
|
||||
{
|
||||
char **ls;
|
||||
ssize_t n;
|
||||
|
||||
n = strchrscnt(s, delim) + 2;
|
||||
|
||||
ls = MALLOC(n, char *);
|
||||
if (ls == NULL)
|
||||
return NULL;
|
||||
|
||||
n = strsep2ls(s, delim, n, ls);
|
||||
if (n == -1) {
|
||||
free(ls);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (np != NULL)
|
||||
*np = n;
|
||||
|
||||
return ls;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strtok/strsep2arr.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
extern inline ssize_t strsep2arr(char *s, const char *restrict delim,
|
||||
size_t n, char *a[restrict n]);
|
||||
@@ -0,0 +1,52 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2ARR_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2ARR_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "sizeof.h"
|
||||
|
||||
|
||||
#define STRSEP2ARR(s, delim, a) \
|
||||
( \
|
||||
strsep2arr(s, delim, countof(a), a) == countof(a) ? 0 : -1 \
|
||||
)
|
||||
|
||||
|
||||
ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4, 3)
|
||||
ATTR_STRING(1) ATTR_STRING(2)
|
||||
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.
|
||||
inline ssize_t
|
||||
strsep2arr(char *s, const char *restrict delim, size_t n, char *a[restrict n])
|
||||
{
|
||||
size_t i;
|
||||
|
||||
for (i = 0; i < n && s != NULL; i++)
|
||||
a[i] = strsep(&s, delim);
|
||||
|
||||
if (s != NULL) {
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,14 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include "string/strtok/strsep2ls.h"
|
||||
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
|
||||
extern inline ssize_t strsep2ls(char *s, const char *restrict delim,
|
||||
size_t n, char *ls[restrict n]);
|
||||
@@ -0,0 +1,48 @@
|
||||
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
|
||||
// SPDX-License-Identifier: BSD-3-Clause
|
||||
|
||||
|
||||
#ifndef SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2LS_H_
|
||||
#define SHADOW_INCLUDE_LIB_STRING_STRTOK_STRSEP2LS_H_
|
||||
|
||||
|
||||
#include <config.h>
|
||||
|
||||
#include <errno.h>
|
||||
#include <stddef.h>
|
||||
#include <sys/types.h>
|
||||
|
||||
#include "attr.h"
|
||||
#include "sizeof.h"
|
||||
#include "string/strtok/strsep2arr.h"
|
||||
|
||||
|
||||
#define STRSEP2LS(s, delim, ls) strsep2ls(s, delim, countof(ls), ls)
|
||||
|
||||
|
||||
ATTR_ACCESS(read_write, 1) ATTR_ACCESS(write_only, 4, 3)
|
||||
ATTR_STRING(1) ATTR_STRING(2)
|
||||
inline ssize_t strsep2ls(char *s, const char *restrict delim,
|
||||
size_t n, char *ls[restrict n]);
|
||||
|
||||
|
||||
// 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])
|
||||
{
|
||||
size_t i;
|
||||
|
||||
i = strsep2arr(s, delim, n, ls);
|
||||
if (i >= n) {
|
||||
errno = E2BIG;
|
||||
return -1;
|
||||
}
|
||||
|
||||
ls[i] = NULL;
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
|
||||
#endif // include guard
|
||||
@@ -0,0 +1,13 @@
|
||||
// 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);
|
||||
@@ -0,0 +1,46 @@
|
||||
// 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