xref: /csrg-svn/lib/libc/string/strncat.c (revision 61193)
142167Sbostic /*-
2*61193Sbostic  * Copyright (c) 1990, 1993
3*61193Sbostic  *	The Regents of the University of California.  All rights reserved.
435093Sbostic  *
542167Sbostic  * This code is derived from software contributed to Berkeley by
642167Sbostic  * Chris Torek.
742167Sbostic  *
842167Sbostic  * %sccs.include.redist.c%
91987Swnj  */
101987Swnj 
1135093Sbostic #if defined(LIBC_SCCS) && !defined(lint)
12*61193Sbostic static char sccsid[] = "@(#)strncat.c	8.1 (Berkeley) 06/04/93";
1335093Sbostic #endif /* LIBC_SCCS and not lint */
1435093Sbostic 
1546144Sbostic #include <sys/cdefs.h>
1642167Sbostic #include <string.h>
1742167Sbostic 
1842167Sbostic /*
1942167Sbostic  * Concatenate src on the end of dst.  At most strlen(dst)+n+1 bytes
2042167Sbostic  * are written at dst (at most n+1 bytes being appended).  Return dst.
2142167Sbostic  */
221987Swnj char *
strncat(dst,src,n)2342167Sbostic strncat(dst, src, n)
2442167Sbostic 	char *dst;
2542167Sbostic 	const char *src;
2642167Sbostic 	register size_t n;
271987Swnj {
2842167Sbostic 	if (n != 0) {
2942167Sbostic 		register char *d = dst;
3042167Sbostic 		register const char *s = src;
311987Swnj 
3242167Sbostic 		while (*d != 0)
3342167Sbostic 			d++;
3442167Sbostic 		do {
3542167Sbostic 			if ((*d = *s++) == 0)
3642167Sbostic 				break;
3742167Sbostic 			d++;
3842167Sbostic 		} while (--n != 0);
3942167Sbostic 		*d = 0;
4042167Sbostic 	}
4142167Sbostic 	return (dst);
421987Swnj }
43