]> pd.if.org Git - pdclib/blob - functions/string/memcpy.c
064cc3479f54a498ad0144a712f58eb16290dba5
[pdclib] / functions / string / memcpy.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* memcpy( 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 <_PDCLIB_aux.h>
12 #include <string.h>
13
14 #ifndef REGTEST
15
16 void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n )
17 {
18     char * dest = (char *) s1;
19     const char * src = (const char *) s2;
20     while ( n-- )
21     {
22         *dest++ = *src++;
23     }
24     return s1;
25 }
26
27 #endif
28
29 #ifdef TEST
30 #include <_PDCLIB_test.h>
31
32 int main()
33 {
34     char s[] = "xxxxxxxxxxx";
35     BEGIN_TESTS;
36     TESTCASE( memcpy( s, abcde, 6 ) == s );
37     TESTCASE( s[4] == 'e' );
38     TESTCASE( s[5] == '\0' );
39     TESTCASE( memcpy( s + 5, abcde, 5 ) == s + 5 );
40     TESTCASE( s[9] == 'e' );
41     TESTCASE( s[10] == 'x' );
42     return TEST_RESULTS;
43 }
44 #endif