Back to index

php5  5.3.10
strlcat.c
Go to the documentation of this file.
00001 /*
00002   +----------------------------------------------------------------------+
00003   | PHP Version 5                                                        |
00004   +----------------------------------------------------------------------+
00005   | Copyright (c) 1997-2012 The PHP Group                                |
00006   +----------------------------------------------------------------------+
00007   | This source file is subject to version 3.01 of the PHP license,      |
00008   | that is bundled with this package in the file LICENSE, and is        |
00009   | available through the world-wide-web at the following url:           |
00010   | http://www.php.net/license/3_01.txt                                  |
00011   | If you did not receive a copy of the PHP license and are unable to   |
00012   | obtain it through the world-wide-web, please send a note to          |
00013   | license@php.net so we can mail you a copy immediately.               |
00014   +----------------------------------------------------------------------+
00015   | Author:                                                              |
00016   +----------------------------------------------------------------------+
00017 */
00018 
00019 /* $Id: strlcat.c 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #include "php.h"
00022 
00023 #ifndef HAVE_STRLCAT
00024 
00025 /*     $OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $    */
00026 
00027 /*
00028  * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com>
00029  * All rights reserved.
00030  *
00031  * Redistribution and use in source and binary forms, with or without
00032  * modification, are permitted provided that the following conditions
00033  * are met:
00034  * 1. Redistributions of source code must retain the above copyright
00035  *    notice, this list of conditions and the following disclaimer.
00036  * 2. Redistributions in binary form must reproduce the above copyright
00037  *    notice, this list of conditions and the following disclaimer in the
00038  *    documentation and/or other materials provided with the distribution.
00039  * 3. The name of the author may not be used to endorse or promote products
00040  *    derived from this software without specific prior written permission.
00041  *
00042  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES,
00043  * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY
00044  * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL
00045  * THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
00046  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
00047  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
00048  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
00049  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
00050  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
00051  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00052  */
00053 
00054 #if defined(LIBC_SCCS) && !defined(lint)
00055 static char *rcsid = "$OpenBSD: strlcat.c,v 1.2 1999/06/17 16:28:58 millert Exp $";
00056 #endif /* LIBC_SCCS and not lint */
00057 
00058 #include <sys/types.h>
00059 #include <string.h>
00060 
00061 /*
00062  * Appends src to string dst of size siz (unlike strncat, siz is the
00063  * full size of dst, not space left).  At most siz-1 characters
00064  * will be copied.  Always NUL terminates (unless siz == 0).
00065  * Returns strlen(src); if retval >= siz, truncation occurred.
00066  */
00067 PHPAPI size_t php_strlcat(dst, src, siz)
00068        char *dst;
00069        const char *src;
00070        size_t siz;
00071 {
00072        register char *d = dst;
00073        register const char *s = src;
00074        register size_t n = siz;
00075        size_t dlen;
00076 
00077        /* Find the end of dst and adjust bytes left but don't go past end */
00078        while (*d != '\0' && n-- != 0)
00079               d++;
00080        dlen = d - dst;
00081        n = siz - dlen;
00082 
00083        if (n == 0)
00084               return(dlen + strlen(s));
00085        while (*s != '\0') {
00086               if (n != 1) {
00087                      *d++ = *s;
00088                      n--;
00089               }
00090               s++;
00091        }
00092        *d = '\0';
00093 
00094        return(dlen + (s - src));   /* count does not include NUL */
00095 }
00096 
00097 #endif /* !HAVE_STRLCAT */
00098 
00099 /*
00100  * Local variables:
00101  * tab-width: 4
00102  * c-basic-offset: 4
00103  * End:
00104  * vim600: sw=4 ts=4 fdm=marker
00105  * vim<600: sw=4 ts=4
00106  */