]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strcmp/: strcaseeq(): Add function
authorAlejandro Colomar <alx@kernel.org>
Wed, 5 Feb 2025 17:42:21 +0000 (18:42 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 15 Feb 2025 16:26:50 +0000 (10:26 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/strcmp/strcaseeq.c [new file with mode: 0644]
lib/string/strcmp/strcaseeq.h [new file with mode: 0644]

index dc67df9e86ffadcd8be0daf348a666a2c2380a41..fe5032692768ab519daf6471fa2acf6655263ef2 100644 (file)
@@ -204,6 +204,8 @@ libshadow_la_SOURCES = \
        string/strchr/strnul.h \
        string/strchr/strrspn.c \
        string/strchr/strrspn.h \
+       string/strcmp/strcaseeq.c \
+       string/strcmp/strcaseeq.h \
        string/strcmp/streq.c \
        string/strcmp/streq.h \
        string/strcpy/stpecpy.c \
diff --git a/lib/string/strcmp/strcaseeq.c b/lib/string/strcmp/strcaseeq.c
new file mode 100644 (file)
index 0000000..2abb369
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include <stdbool.h>
+
+#include "string/strcmp/strcaseeq.h"
+
+
+extern inline bool strcaseeq(const char *s1, const char *s2);
diff --git a/lib/string/strcmp/strcaseeq.h b/lib/string/strcmp/strcaseeq.h
new file mode 100644 (file)
index 0000000..e93b477
--- /dev/null
@@ -0,0 +1,29 @@
+// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
+
+
+#include <config.h>
+
+#include <stdbool.h>
+#include <strings.h>
+
+#include "attr.h"
+
+
+ATTR_STRING(1) ATTR_STRING(2)
+inline bool strcaseeq(const char *s1, const char *s2);
+
+
+// streq(), but case-insensitive.
+inline bool
+strcaseeq(const char *s1, const char *s2)
+{
+       return strcasecmp(s1, s2) == 0;
+}
+
+
+#endif  // include guard