about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-11-06 20:21:16 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-11-06 20:21:16 +0100
commitaaa744cbf633b70e183796e69008cae1923dab00 (patch)
tree0bb5993499f63fdd03113f85bd0f1e917235d2ba
parent87d450cde403cd8fa3e0594915933e0e444e6c9c (diff)
downloadlibste-aaa744cbf633b70e183796e69008cae1923dab00.tar.gz
libste-aaa744cbf633b70e183796e69008cae1923dab00.tar.xz
libste-aaa744cbf633b70e183796e69008cae1923dab00.zip
add stecpy alternative implementation using gcc builtins
-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;
+}