150276Speter/*- 2166124Srafan * Copyright (c) 1990, 1993 350276Speter * The Regents of the University of California. All rights reserved. 450276Speter * 550276Speter * This code is derived from software contributed to Berkeley by 650276Speter * Chris Torek. 750276Speter * 850276Speter * Redistribution and use in source and binary forms, with or without 950276Speter * modification, are permitted provided that the following conditions 1050276Speter * are met: 1150276Speter * 1. Redistributions of source code must retain the above copyright 1250276Speter * notice, this list of conditions and the following disclaimer. 1350276Speter * 2. Redistributions in binary form must reproduce the above copyright 1450276Speter * notice, this list of conditions and the following disclaimer in the 1550276Speter * documentation and/or other materials provided with the distribution. 1650276Speter * 3. Neither the name of the University nor the names of its contributors 1750276Speter * may be used to endorse or promote products derived from this software 1850276Speter * without specific prior written permission. 1950276Speter * 2050276Speter * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 2150276Speter * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2250276Speter * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2350276Speter * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2450276Speter * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2550276Speter * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2650276Speter * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2750276Speter * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2850276Speter * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29166124Srafan * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3050276Speter * SUCH DAMAGE. 3150276Speter */ 3262449Speter 3362449Speter#if defined(LIBC_SCCS) && !defined(lint) 3462449Speterstatic char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; 3550276Speter#endif /* LIBC_SCCS and not lint */ 3650276Speter#include <sys/cdefs.h> 37166124Srafan__FBSDID("$FreeBSD: stable/10/sys/libkern/strncat.c 306536 2016-09-30 22:40:58Z jkim $"); 38166124Srafan 3950276Speter#include <sys/libkern.h> 40166124Srafan 4150276Speter/* 42166124Srafan * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes 4350276Speter * are written at dst (at most n+1 bytes being appended). Return dst. 44166124Srafan */ 4550276Speterchar * 4650276Speterstrncat(char *dst, const char *src, size_t n) 4750276Speter{ 4850276Speter 4950276Speter if (n != 0) { 5050276Speter char *d = dst; 5150276Speter const char *s = src; 5250276Speter 5350276Speter while (*d != 0) 5450276Speter d++; 5550276Speter do { 5650276Speter if ((*d = *s++) == 0) 5750276Speter break; 5850276Speter d++; 59166124Srafan } while (--n != 0); 60166124Srafan *d = 0; 61166124Srafan } 6250276Speter return (dst); 63166124Srafan} 6450276Speter