aboutsummaryrefslogtreecommitdiffstats
path: root/strcasecmp.c
blob: d52bd2905a18a8321f69591612994997c7f4dc2d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
/* 
 * scratch implementation of strcasecmp(), 
 * in case your C library doesn't have it 
 */
#include <ctype.h>

strcasecmp(char *s1, char *s2)
{
    while (toupper(*s1) == toupper(*s2++))
	if (*s1++ == '\0')
	    return(0);
    return(toupper(*s1) - toupper(*--s2));
}

strncasecmp(char *s1, char *s2, register int n)
{
    while (--n >= 0 && toupper(*s1) == toupper(*s2++))
	if (toupper(*s1++) == '\0')
	    return(0);
    return(n < 0 ? 0 : toupper(*s1) - toupper(*--s2));
}