File: strcasecmp.c

package info (click to toggle)
nmh 1.0.2-9
  • links: PTS
  • area: main
  • in suites: potato
  • size: 3,172 kB
  • ctags: 4,449
  • sloc: ansic: 50,696; sh: 1,799; makefile: 1,192; awk: 74; sed: 17
file content (53 lines) | stat: -rw-r--r-- 1,030 bytes parent folder | download | duplicates (2)
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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53

/*
 * strcasecmp.c -- compare strings, ignoring case
 *
 * $Id: strcasecmp.c,v 1.1.1.1 1999/04/30 18:08:34 doug Exp $
 */

#include <h/mh.h>

/*
 * Our version of strcasecmp has to deal with NULL strings.
 * Once that is fixed in the rest of the code, we can use the
 * native version, instead of this one.
 */

int
strcasecmp (const char *s1, const char *s2) 
{
    const unsigned char *us1, *us2;

    us1 = (const unsigned char *) s1,
    us2 = (const unsigned char *) s2;

    if (!us1)
	us1 = "";
    if (!us2)
	us2 = "";
 
    while (tolower(*us1) == tolower(*us2++)) 
	if (*us1++ == '\0')
	    return (0);
    return (tolower(*us1) - tolower(*--us2));
}
 

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

    if (n != 0) { 
	us1 = (const unsigned char *) s1,
	us2 = (const unsigned char *) s2;

	do {  
	    if (tolower(*us1) != tolower(*us2++))
		return (tolower(*us1) - tolower(*--us2));
	    if (*us1++ == '\0')
		break;  
	} while (--n != 0);
    } 
    return (0);
}