summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2016-01-13 19:45:05 +0100
committerSven Eden <yamakuzure@gmx.net>2017-05-17 15:22:15 +0200
commit3b22b89bce6c5185e1db0a28390a0e6df138a27b (patch)
tree233c36edbb61688692d647b6a5013e049ceeedea /src
parent7c1b422919819e9e7af4652b52d5f122a090ce53 (diff)
basic: add ascii_strcasecmp_nn() call
In contrast to ascii_strcasecmp_nn() it takes two character buffers with their individual length. It will then compare the buffers up the smaller size of the two buffers, and finally the length themselves.
Diffstat (limited to 'src')
-rw-r--r--src/basic/string-util.c15
-rw-r--r--src/basic/string-util.h1
2 files changed, 16 insertions, 0 deletions
diff --git a/src/basic/string-util.c b/src/basic/string-util.c
index dfcb29235..6f4593e6b 100644
--- a/src/basic/string-util.c
+++ b/src/basic/string-util.c
@@ -356,6 +356,21 @@ int ascii_strcasecmp_n(const char *a, const char *b, size_t n) {
return 0;
}
+int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m) {
+ int r;
+
+ r = ascii_strcasecmp_n(a, b, MIN(n, m));
+ if (r != 0)
+ return r;
+
+ if (n < m)
+ return -1;
+ else if (n > m)
+ return 1;
+ else
+ 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 48cdc736f..7ed649ae6 100644
--- a/src/basic/string-util.h
+++ b/src/basic/string-util.h
@@ -133,6 +133,7 @@ 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);
+int ascii_strcasecmp_nn(const char *a, size_t n, const char *b, size_t m);
bool chars_intersect(const char *a, const char *b) _pure_;