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.
136761Sugen * 4. 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
366761Sugenstrncmp(s1, s2, n)
376761Sugen	register const char *s1, *s2;
386761Sugen	register size_t n;
396761Sugen{
406761Sugen
416761Sugen	if (n == 0)
426761Sugen		return (0);
436761Sugen	do {
446761Sugen		if (*s1 != *s2++)
4517974Sbde			return (*(const unsigned char *)s1 -
4617974Sbde				*(const unsigned char *)(s2 - 1));
476761Sugen		if (*s1++ == 0)
486761Sugen			break;
496761Sugen	} while (--n != 0);
506761Sugen	return (0);
516761Sugen}
52