]> pd.if.org Git - pdclib/blob - functions/string/memcpy.c
21ef10e45933491a2e79b3ceda12adbcb8a2241f
[pdclib] / functions / string / memcpy.c
1 /* memcpy( void *, const void *, size_t )
2
3    This file is part of the Public Domain C Library (PDCLib).
4    Permission is granted to use, modify, and / or redistribute at will.
5 */
6
7 #include <string.h>
8
9 #ifndef REGTEST
10
11 void * memcpy( void * _PDCLIB_restrict s1, const void * _PDCLIB_restrict s2, size_t n )
12 {
13     char * dest = (char *) s1;
14     const char * src = (const char *) s2;
15     while ( n-- )
16     {
17         *dest++ = *src++;
18     }
19     return s1;
20 }
21
22 #endif
23
24 #ifdef TEST
25
26 #include "_PDCLIB_test.h"
27
28 int main( void )
29 {
30     char s[] = "xxxxxxxxxxx";
31     TESTCASE( memcpy( s, abcde, 6 ) == s );
32     TESTCASE( s[4] == 'e' );
33     TESTCASE( s[5] == '\0' );
34     TESTCASE( memcpy( s + 5, abcde, 5 ) == s + 5 );
35     TESTCASE( s[9] == 'e' );
36     TESTCASE( s[10] == 'x' );
37     return TEST_RESULTS;
38 }
39
40 #endif