1 void *memmove(void *s1, const void *s2, register size_t n)
2 {
3 register char *p1 = s1;
4 register const char *p2 = s2;
5
6 if (n>0) {
7 if (p2 <= p1 && p2 + n > p1) {
8 /* overlap, copy backwards */
9 p1 += n;
10 p2 += n;
11 n++;
12 while (--n > 0) {
13 *--p1 = *--p2;
14 }
15 } else {
16 n++;
17 while (--n > 0) {
18 *p1++ = *p2++;
19 }
20 }
21 }
22 return s1;
23 }
24
25 void *memcpy(void *s1, const void *s2, register size_t n)
26 {
27 register char *p1 = s1;
28 register const char *p2 = s2;
29
30
31 if (n) {
32 n++;
33 while (--n > 0) {
34 *p1++ = *p2++;
35 }
36 }
37 return s1;
38 }
posted on 2008-10-15 10:31
黑色天使 阅读(2694)
评论(5) 编辑 收藏 引用 所属分类:
C\C++