1 /* 2 * This file and its contents are supplied under the terms of the 3 * Common Development and Distribution License ("CDDL"), version 1.0. 4 * You may only use this file in accordance with the terms of version 5 * 1.0 of the CDDL. 6 * 7 * A full copy of the text of the CDDL should have accompanied this 8 * source. A copy of the CDDL is also available via the Internet at 9 * http://www.illumos.org/license/CDDL. 10 */ 11 12 /* 13 * Copyright 2024 Oxide Computer Company 14 */ 15 16 /* 17 * Wide character variant of strlcpy(3C). We must copy at most dstlen wide 18 * characters (not bytes!) from src to dst or less if src is less than dstlen. 19 * Like with strlcpy, this must return the total number of characters that are 20 * in src and it must guarantee that dst is properly terminated with the null 21 * wide-character. 22 */ 23 24 #include "lint.h" 25 #include <wchar.h> 26 #include <sys/sysmacros.h> 27 28 size_t 29 wcslcpy(wchar_t *restrict dst, const wchar_t *restrict src, size_t dstlen) 30 { 31 size_t srclen = wcslen(src); 32 size_t nwcs; 33 34 if (dstlen == 0) { 35 return (srclen); 36 } 37 38 nwcs = MIN(srclen, dstlen - 1); 39 (void) wmemcpy(dst, src, nwcs); 40 dst[nwcs] = L'\0'; 41 return (srclen); 42 } 43