]> pd.if.org Git - pdclib/blob - functions/string/strncat.c
Removed the $Name$ tags (not supported by SVN). Added $Id$ to Makefile / text files.
[pdclib] / functions / string / strncat.c
1 /* $Id$ */
2
3 /* strncat( char *, const char *, size_t )
4
5    This file is part of the Public Domain C Library (PDCLib).
6    Permission is granted to use, modify, and / or redistribute at will.
7 */
8
9 #include <string.h>
10
11 #ifndef REGTEST
12
13 char * strncat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2, size_t n )
14 {
15     char * 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     char s[] = "xx\0xxxxxx";
39     TESTCASE( strncat( s, abcde, 10 ) == s );
40     TESTCASE( s[2] == 'a' );
41     TESTCASE( s[6] == 'e' );
42     TESTCASE( s[7] == '\0' );
43     TESTCASE( s[8] == 'x' );
44     s[0] = '\0';
45     TESTCASE( strncat( s, abcdx, 10 ) == s );
46     TESTCASE( s[4] == 'x' );
47     TESTCASE( s[5] == '\0' );
48     TESTCASE( strncat( s, "\0", 10 ) == s );
49     TESTCASE( s[5] == '\0' );
50     TESTCASE( s[6] == 'e' );
51     TESTCASE( strncat( s, abcde, 0 ) == s );
52     TESTCASE( s[5] == '\0' );
53     TESTCASE( s[6] == 'e' );
54     TESTCASE( strncat( s, abcde, 3 ) == s );
55     TESTCASE( s[5] == 'a' );
56     TESTCASE( s[7] == 'c' );
57     TESTCASE( s[8] == '\0' );
58     return TEST_RESULTS;
59 }
60 #endif