diff options
author | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
---|---|---|
committer | William Harrington <kb0iic@berzerkula.org> | 2025-01-14 16:06:02 -0600 |
commit | 0cc9b20c15460213e488bf5e70963b941482f628 (patch) | |
tree | bb0143245583ec846630f39bfa2258dba640ccd7 /sdk/other/strcopy.c | |
parent | 0e084ade5069756d487b5c948c48b777e37c00c9 (diff) |
Add source.
Diffstat (limited to 'sdk/other/strcopy.c')
-rw-r--r-- | sdk/other/strcopy.c | 61 |
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; +}; + |