3 <<wcslcpy>>---copy a wide-character string to specified length
7 size_t wcslcpy(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
11 size_t wcslcpy(<[dst]>, <[src]>, <[siz]>)
13 const wchar_t *<[src]>;
17 <<wcslcpy>> copies wide-characters from <[src]> to <[dst]>
18 such that up to <[siz]> - 1 characters are copied. A
19 terminating null is appended to the result, unless <[siz]>
23 <<wcslcpy>> returns the number of wide-characters in <[src]>,
24 not including the terminating null wide-character. If the
25 return value is greater than or equal to <[siz]>, then
26 not all wide-characters were copied from <[src]> and truncation
30 No supporting OS subroutines are required.
33 /* $NetBSD: wcslcpy.c,v 1.1 2000/12/23 23:14:36 itojun Exp $ */
34 /* from OpenBSD: strlcpy.c,v 1.4 1999/05/01 18:56:41 millert Exp */
37 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
38 * All rights reserved.
40 * Redistribution and use in source and binary forms, with or without
41 * modification, are permitted provided that the following conditions
43 * 1. Redistributions of source code must retain the above copyright
44 * notice, this list of conditions and the following disclaimer.
45 * 2. Redistributions in binary form must reproduce the above copyright
46 * notice, this list of conditions and the following disclaimer in the
47 * documentation and/or other materials provided with the distribution.
48 * 3. The name of the author may not be used to endorse or promote products
49 * derived from this software without specific prior written permission.
51 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
52 * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
53 * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
54 * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
55 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
56 * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
57 * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
58 * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
59 * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
60 * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
67 * Copy src to string dst of size siz. At most siz-1 characters
68 * will be copied. Always NUL terminates (unless siz == 0).
69 * Returns wcslen(src); if retval >= siz, truncation occurred.
72 _DEFUN (wcslcpy
, (dst
, src
, siz
),
74 _CONST
wchar_t * src _AND
78 _CONST
wchar_t *s
= src
;
81 /* Copy as many bytes as will fit */
82 if (n
!= 0 && --n
!= 0)
86 if ((*d
++ = *s
++) == 0)
92 /* Not enough room in dst, add NUL and traverse rest of src */
96 *d
= '\0'; /* NUL-terminate dst */
101 return (s
- src
- 1); /* count does not include NUL */