From 0cc9b20c15460213e488bf5e70963b941482f628 Mon Sep 17 00:00:00 2001 From: William Harrington Date: Tue, 14 Jan 2025 16:06:02 -0600 Subject: Add source. --- sdk/other/strcopy.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100644 sdk/other/strcopy.c (limited to 'sdk/other/strcopy.c') 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 + +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; +}; + -- cgit v1.2.3-54-g00ecf