aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Stenberg <daniel@haxx.se>2001-02-06 09:08:24 +0000
committerDaniel Stenberg <daniel@haxx.se>2001-02-06 09:08:24 +0000
commit833ce37cb95646bfc02dbf1a87ac3fd5d3937de5 (patch)
treef82380999e53ae7f285daa58d6214774e72f2baa
parent07e7018564be6acdeb3a7e65fec6ebe190f3c1e9 (diff)
new openbsd inspired implementation of strlcat()
-rw-r--r--lib/strequal.c31
1 files changed, 23 insertions, 8 deletions
diff --git a/lib/strequal.c b/lib/strequal.c
index 97d1f9199..42aea7cd0 100644
--- a/lib/strequal.c
+++ b/lib/strequal.c
@@ -77,18 +77,33 @@ int Curl_strnequal(const char *first, const char *second, size_t max)
* For strlcat() that means the initial length of dst plus the length of
* src. While this may seem somewhat confusing it was done to make trunca-
* tion detection simple.
+ *
+ *
*/
size_t strlcat(char *dst, const char *src, size_t size)
{
- size_t len = strlen(dst);
- size_t orglen = len;
- int index=0;
-
- while(src[index] && (len < (size-1)) ) {
- dst[len++] = src[index++];
+ char *d = dst;
+ const char *s = src;
+ size_t n = siz;
+ size_t dlen;
+
+ /* Find the end of dst and adjust bytes left but don't go past end */
+ while (n-- != 0 && *d != '\0')
+ d++;
+ dlen = d - dst;
+ n = siz - dlen;
+
+ if (n == 0)
+ return(dlen + strlen(s));
+ while (*s != '\0') {
+ if (n != 1) {
+ *d++ = *s;
+ n--;
+ }
+ s++;
}
- dst[len]=0;
+ *d = '\0';
- return orglen + strlen(src);
+ return(dlen + (s - src)); /* count does not include NUL */
}
#endif