summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/wcslcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/wcslcat.c')
-rw-r--r--src/lib/libc/string/wcslcat.c47
1 files changed, 23 insertions, 24 deletions
diff --git a/src/lib/libc/string/wcslcat.c b/src/lib/libc/string/wcslcat.c
index ee8ff3c343..2dfe2aae31 100644
--- a/src/lib/libc/string/wcslcat.c
+++ b/src/lib/libc/string/wcslcat.c
@@ -1,8 +1,7 @@
1/* $OpenBSD: wcslcat.c,v 1.4 2011/07/24 15:21:28 millert Exp $ */ 1/* $OpenBSD: wcslcat.c,v 1.5 2015/01/15 03:54:12 millert Exp $ */
2/* $NetBSD: wcslcat.c,v 1.2 2001/01/03 14:33:02 lukem Exp $ */
3 2
4/* 3/*
5 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
6 * 5 *
7 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above 7 * purpose with or without fee is hereby granted, provided that the above
@@ -21,36 +20,36 @@
21#include <wchar.h> 20#include <wchar.h>
22 21
23/* 22/*
24 * Appends src to string dst of size siz (unlike wcsncat, siz is the 23 * Appends src to string dst of size dsize (unlike strncat, dsize is the
25 * full size of dst, not space left). At most siz-1 characters 24 * full size of dst, not space left). At most dsize-1 characters
26 * will be copied. Always NUL terminates (unless siz <= wcslen(dst)). 25 * will be copied. Always NUL terminates (unless dsize <= wcslen(dst)).
27 * Returns wcslen(src) + MIN(siz, wcslen(initial dst)). 26 * Returns wcslen(src) + MIN(dsize, wcslen(initial dst)).
28 * If retval >= siz, truncation occurred. 27 * If retval >= siz, truncation occurred.
29 */ 28 */
30size_t 29size_t
31wcslcat(wchar_t *dst, const wchar_t *src, size_t siz) 30wcslcat(wchar_t *dst, const wchar_t *src, size_t dsize)
32{ 31{
33 wchar_t *d = dst; 32 const wchar_t *odst = dst;
34 const wchar_t *s = src; 33 const wchar_t *osrc = src;
35 size_t n = siz; 34 size_t n = dsize;
36 size_t dlen; 35 size_t dlen;
37 36
38 /* Find the end of dst and adjust bytes left but don't go past end */ 37 /* Find the end of dst and adjust bytes left but don't go past end. */
39 while (n-- != 0 && *d != '\0') 38 while (n-- != 0 && *dst != L'\0')
40 d++; 39 dst++;
41 dlen = d - dst; 40 dlen = dst - odst;
42 n = siz - dlen; 41 n = dsize - dlen;
43 42
44 if (n == 0) 43 if (n-- == 0)
45 return(dlen + wcslen(s)); 44 return(dlen + wcslen(src));
46 while (*s != '\0') { 45 while (*src != L'\0') {
47 if (n != 1) { 46 if (n != 0) {
48 *d++ = *s; 47 *dst++ = *src;
49 n--; 48 n--;
50 } 49 }
51 s++; 50 src++;
52 } 51 }
53 *d = '\0'; 52 *dst = L'\0';
54 53
55 return(dlen + (s - src)); /* count does not include NUL */ 54 return(dlen + (src - osrc)); /* count does not include NUL */
56} 55}