nfs-ganesha 1.4
|
00001 /* 00002 * Copyright (c) 1998 Todd C. Miller <Todd.Miller@courtesan.com> 00003 * 00004 * Permission to use, copy, modify, and distribute this software for any 00005 * purpose with or without fee is hereby granted, provided that the above 00006 * copyright notice and this permission notice appear in all copies. 00007 * 00008 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 00009 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 00010 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 00011 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 00012 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 00013 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 00014 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 00015 */ 00016 00017 #ifndef HAVE_STRLCAT 00018 00019 #include <sys/types.h> 00020 #include <string.h> 00021 00022 /* 00023 * Appends src to string dst of size siz (unlike strncat, siz is the 00024 * full size of dst, not space left). At most siz-1 characters 00025 * will be copied. Always NUL terminates (unless siz <= strlen(dst)). 00026 * Returns strlen(src) + MIN(siz, strlen(initial dst)). 00027 * If retval >= siz, truncation occurred. 00028 */ 00029 size_t 00030 strlcat(char *dst, const char *src, size_t siz) 00031 { 00032 register char *d = dst; 00033 register const char *s = src; 00034 register size_t n = siz; 00035 size_t dlen; 00036 00037 /* Find the end of dst and adjust bytes left but don't go past end */ 00038 while (n-- != 0 && *d != '\0') 00039 d++; 00040 dlen = d - dst; 00041 n = siz - dlen; 00042 00043 if (n == 0) 00044 return (dlen + strlen(s)); 00045 while (*s != '\0') { 00046 if (n != 1) { 00047 *d++ = *s; 00048 n--; 00049 } 00050 s++; 00051 } 00052 *d = '\0'; 00053 00054 return (dlen + (s - src)); /* count does not include NUL */ 00055 } 00056 #endif