strcasecmp.c revision 40036
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> 3540036Smsmith#include <string.h> 3640036Smsmith#include "stand.h" 3740036Smsmith 3840036Smsmith#if defined(LIBC_SCCS) && !defined(lint) 3940036Smsmithstatic char sccsid[] = "@(#)strcasecmp.c 8.1 (Berkeley) 6/4/93"; 4040036Smsmith#endif /* LIBC_SCCS and not lint */ 4140036Smsmith 4240036Smsmithint 4340036Smsmithstrcasecmp(s1, s2) 4440036Smsmith const char *s1, *s2; 4540036Smsmith{ 4640036Smsmith register const u_char 4740036Smsmith *us1 = (const u_char *)s1, 4840036Smsmith *us2 = (const u_char *)s2; 4940036Smsmith 5040036Smsmith while (tolower(*us1) == tolower(*us2++)) 5140036Smsmith if (*us1++ == '\0') 5240036Smsmith return (0); 5340036Smsmith return (tolower(*us1) - tolower(*--us2)); 5440036Smsmith} 5540036Smsmith 5640036Smsmithint 5740036Smsmithstrncasecmp(s1, s2, n) 5840036Smsmith const char *s1, *s2; 5940036Smsmith register size_t n; 6040036Smsmith{ 6140036Smsmith if (n != 0) { 6240036Smsmith register const u_char 6340036Smsmith *us1 = (const u_char *)s1, 6440036Smsmith *us2 = (const u_char *)s2; 6540036Smsmith 6640036Smsmith do { 6740036Smsmith if (tolower(*us1) != tolower(*us2++)) 6840036Smsmith return (tolower(*us1) - tolower(*--us2)); 6940036Smsmith if (*us1++ == '\0') 7040036Smsmith break; 7140036Smsmith } while (--n != 0); 7240036Smsmith } 7340036Smsmith return (0); 7440036Smsmith} 75