Skip to content

Commit 4eb2c50

Browse files
lib/string/strcmp/: strcaseeq(): Add function
Signed-off-by: Alejandro Colomar <[email protected]>
1 parent 929d3e1 commit 4eb2c50

File tree

3 files changed

+44
-0
lines changed

3 files changed

+44
-0
lines changed

lib/Makefile.am

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -204,6 +204,8 @@ libshadow_la_SOURCES = \
204204
string/strchr/strnul.h \
205205
string/strchr/strrspn.c \
206206
string/strchr/strrspn.h \
207+
string/strcmp/strcaseeq.c \
208+
string/strcmp/strcaseeq.h \
207209
string/strcmp/streq.c \
208210
string/strcmp/streq.h \
209211
string/strcpy/stpecpy.c \

lib/string/strcmp/strcaseeq.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
5+
#include <config.h>
6+
7+
#include <stdbool.h>
8+
9+
#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: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// SPDX-FileCopyrightText: 2024, Alejandro Colomar <[email protected]>
2+
// SPDX-License-Identifier: BSD-3-Clause
3+
4+
5+
#ifndef SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
6+
#define SHADOW_INCLUDE_LIB_STRING_STRCMP_STRCASEEQ_H_
7+
8+
9+
#include <config.h>
10+
11+
#include <stdbool.h>
12+
#include <strings.h>
13+
14+
#include "attr.h"
15+
16+
17+
ATTR_STRING(1)
18+
ATTR_STRING(2)
19+
inline bool strcaseeq(const char *s1, const char *s2);
20+
21+
22+
// streq(), but case-insensitive.
23+
inline bool
24+
strcaseeq(const char *s1, const char *s2)
25+
{
26+
return strcasecmp(s1, s2) == 0;
27+
}
28+
29+
30+
#endif // include guard

0 commit comments

Comments
 (0)