xref: /csrg-svn/lib/libc/string/strncat.c (revision 42167)
1*42167Sbostic /*-
2*42167Sbostic  * Copyright (c) 1990 The Regents of the University of California.
335093Sbostic  * All rights reserved.
435093Sbostic  *
5*42167Sbostic  * This code is derived from software contributed to Berkeley by
6*42167Sbostic  * Chris Torek.
7*42167Sbostic  *
8*42167Sbostic  * %sccs.include.redist.c%
91987Swnj  */
101987Swnj 
1135093Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*42167Sbostic static char sccsid[] = "@(#)strncat.c	5.5 (Berkeley) 05/17/90";
1335093Sbostic #endif /* LIBC_SCCS and not lint */
1435093Sbostic 
15*42167Sbostic #include <sys/stdc.h>
16*42167Sbostic #include <string.h>
17*42167Sbostic 
18*42167Sbostic /*
19*42167Sbostic  * Concatenate src on the end of dst.  At most strlen(dst)+n+1 bytes
20*42167Sbostic  * are written at dst (at most n+1 bytes being appended).  Return dst.
21*42167Sbostic  */
221987Swnj char *
23*42167Sbostic strncat(dst, src, n)
24*42167Sbostic 	char *dst;
25*42167Sbostic 	const char *src;
26*42167Sbostic 	register size_t n;
271987Swnj {
28*42167Sbostic 	if (n != 0) {
29*42167Sbostic 		register char *d = dst;
30*42167Sbostic 		register const char *s = src;
311987Swnj 
32*42167Sbostic 		while (*d != 0)
33*42167Sbostic 			d++;
34*42167Sbostic 		do {
35*42167Sbostic 			if ((*d = *s++) == 0)
36*42167Sbostic 				break;
37*42167Sbostic 			d++;
38*42167Sbostic 		} while (--n != 0);
39*42167Sbostic 		*d = 0;
40*42167Sbostic 	}
41*42167Sbostic 	return (dst);
421987Swnj }
43