110791Sjoehw/*-
210791Sjoehw * Copyright (c) 1990, 1993
310791Sjoehw *	The Regents of the University of California.  All rights reserved.
410791Sjoehw *
510791Sjoehw * This code is derived from software contributed to Berkeley by
610791Sjoehw * Chris Torek.
710791Sjoehw *
810791Sjoehw * Redistribution and use in source and binary forms, with or without
910791Sjoehw * modification, are permitted provided that the following conditions
1010791Sjoehw * are met:
1110791Sjoehw * 1. Redistributions of source code must retain the above copyright
1210791Sjoehw *    notice, this list of conditions and the following disclaimer.
1310791Sjoehw * 2. Redistributions in binary form must reproduce the above copyright
1410791Sjoehw *    notice, this list of conditions and the following disclaimer in the
1510791Sjoehw *    documentation and/or other materials provided with the distribution.
1610791Sjoehw * 3. Neither the name of the University nor the names of its contributors
1710791Sjoehw *    may be used to endorse or promote products derived from this software
1810791Sjoehw *    without specific prior written permission.
1910791Sjoehw *
2010791Sjoehw * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
2110791Sjoehw * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
2210791Sjoehw * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
2310791Sjoehw * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
2410791Sjoehw * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
2510791Sjoehw * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
2610791Sjoehw * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
2710791Sjoehw * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
2810791Sjoehw * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
2910791Sjoehw * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
3010791Sjoehw * SUCH DAMAGE.
3110791Sjoehw */
3210791Sjoehw
3310791Sjoehw#if defined(LIBC_SCCS) && !defined(lint)
3410791Sjoehwstatic char sccsid[] = "@(#)strncat.c	8.1 (Berkeley) 6/4/93";
3510791Sjoehw#endif /* LIBC_SCCS and not lint */
3610791Sjoehw#include <sys/cdefs.h>
3710791Sjoehw__FBSDID("$FreeBSD: releng/10.2/lib/libc/string/strncat.c 251069 2013-05-28 20:57:40Z emaste $");
3810791Sjoehw
3910791Sjoehw#include <string.h>
4010791Sjoehw
4110791Sjoehw/*
4210791Sjoehw * Concatenate src on the end of dst.  At most strlen(dst)+n+1 bytes
4310791Sjoehw * are written at dst (at most n+1 bytes being appended).  Return dst.
4410791Sjoehw */
4510791Sjoehwchar *
4610791Sjoehwstrncat(char * __restrict dst, const char * __restrict src, size_t n)
4710791Sjoehw{
4810791Sjoehw	if (n != 0) {
4910791Sjoehw		char *d = dst;
5010791Sjoehw		const char *s = src;
5110791Sjoehw
5210791Sjoehw		while (*d != 0)
5310791Sjoehw			d++;
5410791Sjoehw		do {
5510791Sjoehw			if ((*d = *s++) == 0)
5610791Sjoehw				break;
5710791Sjoehw			d++;
5810791Sjoehw		} while (--n != 0);
5910791Sjoehw		*d = 0;
6010791Sjoehw	}
6110791Sjoehw	return (dst);
6210791Sjoehw}
6310791Sjoehw