diff options
author | Daniel Stenberg <daniel@haxx.se> | 2016-10-31 23:49:54 +0100 |
---|---|---|
committer | Daniel Stenberg <daniel@haxx.se> | 2016-10-31 23:49:54 +0100 |
commit | 07b95ea2680990055d12c935994044dfa24d8e9b (patch) | |
tree | 6009a02d30c4b682e9194c2bb0e86b07b354a51b /tests/server/util.c | |
parent | 95bd2b3e7f00b9ecbd4d5ea7d8bc3b59fcb038c0 (diff) | |
download | curl-07b95ea2680990055d12c935994044dfa24d8e9b.tar.gz |
tests/util: get a private strncasecompare clone
... since the curlx_* code no longer provides one and we don't link
libcurl to these test servers.
Diffstat (limited to 'tests/server/util.c')
-rw-r--r-- | tests/server/util.c | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/tests/server/util.c b/tests/server/util.c index d99336397..e65470786 100644 --- a/tests/server/util.c +++ b/tests/server/util.c @@ -305,3 +305,87 @@ void clear_advisor_read_lock(const char *filename) logmsg("Error removing lock file %s error: %d %s", filename, error, strerror(error)); } + + +/* Portable, consistent toupper (remember EBCDIC). Do not use toupper() because + its behavior is altered by the current locale. */ +static char raw_toupper(char in) +{ +#if !defined(CURL_DOES_CONVERSIONS) + if(in >= 'a' && in <= 'z') + return (char)('A' + in - 'a'); +#else + switch (in) { + case 'a': + return 'A'; + case 'b': + return 'B'; + case 'c': + return 'C'; + case 'd': + return 'D'; + case 'e': + return 'E'; + case 'f': + return 'F'; + case 'g': + return 'G'; + case 'h': + return 'H'; + case 'i': + return 'I'; + case 'j': + return 'J'; + case 'k': + return 'K'; + case 'l': + return 'L'; + case 'm': + return 'M'; + case 'n': + return 'N'; + case 'o': + return 'O'; + case 'p': + return 'P'; + case 'q': + return 'Q'; + case 'r': + return 'R'; + case 's': + return 'S'; + case 't': + return 'T'; + case 'u': + return 'U'; + case 'v': + return 'V'; + case 'w': + return 'W'; + case 'x': + return 'X'; + case 'y': + return 'Y'; + case 'z': + return 'Z'; + } +#endif + + return in; +} + +int strncasecompare(const char *first, const char *second, size_t max) +{ + while(*first && *second && max) { + if(raw_toupper(*first) != raw_toupper(*second)) { + break; + } + max--; + first++; + second++; + } + if(0 == max) + return 1; /* they are equal this far */ + + return raw_toupper(*first) == raw_toupper(*second); +} |