]> pd.if.org Git - pdclib/blob - functions/wchar/wcsncat.c
dos2unix
[pdclib] / functions / wchar / wcsncat.c
1 /* wcsncat( wchar_t *, const wchar_t *, 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 <wchar.h>
8
9 #ifndef REGTEST
10
11 wchar_t * wcsncat( wchar_t * _PDCLIB_restrict s1, 
12                    const wchar_t * _PDCLIB_restrict s2, 
13                    size_t n )
14 {
15     wchar_t * rc = s1;
16     while ( *s1 )
17     {
18         ++s1;
19     }
20     while ( n && ( *s1++ = *s2++ ) )
21     {
22         --n;
23     }
24     if ( n == 0 )
25     {
26         *s1 = '\0';
27     }
28     return rc;
29 }
30
31 #endif
32
33 #ifdef TEST
34 #include "_PDCLIB_test.h"
35
36 int main( void )
37 {
38     wchar_t s[] = L"xx\0xxxxxx";
39     TESTCASE( wcsncat( s, wabcde, 10 ) == s );
40     TESTCASE( s[2] == L'a' );
41     TESTCASE( s[6] == L'e' );
42     TESTCASE( s[7] == L'\0' );
43     TESTCASE( s[8] == L'x' );
44     s[0] = L'\0';
45     TESTCASE( wcsncat( s, wabcdx, 10 ) == s );
46     TESTCASE( s[4] == L'x' );
47     TESTCASE( s[5] == L'\0' );
48     TESTCASE( wcsncat( s, L"\0", 10 ) == s );
49     TESTCASE( s[5] == L'\0' );
50     TESTCASE( s[6] == L'e' );
51     TESTCASE( wcsncat( s, wabcde, 0 ) == s );
52     TESTCASE( s[5] == L'\0' );
53     TESTCASE( s[6] == L'e' );
54     TESTCASE( wcsncat( s, wabcde, 3 ) == s );
55     TESTCASE( s[5] == L'a' );
56     TESTCASE( s[7] == L'c' );
57     TESTCASE( s[8] == L'\0' );
58     return TEST_RESULTS;
59 }
60 #endif