From 5c21215d06ddb7cc67ddf1f57cabc531830eb4bc Mon Sep 17 00:00:00 2001 From: Eugene Triguba Date: Sun, 29 Jun 2025 12:18:01 -0400 Subject: Split strlcat into .c and .h --- src/strlcat.c | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 src/strlcat.c (limited to 'src/strlcat.c') diff --git a/src/strlcat.c b/src/strlcat.c new file mode 100644 index 0000000..5c317c6 --- /dev/null +++ b/src/strlcat.c @@ -0,0 +1,27 @@ +#include +#include + +size_t strlcat(char *dst, const char *src, size_t dstsize) { + char *d = dst; + const char *s = src; + size_t n = dstsize; + size_t dlen; + + /* Find the end of dst and adjust bytes left but don't go past end */ + while (n-- != 0 && *d != '\0') + d++; + dlen = d - dst; + n = dstsize - dlen; + + if (n == 0) return (dlen + strlen(s)); + while (*s != '\0') { + if (n != 1) { + *d++ = *s; + n--; + } + s++; + } + *d = '\0'; + + return (dlen + (s - src)); +} -- cgit v1.2.3