1139815Simp/*- 26761Sugen * Copyright (c) 1989, 1993 36761Sugen * The Regents of the University of California. All rights reserved. 46761Sugen * 56761Sugen * Redistribution and use in source and binary forms, with or without 66761Sugen * modification, are permitted provided that the following conditions 76761Sugen * are met: 86761Sugen * 1. Redistributions of source code must retain the above copyright 96761Sugen * notice, this list of conditions and the following disclaimer. 106761Sugen * 2. Redistributions in binary form must reproduce the above copyright 116761Sugen * notice, this list of conditions and the following disclaimer in the 126761Sugen * documentation and/or other materials provided with the distribution. 13275489Sdelphij * 3. Neither the name of the University nor the names of its contributors 146761Sugen * may be used to endorse or promote products derived from this software 156761Sugen * without specific prior written permission. 166761Sugen * 176761Sugen * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 186761Sugen * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 196761Sugen * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 206761Sugen * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 216761Sugen * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 226761Sugen * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 236761Sugen * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 246761Sugen * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 256761Sugen * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 266761Sugen * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 276761Sugen * SUCH DAMAGE. 286761Sugen */ 296761Sugen 30116189Sobrien#include <sys/cdefs.h> 31116189Sobrien__FBSDID("$FreeBSD$"); 32116189Sobrien 33102281Sjhb#include <sys/libkern.h> 346761Sugen 356761Sugenint 36275489Sdelphijstrncmp(const char *s1, const char *s2, size_t n) 376761Sugen{ 386761Sugen 396761Sugen if (n == 0) 406761Sugen return (0); 416761Sugen do { 426761Sugen if (*s1 != *s2++) 4317974Sbde return (*(const unsigned char *)s1 - 4417974Sbde *(const unsigned char *)(s2 - 1)); 45275489Sdelphij if (*s1++ == '\0') 466761Sugen break; 476761Sugen } while (--n != 0); 486761Sugen return (0); 496761Sugen} 50