/* * strlcat() - Concatenate as much data as we can onto a * fixed-sized string, ensuring the result is NUL-terminated. * Return the total number of bytes required to concatenate * all of the src string onto dst. * * Dan Cross */ #include #include size_t strlcat(char *dst, const char *src, size_t size) { char *p; size_t len; /* * This mimics the OpenBSD semantics most closely. * * We would like to use strlen() here, but the idea is to * catch cases where dst isn't a C-style string, and this * function is (presumably) called in error. */ p = memchr(dst, '\0', size); if (p == NULL) p = dst + size; len = p - dst; return(len + strlcpy(p, src, size - len)); }