1218887Sdim/*-
2218887Sdim * Copyright (c) 1987, 1993
3218887Sdim *	The Regents of the University of California.  All rights reserved.
4218887Sdim *
5218887Sdim * Redistribution and use in source and binary forms, with or without
6218887Sdim * modification, are permitted provided that the following conditions
7218887Sdim * are met:
8218887Sdim * 1. Redistributions of source code must retain the above copyright
9218887Sdim *    notice, this list of conditions and the following disclaimer.
10218887Sdim * 2. Redistributions in binary form must reproduce the above copyright
11218887Sdim *    notice, this list of conditions and the following disclaimer in the
12218887Sdim *    documentation and/or other materials provided with the distribution.
13218887Sdim * 3. All advertising materials mentioning features or use of this software
14218887Sdim *    must display the following acknowledgement:
15218887Sdim *	This product includes software developed by the University of
16218887Sdim *	California, Berkeley and its contributors.
17218887Sdim * 4. Neither the name of the University nor the names of its contributors
18218887Sdim *    may be used to endorse or promote products derived from this software
19249423Sdim *    without specific prior written permission.
20218887Sdim *
21218887Sdim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22218887Sdim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23218887Sdim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24218887Sdim * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25224145Sdim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26221345Sdim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27218887Sdim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28218887Sdim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29218887Sdim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30218887Sdim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31249423Sdim * SUCH DAMAGE.
32218887Sdim */
33218887Sdim
34218887Sdim#include <sys/cdefs.h>
35218887Sdim__FBSDID("$FreeBSD$");
36218887Sdim
37218887Sdim#include <sys/param.h>
38218887Sdim#include <sys/ctype.h>
39218887Sdim#include <sys/libkern.h>
40218887Sdim
41218887Sdimint
42218887Sdimstrcasecmp(const char *s1, const char *s2)
43218887Sdim{
44234353Sdim	const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2;
45234353Sdim
46234353Sdim	while (tolower(*us1) == tolower(*us2)) {
47234353Sdim		if (*us1++ == '\0')
48234353Sdim			return (0);
49234353Sdim		us2++;
50234353Sdim	}
51234353Sdim	return (tolower(*us1) - tolower(*us2));
52234353Sdim}
53234353Sdim
54234353Sdimint
55234353Sdimstrncasecmp(const char *s1, const char *s2, size_t n)
56234353Sdim{
57234353Sdim
58234353Sdim	if (n != 0) {
59263508Sdim		const u_char *us1 = (const u_char *)s1;
60263508Sdim		const u_char *us2 = (const u_char *)s2;
61263508Sdim
62263508Sdim		do {
63263508Sdim			if (tolower(*us1) != tolower(*us2))
64263508Sdim				return (tolower(*us1) - tolower(*us2));
65263508Sdim			if (*us1++ == '\0')
66234353Sdim				break;
67263508Sdim			us2++;
68263508Sdim		} while (--n != 0);
69263508Sdim	}
70263508Sdim	return (0);
71263508Sdim}
72234353Sdim