]> git.ipfire.org Git - thirdparty/shadow.git/commitdiff
lib/string/strcmp/: str{,case}eq(): Simplify implementation
authorAlejandro Colomar <alx@kernel.org>
Thu, 26 Feb 2026 16:54:24 +0000 (17:54 +0100)
committerSerge Hallyn <serge@hallyn.com>
Sat, 28 Feb 2026 03:03:40 +0000 (21:03 -0600)
A one-liner macro is simpler, and works just fine.

We don't need the function at all, since we don't use it as a callback.
The macro changes the return type, but we don't really care about that
detail; we could cast it to bool, but we don't really need that, so keep
it simple.

Reviewed-by: Kees Cook <kees@kernel.org>
Signed-off-by: Alejandro Colomar <alx@kernel.org>
lib/string/strcmp/strcaseeq.c
lib/string/strcmp/strcaseeq.h
lib/string/strcmp/streq.c
lib/string/strcmp/streq.h

index e44f1166b3bf1bc1adbfc5897a00bdc1dbbf7f06..045d2d452f911c75e940c051463395bbc97af402 100644 (file)
@@ -1,12 +1,7 @@
-// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2026, 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);
index 41a8d56300cc82ad1ec178e7086a2feb32697f21..ec0e3d0adabdba2f893a60368a320c0dcbb3c188 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
@@ -8,23 +8,11 @@
 
 #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);
-
-
-// strings case-insensitive equal
-// streq(), but case-insensitive.
-inline bool
-strcaseeq(const char *s1, const char *s2)
-{
-       return strcasecmp(s1, s2) == 0;
-}
+// strcaseeq - strings case-insensitive equal
+#define strcaseeq(s1, s2)  (!strcasecmp(s1, s2))
 
 
 #endif  // include guard
index 030169addfbda3858210dea8b74ae8fdebf65b9f..b46cc98a21abbaee7125b7cc533fa8a02936085c 100644 (file)
@@ -1,12 +1,7 @@
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2026, 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);
index fc0268cb032c3ed8051264a39f63fb2f0bcec9c6..e56ef1cf694eb8db13e7c03636d6b2772337b092 100644 (file)
@@ -1,4 +1,4 @@
-// SPDX-FileCopyrightText: 2024, Alejandro Colomar <alx@kernel.org>
+// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <alx@kernel.org>
 // SPDX-License-Identifier: BSD-3-Clause
 
 
@@ -8,24 +8,11 @@
 
 #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);
-
-
-// strings equal
-/* Return true if s1 and s2 compare equal.  */
-inline bool
-streq(const char *s1, const char *s2)
-{
-       return strcmp(s1, s2) == 0;
-}
+// streq - strings equal
+#define streq(s1, s2)  (!strcmp(s1, s2))
 
 
 #endif  // include guard