File: strncasecmp.c

package info (click to toggle)
coda 2.20-3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 11,292 kB
  • sloc: ansic: 124,817; sh: 4,657; java: 2,391; python: 1,091; yacc: 1,003; makefile: 596; lex: 204; fortran: 60; xml: 5
file content (36 lines) | stat: -rw-r--r-- 557 bytes parent folder | download | duplicates (4)
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
29
30
31
32
33
34
35
36
#ifdef HAVE_CONFIG_H
#include "config.h"
#endif

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

int strncasecmp(const char *s1, const char *s2, size_t len)
{
    unsigned char us1;
    unsigned char us2;
    size_t index;

    if (len <= 0)
    {
        return 0;
    }

    us1 = tolower(*s1);
    us2 = tolower(*s2);

    index = 0;
    while (index < len && us1 != '\0' && us1 == us2)
    {
        index++;
        us1 = tolower(s1[index]);
        us2 = tolower(s2[index]);
    }

    if (index == len)
    {
        return 0;
    }

    return us1 - us2;
}