1155e9eb1SToomas Soome /*
2155e9eb1SToomas Soome * Copyright (c) 2009 David Schultz <das@FreeBSD.org>
3155e9eb1SToomas Soome * All rights reserved.
4155e9eb1SToomas Soome *
5155e9eb1SToomas Soome * Redistribution and use in source and binary forms, with or without
6155e9eb1SToomas Soome * modification, are permitted provided that the following conditions
7155e9eb1SToomas Soome * are met:
8155e9eb1SToomas Soome * 1. Redistributions of source code must retain the above copyright
9155e9eb1SToomas Soome * notice, this list of conditions and the following disclaimer.
10155e9eb1SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright
11155e9eb1SToomas Soome * notice, this list of conditions and the following disclaimer in the
12155e9eb1SToomas Soome * documentation and/or other materials provided with the distribution.
13155e9eb1SToomas Soome *
14155e9eb1SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15155e9eb1SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16155e9eb1SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17155e9eb1SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18155e9eb1SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19155e9eb1SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20155e9eb1SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21155e9eb1SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22155e9eb1SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23155e9eb1SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
24155e9eb1SToomas Soome * SUCH DAMAGE.
25155e9eb1SToomas Soome */
26155e9eb1SToomas Soome
27155e9eb1SToomas Soome #include <sys/cdefs.h>
28155e9eb1SToomas Soome #include <string.h>
29155e9eb1SToomas Soome
30155e9eb1SToomas Soome char *
stpncpy(char * __restrict dst,const char * __restrict src,size_t n)31155e9eb1SToomas Soome stpncpy(char * __restrict dst, const char * __restrict src, size_t n)
32155e9eb1SToomas Soome {
33155e9eb1SToomas Soome
34155e9eb1SToomas Soome for (; n--; dst++, src++) {
35155e9eb1SToomas Soome if (!(*dst = *src)) {
36155e9eb1SToomas Soome char *ret = dst;
37155e9eb1SToomas Soome while (n--)
38155e9eb1SToomas Soome *++dst = '\0';
39155e9eb1SToomas Soome return (ret);
40155e9eb1SToomas Soome }
41155e9eb1SToomas Soome }
42155e9eb1SToomas Soome return (dst);
43155e9eb1SToomas Soome }
44