aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/src/string.c
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/string.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/string.c b/src/string.c
new file mode 100644
index 0000000..878efeb
--- /dev/null
+++ b/src/string.c
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2023 Egor Tensin <Egor.Tensin@gmail.com>
+ * This file is part of the "cimple" project.
+ * For details, see https://github.com/egor-tensin/cimple.
+ * Distributed under the MIT License.
+ */
+
+#include "string.h"
+
+#include <string.h>
+
+char *stpecpy(char *dst, char *end, const char *src)
+{
+ if (!dst)
+ return NULL;
+ if (dst == end)
+ return end;
+
+ char *p = memccpy(dst, src, '\0', end - dst);
+ if (p)
+ return p - 1;
+
+ end[-1] = '\0';
+ return end;
+}