]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strcmp/: streq(): Add function
authorAlejandro Colomar <alx@kernel.org>
Tue, 15 Oct 2024 11:21:17 +0000 (13:21 +0200)
committerSerge Hallyn <serge@hallyn.com>
Mon, 11 Nov 2024 05:07:19 +0000 (23:07 -0600)
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/Makefile.am
lib/string/strcmp/streq.c [new file with mode: 0644]
lib/string/strcmp/streq.h [new file with mode: 0644]

index 4ea5ec4e59b593fef459faaeb59465f377e78c30..96393354b51dc2ca05335a919bdd1ff08a9a742d 100644 (file)
@@ -190,6 +190,8 @@ libshadow_la_SOURCES = \
        string/strchr/strnul.h \
        string/strchr/strrspn.c \
        string/strchr/strrspn.h \
+       string/strcmp/streq.c \
+       string/strcmp/streq.h \
        string/strcpy/stpecpy.c \
        string/strcpy/stpecpy.h \
        string/strcpy/strncat.c \
diff --git a/lib/string/strcmp/streq.c b/lib/string/strcmp/streq.c
new file mode 100644 (file)
index 0000000..52057ed
--- /dev/null
@@ -0,0 +1,12 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include <config.h>
+
+#include <stdbool.h>
+
+#include "string/strcmp/streq.h"
+
+
+extern inline bool streq(const char *s1, const char *s2);
diff --git a/lib/string/strcmp/streq.h b/lib/string/strcmp/streq.h
new file mode 100644 (file)
index 0000000..267045c
--- /dev/null
@@ -0,0 +1,30 @@
+// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STREQ_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STREQ_H_
+
+
+#include <config.h>
+
+#include <stdbool.h>
+#include <string.h>
+
+#include "attr.h"
+
+
+ATTR_STRING(1)
+ATTR_STRING(2)
+inline bool streq(const char *s1, const char *s2);
+
+
+/* Return true if s1 and s2 compare equal.  */
+inline bool
+streq(const char *s1, const char *s2)
+{
+       return strcmp(s1, s2) == 0;
+}
+
+
+#endif  // include guard