about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--stecpy-memccpy.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/stecpy-memccpy.c b/stecpy-memccpy.c
new file mode 100644
index 0000000..e4ce259
--- /dev/null
+++ b/stecpy-memccpy.c
@@ -0,0 +1,16 @@
+#include <string.h>
+
+char *
+stecpy(char *dst, char *end, const char *src)
+{
+        if (dst >= end)
+                return dst;
+
+	dst = memccpy(dst, src, '\0', end - dst);
+	if (!dst) {
+		end[-1] = 0;
+		return end;
+	}
+
+	return dst - 1;
+}