3 <<wcslcat>>---concatenate wide-character strings to specified length
7 size_t wcslcat(wchar_t *<[dst]>, const wchar_t *<[src]>, size_t <[siz]>);
10 The <<wcslcat>> function appends wide characters from <[src]> to
11 end of the <[dst]> wide-character string so that the resultant
12 wide-character string is not more than <[siz]> wide characters
13 including the terminating null wide-character code. A terminating
14 null wide character is always added unless <[siz]> is 0. Thus,
15 the maximum number of wide characters that can be appended from
16 <[src]> is <[siz]> - 1. If copying takes place between objects
17 that overlap, the behaviour is undefined.
20 Wide-character string length of initial <[dst]> plus the
21 wide-character string length of <[src]> (does not include
22 terminating null wide-characters). If the return value is
23 greater than or equal to <[siz]>, then truncation occurred and
24 not all wide characters from <[src]> were appended.
27 No supporting OS subroutines are required.
30 /* $OpenBSD: wcslcat.c,v 1.7 2019/01/25 00:19:25 millert Exp $ */
33 * Copyright (c) 1998, 2015 Todd C. Miller <millert@openbsd.org>
35 * Permission to use, copy, modify, and distribute this software for any
36 * purpose with or without fee is hereby granted, provided that the above
37 * copyright notice and this permission notice appear in all copies.
39 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
40 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
41 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
42 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
43 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
44 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
45 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
48 #include <sys/types.h>
52 * Appends src to string dst of size dsize (unlike strncat, dsize is the
53 * full size of dst, not space left). At most dsize-1 characters
54 * will be copied. Always NUL terminates (unless dsize <= wcslen(dst)).
55 * Returns wcslen(src) + MIN(dsize, wcslen(initial dst)).
56 * If retval >= siz, truncation occurred.
59 wcslcat (wchar_t *dst
,
63 const wchar_t *odst
= dst
;
64 const wchar_t *osrc
= src
;
68 /* Find the end of dst and adjust bytes left but don't go past end. */
69 while (n
-- != 0 && *dst
!= L
'\0')
75 return(dlen
+ wcslen(src
));
76 while (*src
!= L
'\0') {
85 return(dlen
+ (src
- osrc
)); /* count does not include NUL */