aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEugene Triguba <eugenetriguba@gmail.com>2025-06-29 12:18:01 -0400
committerEugene Triguba <eugenetriguba@gmail.com>2025-06-29 12:18:01 -0400
commit5c21215d06ddb7cc67ddf1f57cabc531830eb4bc (patch)
tree3afe12cd989cd0f1166dec5a7faed6c37ae4e85e
parentPrint error to stderr (diff)
downloadcli-5c21215d06ddb7cc67ddf1f57cabc531830eb4bc.zip
Split strlcat into .c and .h
-rw-r--r--src/strlcat.c27
-rw-r--r--src/strlcat.h28
2 files changed, 29 insertions, 26 deletions
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 <stddef.h>
+#include <string.h>
+
+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));
+}
diff --git a/src/strlcat.h b/src/strlcat.h
index 6317855..0470b83 100644
--- a/src/strlcat.h
+++ b/src/strlcat.h
@@ -2,7 +2,6 @@
#define HAVE_STRLCAT
#include <stddef.h>
-#include <string.h>
/*
* Appends src to string dst of size siz (unlike strncat, siz is the
@@ -11,29 +10,6 @@
* Returns strlen(src) + MIN(siz, strlen(initial dst)).
* If retval >= siz, truncation occurred.
*/
-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;
+size_t strlcat(char *dst, const char *src, size_t dstsize);
- /* 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));
-}
-
-#endif /* HAVE_STRLCAT */
+#endif