From 522d85ae0a3dd80ec58033289c4f63ba7dfc63a8 Mon Sep 17 00:00:00 2001 From: Lennart Poettering Date: Wed, 13 Jan 2016 02:21:16 +0100 Subject: basic: add new ascii_strcasecmp_n() call --- src/basic/string-util.c | 15 +++++++++++++++ src/basic/string-util.h | 2 ++ 2 files changed, 17 insertions(+) (limited to 'src/basic') diff --git a/src/basic/string-util.c b/src/basic/string-util.c index 849e457439..b7b8c97bc0 100644 --- a/src/basic/string-util.c +++ b/src/basic/string-util.c @@ -348,6 +348,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 1ac6bcd6f8..6374e11119 100644 --- a/src/basic/string-util.h +++ b/src/basic/string-util.h @@ -134,6 +134,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) { -- cgit v1.2.3-54-g00ecf