diff options
Diffstat (limited to 'main/strlcat.c')
| -rw-r--r-- | main/strlcat.c | 39 |
1 files changed, 20 insertions, 19 deletions
diff --git a/main/strlcat.c b/main/strlcat.c index d3cfd17040..88cef70c56 100644 --- a/main/strlcat.c +++ b/main/strlcat.c @@ -20,9 +20,9 @@ #include "php.h" -#ifndef HAVE_STRLCAT +#ifdef USE_STRLCAT_PHP_IMPL -/* $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $ */ +/* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */ /* * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> @@ -52,7 +52,7 @@ */ #if defined(LIBC_SCCS) && !defined(lint) -static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $"; +static char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $"; #endif /* LIBC_SCCS and not lint */ #include <sys/types.h> @@ -61,37 +61,38 @@ static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp /* * Appends src to string dst of size siz (unlike strncat, siz is the * full size of dst, not space left). At most siz-1 characters - * will be copied. Always NUL terminates (unless siz == 0). - * Returns strlen(src); if retval >= siz, truncation occurred. + * will be copied. Always NUL terminates (unless siz <= strlen(dst)). + * Returns strlen(src) + MIN(siz, strlen(initial dst). + * If retval >= siz, truncation occurred. */ PHPAPI size_t php_strlcat(dst, src, siz) char *dst; const char *src; size_t siz; { - register char *d = dst; - register const char *s = src; - register size_t n = siz; + const 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 (*d != '\0' && n-- != 0) - d++; - dlen = d - dst; + while (n-- != 0 && *dst != '\0') + dst++; + dlen = dst - d; n = siz - dlen; - if (n == 0) - return(dlen + strlen(s)); - while (*s != '\0') { - if (n != 1) { - *d++ = *s; + if (n-- == 0) + return(dlen + strlen(src)); + while (*src != '\0') { + if (n != 0) { + *dst++ = *src; n--; } - s++; + src++; } - *d = '\0'; + *dst = '\0'; - return(dlen + (s - src)); /* count does not include NUL */ + return(dlen + (src - s)); } #endif /* !HAVE_STRLCAT */ |
