aboutsummaryrefslogtreecommitdiffstats
path: root/sdk/other/strcopy.c
diff options
context:
space:
mode:
Diffstat (limited to 'sdk/other/strcopy.c')
-rw-r--r--sdk/other/strcopy.c61
1 files changed, 61 insertions, 0 deletions
diff --git a/sdk/other/strcopy.c b/sdk/other/strcopy.c
new file mode 100644
index 0000000..077f897
--- /dev/null
+++ b/sdk/other/strcopy.c
@@ -0,0 +1,61 @@
+/*
+ * String copying defined for supporting over-lapping strings 'insertion'.
+ * $Id$
+ * Copyright (c) 1997 by Tycho Softworks.
+ * For conditions of distribution and reuse see product license.
+ */
+
+#include <other/string.h>
+
+static char *revcopy(char *to, const char *from, size_t count)
+{
+ while(count--)
+ *(to--) = *(from--);
+
+ *to = *from;
+ return to;
+};
+
+char *strcopy(char *to, const char *from)
+{
+ char *s1 = to;
+ int l = from - to;
+ int l2 = len(from);
+
+ if(!to || !from)
+ return NULL;
+
+ if(l > 0 && l <= l2)
+ return revcopy(to + l2, from + l2, l2);
+
+ ++l2;
+ while(l2--)
+ *(to++) = *(from++);
+
+ return s1;
+};
+
+char *strncopy(char *to, const char *from, int l2)
+{
+ char *s1 = to;
+ int l = from - to;
+ if(len(from) < l2)
+ return strcopy(to, from);
+
+ if(!to || !from)
+ return NULL;
+
+ if(l > 0 && l <= l2)
+ {
+ to[l2] = 0;
+ --l2;
+ return revcopy(to + l2, from + l2, l2);
+ }
+
+ while(l2--)
+ *(to++) = *(from++);
+
+ *to = 0;
+ return s1;
+};
+