File: strcasecmp.c

package info (click to toggle)
xfig 1%3A3.2.9a-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 33,016 kB
  • sloc: ansic: 76,504; sh: 3,214; makefile: 303; xml: 112; javascript: 22; csh: 5
file content (22 lines) | stat: -rw-r--r-- 538 bytes parent folder | download | duplicates (12)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
/* strcasecmp by Fred Appelman (Fred.Appelman@cv.ruu.nl) */

#include <ctype.h>

int strcasecmp(const char* s1, const char* s2)
{
	char c1,c2;

	while (*s1 && *s2)
	{
		c1=toupper(*s1++);
		c2=toupper(*s2++);
		if (c1<c2) return -1; /* s1 is "smaller" */
		if (c1>c2) return +1; /* s2 is "smaller" */
	}
	/* Check for end of string, if not both the strings ended they are
	 * not the same.
	 */
	if (*s1=='\0' && *s2!='\0') return -1; /* s1 ended premature */
	if (*s1!='\0' && *s2=='\0') return +1; /* s2 ended premature */
	return 0;
}