1189136Sdas/*- 2189136Sdas * Copyright (c) 2009 David Schultz <das@FreeBSD.org> 3189136Sdas * All rights reserved. 4189136Sdas * 5189136Sdas * Redistribution and use in source and binary forms, with or without 6189136Sdas * modification, are permitted provided that the following conditions 7189136Sdas * are met: 8189136Sdas * 1. Redistributions of source code must retain the above copyright 9189136Sdas * notice, this list of conditions and the following disclaimer. 10189136Sdas * 2. Redistributions in binary form must reproduce the above copyright 11189136Sdas * notice, this list of conditions and the following disclaimer in the 12189136Sdas * documentation and/or other materials provided with the distribution. 13189136Sdas * 14189136Sdas * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 15189136Sdas * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16189136Sdas * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17189136Sdas * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18189136Sdas * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19189136Sdas * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20189136Sdas * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21189136Sdas * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22189136Sdas * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23189136Sdas * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24189136Sdas * SUCH DAMAGE. 25189136Sdas */ 26189136Sdas 27189136Sdas#include <sys/cdefs.h> 28189136Sdas__FBSDID("$FreeBSD$"); 29189136Sdas 30189361Sdas#include <wchar.h> 31189136Sdas 32189361Sdaswchar_t * 33189361Sdaswcpncpy(wchar_t * __restrict dst, const wchar_t * __restrict src, size_t n) 34189136Sdas{ 35189136Sdas 36189136Sdas for (; n--; dst++, src++) { 37189136Sdas if (!(*dst = *src)) { 38189361Sdas wchar_t *ret = dst; 39189136Sdas while (n--) 40189361Sdas *++dst = L'\0'; 41189136Sdas return (ret); 42189136Sdas } 43189136Sdas } 44189136Sdas return (dst); 45189136Sdas} 46