Skip to content

Commit ff33eca

Browse files
lib/string/strcmp/: streq(): 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. Signed-off-by: Alejandro Colomar <[email protected]>
1 parent f27656a commit ff33eca

File tree

2 files changed

+4
-22
lines changed

2 files changed

+4
-22
lines changed

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)