about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--stecpy-builtin.c18
1 files changed, 18 insertions, 0 deletions
diff --git a/stecpy-builtin.c b/stecpy-builtin.c
new file mode 100644
index 0000000..72f6adc
--- /dev/null
+++ b/stecpy-builtin.c
@@ -0,0 +1,18 @@
+#include <string.h>
+
+char *
+stecpy(char *dst, char *end, const char *src)
+{
+        if (dst >= end)
+                return dst;
+
+	size_t n = strnlen(src, end - dst);
+
+	if (n == end - dst) {
+		memcpy(dst, src, n - 1);
+		end[-1] = 0;
+		return end;
+	}
+
+	return memcpy(dst, src, n + 1) + n;
+}