2003-02-19 16:40:19 +08:00
|
|
|
/*
|
|
|
|
+----------------------------------------------------------------------+
|
2019-01-30 17:03:12 +08:00
|
|
|
| Copyright (c) The PHP Group |
|
2003-02-19 16:40:19 +08:00
|
|
|
+----------------------------------------------------------------------+
|
2006-01-01 20:51:34 +08:00
|
|
|
| This source file is subject to version 3.01 of the PHP license, |
|
2003-02-19 16:40:19 +08:00
|
|
|
| that is bundled with this package in the file LICENSE, and is |
|
2003-06-11 04:04:29 +08:00
|
|
|
| available through the world-wide-web at the following url: |
|
2006-01-01 20:51:34 +08:00
|
|
|
| http://www.php.net/license/3_01.txt |
|
2003-02-19 16:40:19 +08:00
|
|
|
| If you did not receive a copy of the PHP license and are unable to |
|
|
|
|
| obtain it through the world-wide-web, please send a note to |
|
|
|
|
| license@php.net so we can mail you a copy immediately. |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
| Author: |
|
|
|
|
+----------------------------------------------------------------------+
|
|
|
|
*/
|
|
|
|
|
1999-11-27 08:48:50 +08:00
|
|
|
#include "php.h"
|
1999-11-26 21:33:41 +08:00
|
|
|
|
2017-03-20 06:19:31 +08:00
|
|
|
#ifdef USE_STRLCAT_PHP_IMPL
|
1999-09-15 03:12:57 +08:00
|
|
|
|
2017-08-24 13:58:15 +08:00
|
|
|
/* $OpenBSD: strlcat.c,v 1.18 2016/10/16 17:37:39 dtucker Exp $ */
|
1999-09-15 03:12:57 +08:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
|
|
|
|
* All rights reserved.
|
|
|
|
*
|
|
|
|
* Redistribution and use in source and binary forms, with or without
|
|
|
|
* modification, are permitted provided that the following conditions
|
|
|
|
* are met:
|
|
|
|
* 1. Redistributions of source code must retain the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer.
|
|
|
|
* 2. Redistributions in binary form must reproduce the above copyright
|
|
|
|
* notice, this list of conditions and the following disclaimer in the
|
|
|
|
* documentation and/or other materials provided with the distribution.
|
|
|
|
* 3. The name of the author may not be used to endorse or promote products
|
|
|
|
* derived from this software without specific prior written permission.
|
|
|
|
*
|
|
|
|
* THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
|
|
|
|
* INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
|
|
|
|
* AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
|
|
|
|
* THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
|
|
|
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
|
|
|
|
* PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
|
|
|
|
* OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
|
|
|
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
|
|
|
|
* OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
|
|
|
|
* ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2020-09-08 02:35:48 +08:00
|
|
|
static const char *rcsid = "$OpenBSD: strlcat.c,v 1.17 2016/10/14 18:19:04 dtucker Exp $";
|
1999-09-15 03:12:57 +08:00
|
|
|
#endif /* LIBC_SCCS and not lint */
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
/*
|
|
|
|
* 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
|
2017-08-24 13:58:15 +08:00
|
|
|
* will be copied. Always NUL terminates (unless siz <= strlen(dst)).
|
2017-12-31 12:35:25 +08:00
|
|
|
* Returns strlen(src) + MIN(siz, strlen(initial dst).
|
2017-08-24 13:58:15 +08:00
|
|
|
* If retval >= siz, truncation occurred.
|
1999-09-15 03:12:57 +08:00
|
|
|
*/
|
2001-05-30 13:00:39 +08:00
|
|
|
PHPAPI size_t php_strlcat(dst, src, siz)
|
1999-09-15 03:12:57 +08:00
|
|
|
char *dst;
|
|
|
|
const char *src;
|
|
|
|
size_t siz;
|
|
|
|
{
|
2016-10-15 21:53:38 +08:00
|
|
|
const char *d = dst;
|
|
|
|
const char *s = src;
|
|
|
|
size_t n = siz;
|
1999-09-15 03:12:57 +08:00
|
|
|
size_t dlen;
|
|
|
|
|
|
|
|
/* Find the end of dst and adjust bytes left but don't go past end */
|
2016-10-15 21:53:38 +08:00
|
|
|
while (n-- != 0 && *dst != '\0')
|
|
|
|
dst++;
|
2017-08-24 13:58:15 +08:00
|
|
|
dlen = dst - d;
|
1999-09-15 03:12:57 +08:00
|
|
|
n = siz - dlen;
|
|
|
|
|
2016-10-15 21:53:38 +08:00
|
|
|
if (n-- == 0)
|
|
|
|
return(dlen + strlen(src));
|
|
|
|
while (*src != '\0') {
|
|
|
|
if (n != 0) {
|
|
|
|
*dst++ = *src;
|
1999-09-15 03:12:57 +08:00
|
|
|
n--;
|
|
|
|
}
|
2016-10-15 21:53:38 +08:00
|
|
|
src++;
|
1999-09-15 03:12:57 +08:00
|
|
|
}
|
2016-10-15 21:53:38 +08:00
|
|
|
*dst = '\0';
|
1999-09-15 03:12:57 +08:00
|
|
|
|
2017-08-24 13:58:15 +08:00
|
|
|
return(dlen + (src - s));
|
1999-09-15 03:12:57 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif /* !HAVE_STRLCAT */
|