summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/strlcat.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/strlcat.c')
-rw-r--r--src/lib/libc/string/strlcat.c46
1 files changed, 23 insertions, 23 deletions
diff --git a/src/lib/libc/string/strlcat.c b/src/lib/libc/string/strlcat.c
index ceab094411..2c7404a535 100644
--- a/src/lib/libc/string/strlcat.c
+++ b/src/lib/libc/string/strlcat.c
@@ -1,7 +1,7 @@
1/* $OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $ */ 1/* $OpenBSD: strlcat.c,v 1.14 2015/01/15 03:54:12 millert Exp $ */
2 2
3/* 3/*
4 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 4 * Copyright (c) 1998, 2015 Todd C. Miller <Todd.Miller@courtesan.com>
5 * 5 *
6 * Permission to use, copy, modify, and distribute this software for any 6 * Permission to use, copy, modify, and distribute this software for any
7 * 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
@@ -20,36 +20,36 @@
20#include <string.h> 20#include <string.h>
21 21
22/* 22/*
23 * Appends src to string dst of size siz (unlike strncat, siz is the 23 * Appends src to string dst of size dsize (unlike strncat, dsize is the
24 * 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
25 * will be copied. Always NUL terminates (unless siz <= strlen(dst)). 25 * will be copied. Always NUL terminates (unless dsize <= strlen(dst)).
26 * Returns strlen(src) + MIN(siz, strlen(initial dst)). 26 * Returns strlen(src) + MIN(dsize, strlen(initial dst)).
27 * If retval >= siz, truncation occurred. 27 * If retval >= siz, truncation occurred.
28 */ 28 */
29size_t 29size_t
30strlcat(char *dst, const char *src, size_t siz) 30strlcat(char *dst, const char *src, size_t dsize)
31{ 31{
32 char *d = dst; 32 const char *odst = dst;
33 const char *s = src; 33 const char *osrc = src;
34 size_t n = siz; 34 size_t n = dsize;
35 size_t dlen; 35 size_t dlen;
36 36
37 /* 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. */
38 while (n-- != 0 && *d != '\0') 38 while (n-- != 0 && *dst != '\0')
39 d++; 39 dst++;
40 dlen = d - dst; 40 dlen = dst - odst;
41 n = siz - dlen; 41 n = dsize - dlen;
42 42
43 if (n == 0) 43 if (n-- == 0)
44 return(dlen + strlen(s)); 44 return(dlen + strlen(src));
45 while (*s != '\0') { 45 while (*src != '\0') {
46 if (n != 1) { 46 if (n != 0) {
47 *d++ = *s; 47 *dst++ = *src;
48 n--; 48 n--;
49 } 49 }
50 s++; 50 src++;
51 } 51 }
52 *d = '\0'; 52 *dst = '\0';
53 53
54 return(dlen + (s - src)); /* count does not include NUL */ 54 return(dlen + (src - osrc)); /* count does not include NUL */
55} 55}