Skip to content

Commit 0983531

Browse files
alejandro-colomarhallyn
authored andcommitted
lib/string/strcmp/: str{,case}eq(): Simplify implementation
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 <[email protected]> Signed-off-by: Alejandro Colomar <[email protected]>
1 parent ea80db6 commit 0983531

File tree

4 files changed

+8
-43
lines changed

4 files changed

+8
-43
lines changed

lib/string/strcmp/strcaseeq.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

55
#include "config.h"
66

7-
#include <stdbool.h>
8-
97
#include "string/strcmp/strcaseeq.h"
10-
11-
12-
extern inline bool strcaseeq(const char *s1, const char *s2);

lib/string/strcmp/strcaseeq.h

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024-2025, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -8,23 +8,11 @@
88

99
#include "config.h"
1010

11-
#include <stdbool.h>
1211
#include <strings.h>
1312

14-
#include "attr.h"
1513

16-
17-
ATTR_STRING(1) ATTR_STRING(2)
18-
inline bool strcaseeq(const char *s1, const char *s2);
19-
20-
21-
// strings case-insensitive equal
22-
// streq(), but case-insensitive.
23-
inline bool
24-
strcaseeq(const char *s1, const char *s2)
25-
{
26-
return strcasecmp(s1, s2) == 0;
27-
}
14+
// strcaseeq - strings case-insensitive equal
15+
#define strcaseeq(s1, s2) (!strcasecmp(s1, s2))
2816

2917

3018
#endif // include guard

lib/string/strcmp/streq.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,7 @@
1-
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

55
#include "config.h"
66

7-
#include <stdbool.h>
8-
97
#include "string/strcmp/streq.h"
10-
11-
12-
extern inline bool streq(const char *s1, const char *s2);

lib/string/strcmp/streq.h

Lines changed: 3 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
1+
// SPDX-FileCopyrightText: 2024-2026, Alejandro Colomar <[email protected]>
22
// SPDX-License-Identifier: BSD-3-Clause
33

44

@@ -8,24 +8,11 @@
88

99
#include "config.h"
1010

11-
#include <stdbool.h>
1211
#include <string.h>
1312

14-
#include "attr.h"
1513

16-
17-
ATTR_STRING(1)
18-
ATTR_STRING(2)
19-
inline bool streq(const char *s1, const char *s2);
20-
21-
22-
// strings equal
23-
/* Return true if s1 and s2 compare equal. */
24-
inline bool
25-
streq(const char *s1, const char *s2)
26-
{
27-
return strcmp(s1, s2) == 0;
28-
}
14+
// streq - strings equal
15+
#define streq(s1, s2) (!strcmp(s1, s2))
2916

3017

3118
#endif // include guard

0 commit comments

Comments
 (0)