Mercurial > dropbear
comparison compat.c @ 1322:826a3293fe5a
upgrade strlcat
in order to remove K&R code
author | Francois Perrad <francois.perrad@gadz.org> |
---|---|
date | Fri, 25 Mar 2016 07:57:19 +0100 |
parents | a0062a354a80 |
children | 271c57aa3da5 |
comparison
equal
deleted
inserted
replaced
1321:2535ea9d0a6f | 1322:826a3293fe5a |
---|---|
112 | 112 |
113 } | 113 } |
114 #endif /* HAVE_STRLCPY */ | 114 #endif /* HAVE_STRLCPY */ |
115 | 115 |
116 #ifndef HAVE_STRLCAT | 116 #ifndef HAVE_STRLCAT |
117 /* taken from openbsd-compat for OpenSSH 3.6.1p1 */ | 117 /* taken from openbsd-compat for OpenSSH 7.2p2 */ |
118 /* "$OpenBSD: strlcat.c,v 1.8 2001/05/13 15:40:15 deraadt Exp $" | 118 /* "$OpenBSD: strlcat.c,v 1.13 2005/08/08 08:05:37 espie Exp $" |
119 * | 119 * |
120 * Appends src to string dst of size siz (unlike strncat, siz is the | 120 * Appends src to string dst of size siz (unlike strncat, siz is the |
121 * full size of dst, not space left). At most siz-1 characters | 121 * full size of dst, not space left). At most siz-1 characters |
122 * will be copied. Always NUL terminates (unless siz <= strlen(dst)). | 122 * will be copied. Always NUL terminates (unless siz <= strlen(dst)). |
123 * Returns strlen(src) + MIN(siz, strlen(initial dst)). | 123 * Returns strlen(src) + MIN(siz, strlen(initial dst)). |
124 * If retval >= siz, truncation occurred. | 124 * If retval >= siz, truncation occurred. |
125 */ | 125 */ |
126 size_t | 126 size_t |
127 strlcat(dst, src, siz) | 127 strlcat(char *dst, const char *src, size_t siz) |
128 char *dst; | |
129 const char *src; | |
130 size_t siz; | |
131 { | 128 { |
132 register char *d = dst; | 129 char *d = dst; |
133 register const char *s = src; | 130 const char *s = src; |
134 register size_t n = siz; | 131 size_t n = siz; |
135 size_t dlen; | 132 size_t dlen; |
136 | 133 |
137 /* Find the end of dst and adjust bytes left but don't go past end */ | 134 /* Find the end of dst and adjust bytes left but don't go past end */ |
138 while (n-- != 0 && *d != '\0') | 135 while (n-- != 0 && *d != '\0') |
139 d++; | 136 d++; |