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