summaryrefslogtreecommitdiff
path: root/prism/util/pm_strncasecmp.c
blob: fce11835e058370e1ffbebc5b6c2ed46d40318af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <ctype.h>
#include <stddef.h>
#include <stdint.h>

int
pm_strncasecmp(const uint8_t *string1, const uint8_t *string2, size_t length) {
    size_t offset = 0;
    int difference = 0;

    while (offset < length && string1[offset] != '\0') {
        if (string2[offset] == '\0') return string1[offset];
        if ((difference = tolower(string1[offset]) - tolower(string2[offset])) != 0) return difference;
        offset++;
    }

    return difference;
}