strcasecmp.c revision 84221
138032Speter/*
238032Speter * Copyright (c) 1987, 1993
364565Sgshapiro *	The Regents of the University of California.  All rights reserved.
464565Sgshapiro *
538032Speter * Redistribution and use in source and binary forms, with or without
638032Speter * modification, are permitted provided that the following conditions
738032Speter * are met:
838032Speter * 1. Redistributions of source code must retain the above copyright
938032Speter *    notice, this list of conditions and the following disclaimer.
1038032Speter * 2. Redistributions in binary form must reproduce the above copyright
1138032Speter *    notice, this list of conditions and the following disclaimer in the
1238032Speter *    documentation and/or other materials provided with the distribution.
1338032Speter * 3. All advertising materials mentioning features or use of this software
1464565Sgshapiro *    must display the following acknowledgement:
1538032Speter *	This product includes software developed by the University of
1664565Sgshapiro *	California, Berkeley and its contributors.
1764565Sgshapiro * 4. Neither the name of the University nor the names of its contributors
1838032Speter *    may be used to endorse or promote products derived from this software
1938032Speter *    without specific prior written permission.
2038032Speter *
2138032Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2238032Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2338032Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2438032Speter * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2538032Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2638032Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2738032Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2838032Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2938032Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
3038032Speter * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3138032Speter * SUCH DAMAGE.
3238032Speter */
3338032Speter
3438032Speter#include <sys/cdefs.h>
3538032Speter__FBSDID("$FreeBSD: head/lib/libstand/strcasecmp.c 84221 2001-09-30 22:28:01Z dillon $");
3638032Speter
3738032Speter#include <sys/cdefs.h>
3838032Speter#include <string.h>
3938032Speter#include "stand.h"
4038032Speter
4138032Speter#if defined(LIBC_SCCS) && !defined(lint)
4238032Speterstatic char sccsid[] = "@(#)strcasecmp.c	8.1 (Berkeley) 6/4/93";
4338032Speter#endif /* LIBC_SCCS and not lint */
4438032Speter
4538032Speterint
4638032Speterstrcasecmp(s1, s2)
4738032Speter	const char *s1, *s2;
4838032Speter{
4938032Speter	register const u_char
5038032Speter			*us1 = (const u_char *)s1,
5138032Speter			*us2 = (const u_char *)s2;
5238032Speter
5338032Speter	while (tolower(*us1) == tolower(*us2++))
5438032Speter		if (*us1++ == '\0')
5538032Speter			return (0);
5638032Speter	return (tolower(*us1) - tolower(*--us2));
5738075Speter}
5838032Speter
5938032Speterint
6038032Speterstrncasecmp(s1, s2, n)
61	const char *s1, *s2;
62	register size_t n;
63{
64	if (n != 0) {
65		register const u_char
66				*us1 = (const u_char *)s1,
67				*us2 = (const u_char *)s2;
68
69		do {
70			if (tolower(*us1) != tolower(*us2++))
71				return (tolower(*us1) - tolower(*--us2));
72			if (*us1++ == '\0')
73				break;
74		} while (--n != 0);
75	}
76	return (0);
77}
78