strcasecmp.c revision 84221
140036Smsmith/*
240036Smsmith * Copyright (c) 1987, 1993
340036Smsmith *	The Regents of the University of California.  All rights reserved.
440036Smsmith *
540036Smsmith * Redistribution and use in source and binary forms, with or without
640036Smsmith * modification, are permitted provided that the following conditions
740036Smsmith * are met:
840036Smsmith * 1. Redistributions of source code must retain the above copyright
940036Smsmith *    notice, this list of conditions and the following disclaimer.
1040036Smsmith * 2. Redistributions in binary form must reproduce the above copyright
1140036Smsmith *    notice, this list of conditions and the following disclaimer in the
1240036Smsmith *    documentation and/or other materials provided with the distribution.
1340036Smsmith * 3. All advertising materials mentioning features or use of this software
1440036Smsmith *    must display the following acknowledgement:
1540036Smsmith *	This product includes software developed by the University of
1640036Smsmith *	California, Berkeley and its contributors.
1740036Smsmith * 4. Neither the name of the University nor the names of its contributors
1840036Smsmith *    may be used to endorse or promote products derived from this software
1940036Smsmith *    without specific prior written permission.
2040036Smsmith *
2140036Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2240036Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2340036Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2440036Smsmith * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2540036Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2640036Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2740036Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2840036Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2940036Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3040036Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3140036Smsmith * SUCH DAMAGE.
3240036Smsmith */
3340036Smsmith
3440036Smsmith#include <sys/cdefs.h>
3584221Sdillon__FBSDID("$FreeBSD: head/lib/libstand/strcasecmp.c 84221 2001-09-30 22:28:01Z dillon $");
3684221Sdillon
3784221Sdillon#include <sys/cdefs.h>
3840036Smsmith#include <string.h>
3940036Smsmith#include "stand.h"
4040036Smsmith
4140036Smsmith#if defined(LIBC_SCCS) && !defined(lint)
4240036Smsmithstatic char sccsid[] = "@(#)strcasecmp.c	8.1 (Berkeley) 6/4/93";
4340036Smsmith#endif /* LIBC_SCCS and not lint */
4440036Smsmith
4540036Smsmithint
4640036Smsmithstrcasecmp(s1, s2)
4740036Smsmith	const char *s1, *s2;
4840036Smsmith{
4940036Smsmith	register const u_char
5040036Smsmith			*us1 = (const u_char *)s1,
5140036Smsmith			*us2 = (const u_char *)s2;
5240036Smsmith
5340036Smsmith	while (tolower(*us1) == tolower(*us2++))
5440036Smsmith		if (*us1++ == '\0')
5540036Smsmith			return (0);
5640036Smsmith	return (tolower(*us1) - tolower(*--us2));
5740036Smsmith}
5840036Smsmith
5940036Smsmithint
6040036Smsmithstrncasecmp(s1, s2, n)
6140036Smsmith	const char *s1, *s2;
6240036Smsmith	register size_t n;
6340036Smsmith{
6440036Smsmith	if (n != 0) {
6540036Smsmith		register const u_char
6640036Smsmith				*us1 = (const u_char *)s1,
6740036Smsmith				*us2 = (const u_char *)s2;
6840036Smsmith
6940036Smsmith		do {
7040036Smsmith			if (tolower(*us1) != tolower(*us2++))
7140036Smsmith				return (tolower(*us1) - tolower(*--us2));
7240036Smsmith			if (*us1++ == '\0')
7340036Smsmith				break;
7440036Smsmith		} while (--n != 0);
7540036Smsmith	}
7640036Smsmith	return (0);
7740036Smsmith}
78