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