aboutsummaryrefslogtreecommitdiff
path: root/stecpe.c
diff options
context:
space:
mode:
authorLeah Neukirchen <leah@vuxu.org>2021-11-05 18:52:11 +0100
committerLeah Neukirchen <leah@vuxu.org>2021-11-05 18:52:46 +0100
commit75ea20675d012e692996bc6beae9149b0deb08b0 (patch)
treeab1569403e1c5f8e76f5f93f969a3335275c54a5 /stecpe.c
downloadlibste-75ea20675d012e692996bc6beae9149b0deb08b0.tar.gz
libste-75ea20675d012e692996bc6beae9149b0deb08b0.tar.xz
libste-75ea20675d012e692996bc6beae9149b0deb08b0.zip
initial commit
Diffstat (limited to 'stecpe.c')
-rw-r--r--stecpe.c21
1 files changed, 21 insertions, 0 deletions
diff --git a/stecpe.c b/stecpe.c
new file mode 100644
index 0000000..0cfbaad
--- /dev/null
+++ b/stecpe.c
@@ -0,0 +1,21 @@
+#include <stddef.h>
+#include <string.h>
+
+char *
+stecpe(char *dst, const char *end, const char *src, const char *srcend)
+{
+ if (dst >= end)
+ return dst;
+
+ size_t l = end - dst - 1;
+ size_t t = 1;
+ if (srcend - src < l) {
+ l = srcend - src;
+ t = 0;
+ }
+
+ memcpy(dst, src, l);
+ dst[l] = 0;
+
+ return dst + l + t;
+}