about summary refs log tree commit diff
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-11-06 19:12:19 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-11-06 19:12:19 +0100
commitd2b694a313ecb8fb8a4c510c2f229b07543fe8a9 (patch)
tree460547073fa0730feb2aa9a0d8b5d01e98e91992
parent8ba5282b9982e1d49199f816a1ec4148a232d8df (diff)
downloadlibste-d2b694a313ecb8fb8a4c510c2f229b07543fe8a9.tar.gz
libste-d2b694a313ecb8fb8a4c510c2f229b07543fe8a9.tar.xz
libste-d2b694a313ecb8fb8a4c510c2f229b07543fe8a9.zip
add stecpy alternative implementation using memccpy
-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;
+}