1e05c4d0joel/*-
29da7bddpfg * SPDX-License-Identifier: BSD-4-Clause
39da7bddpfg *
4a4b69e0pjd * Copyright (c) 1987, 1993
5a4b69e0pjd *	The Regents of the University of California.  All rights reserved.
6a4b69e0pjd *
7a4b69e0pjd * Redistribution and use in source and binary forms, with or without
8a4b69e0pjd * modification, are permitted provided that the following conditions
9a4b69e0pjd * are met:
10a4b69e0pjd * 1. Redistributions of source code must retain the above copyright
11a4b69e0pjd *    notice, this list of conditions and the following disclaimer.
12a4b69e0pjd * 2. Redistributions in binary form must reproduce the above copyright
13a4b69e0pjd *    notice, this list of conditions and the following disclaimer in the
14a4b69e0pjd *    documentation and/or other materials provided with the distribution.
15a4b69e0pjd * 3. All advertising materials mentioning features or use of this software
16a4b69e0pjd *    must display the following acknowledgement:
17a4b69e0pjd *	This product includes software developed by the University of
18a4b69e0pjd *	California, Berkeley and its contributors.
19a4b69e0pjd * 4. Neither the name of the University nor the names of its contributors
20a4b69e0pjd *    may be used to endorse or promote products derived from this software
21a4b69e0pjd *    without specific prior written permission.
22a4b69e0pjd *
23a4b69e0pjd * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24a4b69e0pjd * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25a4b69e0pjd * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26a4b69e0pjd * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27a4b69e0pjd * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28a4b69e0pjd * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29a4b69e0pjd * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30a4b69e0pjd * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31a4b69e0pjd * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32a4b69e0pjd * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33a4b69e0pjd * SUCH DAMAGE.
34a4b69e0pjd */
35a4b69e0pjd
36a4b69e0pjd#include <sys/cdefs.h>
37a4b69e0pjd__FBSDID("$FreeBSD$");
38a4b69e0pjd
39a4b69e0pjd#include <sys/param.h>
40a4b69e0pjd#include <sys/ctype.h>
41a4b69e0pjd#include <sys/libkern.h>
42a4b69e0pjd
43a4b69e0pjdint
44a4b69e0pjdstrcasecmp(const char *s1, const char *s2)
45a4b69e0pjd{
46a4b69e0pjd	const u_char *us1 = (const u_char *)s1, *us2 = (const u_char *)s2;
47a4b69e0pjd
48e540031pjd	while (tolower(*us1) == tolower(*us2)) {
49a4b69e0pjd		if (*us1++ == '\0')
50a4b69e0pjd			return (0);
51e540031pjd		us2++;
52a4b69e0pjd	}
53e540031pjd	return (tolower(*us1) - tolower(*us2));
54a4b69e0pjd}
55a4b69e0pjd
56a4b69e0pjdint
57a4b69e0pjdstrncasecmp(const char *s1, const char *s2, size_t n)
58a4b69e0pjd{
59a4b69e0pjd
60a4b69e0pjd	if (n != 0) {
61a4b69e0pjd		const u_char *us1 = (const u_char *)s1;
62a4b69e0pjd		const u_char *us2 = (const u_char *)s2;
63a4b69e0pjd
64a4b69e0pjd		do {
65e540031pjd			if (tolower(*us1) != tolower(*us2))
66e540031pjd				return (tolower(*us1) - tolower(*us2));
67a4b69e0pjd			if (*us1++ == '\0')
68a4b69e0pjd				break;
69e540031pjd			us2++;
70a4b69e0pjd		} while (--n != 0);
71a4b69e0pjd	}
72a4b69e0pjd	return (0);
73a4b69e0pjd}
74