]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strtok/: xastrsep2ls(): Add function
authorAlejandro Colomar <alx@kernel.org>
Sat, 7 Dec 2024 00:59:57 +0000 (01:59 +0100)
committerAlejandro Colomar <foss+github@alejandro-colomar.es>
Sat, 7 Jun 2025 14:52:03 +0000 (16:52 +0200)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/strtok/xastrsep2ls.c [new file with mode: 0644]
lib/string/strtok/xastrsep2ls.h [new file with mode: 0644]

index aafc9fd7cc2b735968bc9558b92397deecd83673..21653c5be7cede43294100d3f019780315891fd3 100644 (file)
@@ -249,6 +249,8 @@ libshadow_la_SOURCES = \
        string/strtok/strsep2arr.h \
        string/strtok/strsep2ls.c \
        string/strtok/strsep2ls.h \
+       string/strtok/xastrsep2ls.c \
+       string/strtok/xastrsep2ls.h \
        strtoday.c \
        sub.c \
        subordinateio.h \
diff --git a/lib/string/strtok/xastrsep2ls.c b/lib/string/strtok/xastrsep2ls.c
new file mode 100644 (file)
index 0000000..84572fd
--- /dev/null
@@ -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);
diff --git a/lib/string/strtok/xastrsep2ls.h b/lib/string/strtok/xastrsep2ls.h
new file mode 100644 (file)
index 0000000..e935a92
--- /dev/null
@@ -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