* 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 <= strlen(dst)). * Returns strlen(src) + MIN(siz, strlen(initial dst)). * If retval >= siz, truncation occurred. */
(dst, src, siz)
| 38 | * If retval >= siz, truncation occurred. |
| 39 | */ |
| 40 | size_t |
| 41 | strlcat(dst, src, siz) |
| 42 | char *dst; |
| 43 | const char *src; |
| 44 | size_t siz; |
| 45 | { |
| 46 | char *d = dst; |
| 47 | const char *s = src; |
| 48 | size_t n = siz; |
| 49 | size_t dlen; |
| 50 | |
| 51 | /* Find the end of dst and adjust bytes left but don't go past end */ |
| 52 | while (n-- != 0 && *d != '\0') |
| 53 | d++; |
| 54 | dlen = d - dst; |
| 55 | n = siz - dlen; |
| 56 | |
| 57 | if (n == 0) |
| 58 | return(dlen + strlen(s)); |
| 59 | while (*s != '\0') { |
| 60 | if (n != 1) { |
| 61 | *d++ = *s; |
| 62 | n--; |
| 63 | } |
| 64 | s++; |
| 65 | } |
| 66 | *d = '\0'; |
| 67 | |
| 68 | return(dlen + (s - src)); /* count does not include NUL */ |
| 69 | } |
no outgoing calls