blob: 077f8976210ad61e37224f402258c362488738c6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
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;
};
|