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 * 4. Neither the name of the University nor the names of its contributors 1440036Smsmith * may be used to endorse or promote products derived from this software 1540036Smsmith * without specific prior written permission. 1640036Smsmith * 1740036Smsmith * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 1840036Smsmith * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 1940036Smsmith * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2040036Smsmith * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2140036Smsmith * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2240036Smsmith * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2340036Smsmith * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2440036Smsmith * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2540036Smsmith * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2640036Smsmith * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 2740036Smsmith * SUCH DAMAGE. 2840036Smsmith */ 2940036Smsmith 3040036Smsmith#include <sys/cdefs.h> 3184221Sdillon__FBSDID("$FreeBSD: stable/11/stand/libsa/strcasecmp.c 329132 2018-02-11 19:51:29Z kevans $"); 3284221Sdillon 3384221Sdillon#include <sys/cdefs.h> 3440036Smsmith#include <string.h> 3540036Smsmith#include "stand.h" 3640036Smsmith 3740036Smsmith#if defined(LIBC_SCCS) && !defined(lint) 3840036Smsmithstatic char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; 3940036Smsmith#endif /* LIBC_SCCS and not lint */ 4040036Smsmith 4140036Smsmithint 4240036Smsmithstrcasecmp(s1, s2) 4340036Smsmith const char *s1, *s2; 4440036Smsmith{ 4592913Sobrien const u_char 4640036Smsmith *us1 = (const u_char *)s1, 4740036Smsmith *us2 = (const u_char *)s2; 4840036Smsmith 4940036Smsmith while (tolower(*us1) == tolower(*us2++)) 5040036Smsmith if (*us1++ == '\0') 5140036Smsmith return (0); 5240036Smsmith return (tolower(*us1) - tolower(*--us2)); 5340036Smsmith} 5440036Smsmith 5540036Smsmithint 5640036Smsmithstrncasecmp(s1, s2, n) 5740036Smsmith const char *s1, *s2; 5892913Sobrien size_t n; 5940036Smsmith{ 6040036Smsmith if (n != 0) { 6192913Sobrien const u_char 6240036Smsmith *us1 = (const u_char *)s1, 6340036Smsmith *us2 = (const u_char *)s2; 6440036Smsmith 6540036Smsmith do { 6640036Smsmith if (tolower(*us1) != tolower(*us2++)) 6740036Smsmith return (tolower(*us1) - tolower(*--us2)); 6840036Smsmith if (*us1++ == '\0') 6940036Smsmith break; 7040036Smsmith } while (--n != 0); 7140036Smsmith } 7240036Smsmith return (0); 7340036Smsmith} 74