1*599546b3Sderaadt /* $OpenBSD: strncmp.c,v 1.4 2003/08/11 06:23:09 deraadt Exp $ */
2c210bb38Smickey
3c210bb38Smickey /*-
4c210bb38Smickey * Copyright (c) 1996 Michael Shalayeff
5c210bb38Smickey * All rights reserved.
6c210bb38Smickey *
7c210bb38Smickey * Redistribution and use in source and binary forms, with or without
8c210bb38Smickey * modification, are permitted provided that the following conditions
9c210bb38Smickey * are met:
10c210bb38Smickey * 1. Redistributions of source code must retain the above copyright
11c210bb38Smickey * notice, this list of conditions and the following disclaimer.
12c210bb38Smickey * 2. Redistributions in binary form must reproduce the above copyright
13c210bb38Smickey * notice, this list of conditions and the following disclaimer in the
14c210bb38Smickey * documentation and/or other materials provided with the distribution.
15c210bb38Smickey *
16c210bb38Smickey * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17c210bb38Smickey * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
18c210bb38Smickey * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19c210bb38Smickey * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
20c210bb38Smickey * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21c210bb38Smickey * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22c210bb38Smickey * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23c210bb38Smickey * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24c210bb38Smickey * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25c210bb38Smickey * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26c210bb38Smickey * SUCH DAMAGE.
27c210bb38Smickey *
28c210bb38Smickey */
29c210bb38Smickey
30c210bb38Smickey #include <sys/types.h>
31c210bb38Smickey #include "stand.h"
32c210bb38Smickey
33c210bb38Smickey int
strncmp(const char * s1,const char * s2,size_t len)34*599546b3Sderaadt strncmp(const char *s1, const char *s2, size_t len)
35c210bb38Smickey {
36c210bb38Smickey if (len-- == 0)
37c210bb38Smickey return 0;
38c210bb38Smickey
39c210bb38Smickey while (*s1 && *s2 && len-- && *s1 == *s2)
40c210bb38Smickey s1++, s2++;
41c210bb38Smickey return *s1 - *s2;
42c210bb38Smickey }
43