summaryrefslogtreecommitdiff
path: root/firmware/common/strcasecmp.c
blob: 7bd0d61dd579a493f09671628d7c947a63d134b3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28

#include <string.h>
#include <ctype.h>

int strcasecmp(const char *s1, const char *s2)
{
    while (*s1 != '\0' && tolower(*s1) == tolower(*s2)) {
        s1++;
        s2++;
    }

    return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
}

int strncasecmp(const char *s1, const char *s2, size_t n)
{
    if(!n)
      return 0;

    while (n-- != 0 && tolower(*s1) == tolower(*s2)) {
        if(n == 0 || *s1 == '\0')
          break;
        s1++;
        s2++;
    }

    return tolower(*(unsigned char *) s1) - tolower(*(unsigned char *) s2);
}