]> pd.if.org Git - pdclib/blob - functions/string/memmove.c
Added #ifdef to allow regression against system lib.
[pdclib] / functions / string / memmove.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* memmove( void *, const void *, size_t )
6
7    This file is part of the Public Domain C Library (PDCLib).
8    Permission is granted to use, modify, and / or redistribute at will.
9 */
10
11 #include <string.h>
12
13 #ifndef REGTEST
14
15 void * memmove( void * s1, const void * s2, size_t n )
16 {
17     char * dest = (char *) s1;
18     const char * src = (const char *) s2;
19     if ( dest <= src )
20     {
21         while ( n-- )
22         {
23             *dest++ = *src++;
24         }
25     }
26     else
27     {
28         src += n;
29         dest += n;
30         while ( n-- )
31         {
32             *--dest = *--src;
33         }
34     }
35     return s1;
36 }
37
38 #endif
39
40 #ifdef TEST
41 #include <_PDCLIB_test.h>
42
43 int main()
44 {
45     char s[] = "xxxxabcde";
46     BEGIN_TESTS;
47     TESTCASE( memmove( s, s + 4, 5 ) == s );
48     TESTCASE( s[0] == 'a' );
49     TESTCASE( s[4] == 'e' );
50     TESTCASE( s[5] == 'b' );
51     TESTCASE( memmove( s + 4, s, 5 ) == s + 4 );
52     TESTCASE( s[4] == 'a' );
53     return TEST_RESULTS;
54 }
55 #endif