]> pd.if.org Git - pdclib/blob - functions/string/strcat.c
bb7db50abc62203fa62473b4a98b74b6f33ec56d
[pdclib] / functions / string / strcat.c
1 /* $Id$ */
2
3 /* strcat( char *, const char * )
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 * 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 #endif
25
26 #ifdef TEST
27 #include <_PDCLIB_test.h>
28
29 int main( void )
30 {
31     char s[] = "xx\0xxxxxx";
32     TESTCASE( strcat( s, abcde ) == s );
33     TESTCASE( s[2] == 'a' );
34     TESTCASE( s[6] == 'e' );
35     TESTCASE( s[7] == '\0' );
36     TESTCASE( s[8] == 'x' );
37     s[0] = '\0';
38     TESTCASE( strcat( s, abcdx ) == s );
39     TESTCASE( s[4] == 'x' );
40     TESTCASE( s[5] == '\0' );
41     TESTCASE( strcat( s, "\0" ) == s );
42     TESTCASE( s[5] == '\0' );
43     TESTCASE( s[6] == 'e' );
44     return TEST_RESULTS;
45 }
46 #endif