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