]> pd.if.org Git - pdclib/blob - functions/string/strncat.c
Added #ifdef to allow regression against system lib.
[pdclib] / functions / string / strncat.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* strncat( char *, const char *, 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 char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
17 {
18     char * rc = s1;
19     while ( *s1 )
20     {
21         ++s1;
22     }
23     while ( n && ( *s1++ = *s2++ ) )
24     {
25         --n;
26     }
27     if ( n == 0 )
28     {
29         *s1 = '\0';
30     }
31     return rc;
32 }
33
34 #endif
35
36 #ifdef TEST
37 #include <_PDCLIB_test.h>
38
39 int main()
40 {
41     char s[] = "xx\0xxxxxx";
42     BEGIN_TESTS;
43     TESTCASE( strncat( s, abcde, 10 ) == s );
44     TESTCASE( s[2] == 'a' );
45     TESTCASE( s[6] == 'e' );
46     TESTCASE( s[7] == '\0' );
47     TESTCASE( s[8] == 'x' );
48     s[0] = '\0';
49     TESTCASE( strncat( s, abcdx, 10 ) == s );
50     TESTCASE( s[4] == 'x' );
51     TESTCASE( s[5] == '\0' );
52     TESTCASE( strncat( s, "\0", 10 ) == s );
53     TESTCASE( s[5] == '\0' );
54     TESTCASE( s[6] == 'e' );
55     TESTCASE( strncat( s, abcde, 0 ) == s );
56     TESTCASE( s[5] == '\0' );
57     TESTCASE( s[6] == 'e' );
58     TESTCASE( strncat( s, abcde, 3 ) == s );
59     TESTCASE( s[5] == 'a' );
60     TESTCASE( s[7] == 'c' );
61     TESTCASE( s[8] == '\0' );
62     return TEST_RESULTS;
63 }
64 #endif