]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/ctype/strchrisascii/: strchriscntrl(): Add function
authorAlejandro Colomar <alx@kernel.org>
Fri, 13 Dec 2024 02:46:33 +0000 (03:46 +0100)
committerSerge Hallyn <serge@hallyn.com>
Tue, 3 Jun 2025 14:04:01 +0000 (09:04 -0500)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/ctype/strchrisascii/strchriscntrl.c [new file with mode: 0644]
lib/string/ctype/strchrisascii/strchriscntrl.h [new file with mode: 0644]

index fd9292a3ed5db3328f15bbb27fb04b63f1ebb8e1..42a439b4150f681f10444f8c029b6f826adcb983 100644 (file)
@@ -179,6 +179,8 @@ libshadow_la_SOURCES = \
        spawn.c \
        sssd.c \
        sssd.h \
+       string/ctype/strchrisascii/strchriscntrl.c \
+       string/ctype/strchrisascii/strchriscntrl.h \
        string/ctype/strisascii/strisdigit.c \
        string/ctype/strisascii/strisdigit.h \
        string/ctype/strisascii/strisprint.c \
diff --git a/lib/string/ctype/strchrisascii/strchriscntrl.c b/lib/string/ctype/strchrisascii/strchriscntrl.c
new file mode 100644 (file)
index 0000000..cb99c6f
--- /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/strchrisascii/strchriscntrl.h"
+
+#include <stdbool.h>
+
+
+extern inline bool strchriscntrl(const char *s);
diff --git a/lib/string/ctype/strchrisascii/strchriscntrl.h b/lib/string/ctype/strchrisascii/strchriscntrl.h
new file mode 100644 (file)
index 0000000..966aa94
--- /dev/null
@@ -0,0 +1,36 @@
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_CTYPE_STRCHRISASCII_STRCHRISCNTRL_H_
+#define SHADOW_INCLUDE_LIB_STRING_CTYPE_STRCHRISASCII_STRCHRISCNTRL_H_
+
+
+#include <config.h>
+
+#include <ctype.h>
+#include <stdbool.h>
+
+#include "string/strcmp/streq.h"
+
+
+inline bool strchriscntrl(const char *s);
+
+
+// string character is [:cntrl:]
+// Return true if any iscntrl(3) character is found in the string.
+inline bool
+strchriscntrl(const char *s)
+{
+       for (; !streq(s, ""); s++) {
+               unsigned char  c = *s;
+
+               if (iscntrl(c))
+                       return true;
+       }
+
+       return false;
+}
+
+
+#endif  // include guard