chiark / gitweb /
basic: add new ascii_strcasecmp_n() call
authorLennart Poettering <lennart@poettering.net>
Wed, 13 Jan 2016 01:21:16 +0000 (02:21 +0100)
committerSven Eden <yamakuzure@gmx.net>
Wed, 17 May 2017 13:22:15 +0000 (15:22 +0200)
src/basic/string-util.c
src/basic/string-util.h

index e2bdb89765b9adc20faea56efaaadc1814a5c823..dfcb29235546d6764cd0e86f5a14edb221e639b8 100644 (file)
@@ -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;
 
index 8b87c1e23d356e4f3b7d2becf9c9174bc8df3b01..48cdc736fd9c25de56296a3be56f822ec0dbc14a 100644 (file)
@@ -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) {