]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/ctype/strisascii/: strisdigit(): Add function
authorAlejandro Colomar <alx@kernel.org>
Wed, 11 Dec 2024 00:57:29 +0000 (01:57 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sun, 16 Feb 2025 22:12:16 +0000 (16:12 -0600)
Reviewed-by: Serge Hallyn <serge@hallyn.com>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/ctype/strisascii/strisdigit.c [new file with mode: 0644]
lib/string/ctype/strisascii/strisdigit.h [new file with mode: 0644]

index fc39e01791abae4ebd8bbd8cee8a83c13ba2dd31..307e70469d223e1dcd12918a8f9dab588dbf9889 100644 (file)
@@ -186,6 +186,8 @@ libshadow_la_SOURCES = \
        spawn.c \
        sssd.c \
        sssd.h \
+       string/ctype/strisascii/strisdigit.c \
+       string/ctype/strisascii/strisdigit.h \
        string/memset/memzero.c \
        string/memset/memzero.h \
        string/sprintf/snprintf.c \
diff --git a/lib/string/ctype/strisascii/strisdigit.c b/lib/string/ctype/strisascii/strisdigit.c
new file mode 100644 (file)
index 0000000..a0e1449
--- /dev/null
@@ -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);
diff --git a/lib/string/ctype/strisascii/strisdigit.h b/lib/string/ctype/strisascii/strisdigit.h
new file mode 100644 (file)
index 0000000..065ba19
--- /dev/null
@@ -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