3 /* strncpy( char *, const char *, size_t )
5 This file is part of the Public Domain C Library (PDCLib).
6 Permission is granted to use, modify, and / or redistribute at will.
11 /* TODO: Debuggung only */
16 char * strncpy( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
19 while ( ( n > 0 ) && ( *s1++ = *s2++ ) )
21 /* Cannot do "n--" in the conditional as size_t is unsigned and we have
22 to check it again for >0 in the next loop.
26 /* TODO: This works correctly, but somehow the handling of n is ugly as
42 #include <_PDCLIB_test.h>
47 TESTCASE( strncpy( s, "", 1 ) == s );
48 TESTCASE( s[0] == '\0' );
49 TESTCASE( s[1] == 'x' );
50 TESTCASE( strncpy( s, abcde, 6 ) == s );
51 TESTCASE( s[0] == 'a' );
52 TESTCASE( s[4] == 'e' );
53 TESTCASE( s[5] == '\0' );
54 TESTCASE( s[6] == 'x' );
55 TESTCASE( strncpy( s, abcde, 7 ) == s );
56 TESTCASE( s[6] == '\0' );
57 TESTCASE( strncpy( s, "xxxx", 3 ) == s );
58 TESTCASE( s[0] == 'x' );
59 TESTCASE( s[2] == 'x' );
60 TESTCASE( s[3] == 'd' );