15dfecf96Smrg/* $XFree86: xc/programs/xedit/strcasecmp.c,v 1.1 1999/06/14 02:38:07 dawes Exp $ */
25dfecf96Smrg
35dfecf96Smrg#include <ctype.h>
45dfecf96Smrg#include <sys/types.h>
55dfecf96Smrg
65dfecf96Smrg#ifndef LISP
75dfecf96Smrg#include "xedit.h"
85dfecf96Smrg#endif
95dfecf96Smrg
105dfecf96Smrg/* Just like the BSD version.  It assumes that tolower() is ANSI-compliant */
115dfecf96Smrg
125dfecf96Smrgint
135dfecf96Smrgstrcasecmp(const char *s1, const char *s2)
145dfecf96Smrg{
155dfecf96Smrg	const unsigned char *us1 = (const unsigned char *)s1;
165dfecf96Smrg	const unsigned char *us2 = (const unsigned char *)s2;
175dfecf96Smrg
185dfecf96Smrg	while (tolower(*us1) == tolower(*us2++))
195dfecf96Smrg		if (*us1++ == '\0')
205dfecf96Smrg			return 0;
215dfecf96Smrg	return tolower(*us1) - tolower(*--us2);
225dfecf96Smrg}
235dfecf96Smrg
245dfecf96Smrgint
255dfecf96Smrgstrncasecmp(const char *s1, const char *s2, size_t n)
265dfecf96Smrg{
275dfecf96Smrg	if (n != 0) {
285dfecf96Smrg		const unsigned char *us1 = (const unsigned char *)s1;
295dfecf96Smrg		const unsigned char *us2 = (const unsigned char *)s2;
305dfecf96Smrg
315dfecf96Smrg		do {
325dfecf96Smrg			if (tolower(*us1) != tolower(*us2++))
335dfecf96Smrg				return tolower(*us1) - tolower(*--us2);
345dfecf96Smrg			if (*us1++ == '\0')
355dfecf96Smrg				break;
365dfecf96Smrg		} while (--n != 0);
375dfecf96Smrg	}
385dfecf96Smrg	return 0;
395dfecf96Smrg}
405dfecf96Smrg
41