1*cf7dd858SToomas Soome /* 2*cf7dd858SToomas Soome * Copyright (c) 2009 David Schultz <das@FreeBSD.org> 3*cf7dd858SToomas Soome * All rights reserved. 4*cf7dd858SToomas Soome * 5*cf7dd858SToomas Soome * Redistribution and use in source and binary forms, with or without 6*cf7dd858SToomas Soome * modification, are permitted provided that the following conditions 7*cf7dd858SToomas Soome * are met: 8*cf7dd858SToomas Soome * 1. Redistributions of source code must retain the above copyright 9*cf7dd858SToomas Soome * notice, this list of conditions and the following disclaimer. 10*cf7dd858SToomas Soome * 2. Redistributions in binary form must reproduce the above copyright 11*cf7dd858SToomas Soome * notice, this list of conditions and the following disclaimer in the 12*cf7dd858SToomas Soome * documentation and/or other materials provided with the distribution. 13*cf7dd858SToomas Soome * 14*cf7dd858SToomas Soome * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15*cf7dd858SToomas Soome * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16*cf7dd858SToomas Soome * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17*cf7dd858SToomas Soome * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18*cf7dd858SToomas Soome * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19*cf7dd858SToomas Soome * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20*cf7dd858SToomas Soome * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21*cf7dd858SToomas Soome * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22*cf7dd858SToomas Soome * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23*cf7dd858SToomas Soome * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24*cf7dd858SToomas Soome * SUCH DAMAGE. 25*cf7dd858SToomas Soome */ 26*cf7dd858SToomas Soome 27*cf7dd858SToomas Soome #include <sys/cdefs.h> 28*cf7dd858SToomas Soome #include <string.h> 29*cf7dd858SToomas Soome 30*cf7dd858SToomas Soome char * 31*cf7dd858SToomas Soome stpncpy(char * __restrict dst, const char * __restrict src, size_t n) 32*cf7dd858SToomas Soome { 33*cf7dd858SToomas Soome 34*cf7dd858SToomas Soome for (; n--; dst++, src++) { 35*cf7dd858SToomas Soome if (!(*dst = *src)) { 36*cf7dd858SToomas Soome char *ret = dst; 37*cf7dd858SToomas Soome while (n--) 38*cf7dd858SToomas Soome *++dst = '\0'; 39*cf7dd858SToomas Soome return (ret); 40*cf7dd858SToomas Soome } 41*cf7dd858SToomas Soome } 42*cf7dd858SToomas Soome return (dst); 43*cf7dd858SToomas Soome } 44