string/strcmp/strcaseprefix.h \
string/strcmp/streq.c \
string/strcmp/streq.h \
+ string/strcmp/strneq.c \
+ string/strcmp/strneq.h \
string/strcmp/strprefix.c \
string/strcmp/strprefix.h \
string/strcpy/stpecpy.c \
The return value of strcmp(3) is confusing.
strcmp(3) would be legitimate for sorting strings.
+ strncmp(3)
+ Use STRNEQ(), or strpfx(), or else, depending on what you want.
+ The return value of strncmp(3) is confusing,
+ and it is unclear the purpose of its use when you read it.
+
strcasecmp(3)
Use strcaseeq() instead.
Like strsfx(), but ignore upper-/lower-case.
n/
- strneq() // Unimplemented
+ strneq()
Return true if a [[gnu::nonstring]] is equal to a string.
- STRNEQ() // Unimplemented
+ STRNEQ()
Like strneq(), but takes an array.
strnpfx() // Unimplemented
--- /dev/null
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#include "config.h"
+
+#include "string/strcmp/strneq.h"
+
+#include <stdbool.h>
+#include <stddef.h>
+
+
+extern inline bool strneq(const char *strn, const char *s, size_t size);
--- /dev/null
+// SPDX-FileCopyrightText: 2025, Alejandro Colomar <alx@kernel.org>
+// SPDX-License-Identifier: BSD-3-Clause
+
+
+#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STRNEQ_H_
+#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRNEQ_H_
+
+
+#include "config.h"
+
+#include <stdbool.h>
+#include <string.h>
+
+#include "attr.h"
+#include "sizeof.h"
+
+
+#define STRNEQ(strn, s) strneq(strn, s, countof(strn))
+
+
+ATTR_STRING(2)
+inline bool strneq(ATTR_NONSTRING const char *strn, const char *s, size_t size);
+
+
+// nonstring equal
+/* Return true if the nonstring strn and the string s compare equal. */
+inline bool
+strneq(const char *strn, const char *s, size_t size)
+{
+ if (strlen(s) > size)
+ return false;
+
+ return strncmp(strn, s, size) == 0;
+}
+
+
+#endif // include guard