]> pd.if.org Git - pdclib/blob - functions/string/strcat.c
d1135756069099dad2a478e9a55a19f65951750b
[pdclib] / functions / string / strcat.c
1 /* $Id$ */
2
3 /* Release $Name$ */
4
5 /* strcat( char *, const char * )
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
13 char * strcat( char * _PDCLIB_restrict s1, const char * _PDCLIB_restrict s2 )
14 {
15     char * rc = s1;
16     if ( *s1 )
17     {
18         while ( *++s1 );
19     }
20     while ( (*s1++ = *s2++) );
21     return rc;
22 }
23
24 #ifdef TEST
25 #include <_PDCLIB_test.h>
26
27 int main()
28 {
29     char s[] = "xx\0xxxxxx";
30     BEGIN_TESTS;
31     TESTCASE( strcat( s, abcde ) == s );
32     TESTCASE( s[2] == 'a' );
33     TESTCASE( s[6] == 'e' );
34     TESTCASE( s[7] == '\0' );
35     TESTCASE( s[8] == 'x' );
36     s[0] = '\0';
37     TESTCASE( strcat( s, abcdx ) == s );
38     TESTCASE( s[4] == 'x' );
39     TESTCASE( s[5] == '\0' );
40     TESTCASE( strcat( s, "\0" ) == s );
41     TESTCASE( s[5] == '\0' );
42     TESTCASE( s[6] == 'e' );
43     return TEST_RESULTS;
44 }
45 #endif