summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-13 02:21:16 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit7c1b422919819e9e7af4652b52d5f122a090ce53 (patch)
tree98f8b918f756071786110b717cbf36df7e254adc /src
parent039c931bcd7a6aaf7fb7a8b48b41e2bfb0e6f485 (diff)
basic: add new ascii_strcasecmp_n() call
Diffstat (limited to 'src')
-rw-r--r--src/basic/string-util.c15
-rw-r--r--src/basic/string-util.h2
2 files changed, 17 insertions, 0 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index e2bdb8976..dfcb29235 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -341,6 +341,21 @@ char *ascii_strlower_n(char *t, size_t n) {
return t;
}
+int ascii_strcasecmp_n(const char *a, const char *b, size_t n) {
+
+ for (; n > 0; a++, b++, n--) {
+ int x, y;
+
+ x = (int) (uint8_t) ascii_tolower(*a);
+ y = (int) (uint8_t) ascii_tolower(*b);
+
+ if (x != y)
+ return x - y;
+ }
+
+ return 0;
+}
+
bool chars_intersect(const char *a, const char *b) {
const char *p;
diff --git a/src/basic/string-util.h b/src/basic/string-util.h
index 8b87c1e23..48cdc736f 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -132,6 +132,8 @@ char ascii_tolower(char x);
char *ascii_strlower(char *s);
char *ascii_strlower_n(char *s, size_t n);
+int ascii_strcasecmp_n(const char *a, const char *b, size_t n);
+
bool chars_intersect(const char *a, const char *b) _pure_;
static inline bool _pure_ in_charset(const char *s, const char* charset) {