1298714Sjkim/*- 2298714Sjkim * Copyright (c) 1990, 1993 3298714Sjkim * The Regents of the University of California. All rights reserved. 4298714Sjkim * 5298714Sjkim * This code is derived from software contributed to Berkeley by 6298714Sjkim * Chris Torek. 7298714Sjkim * 8298714Sjkim * Redistribution and use in source and binary forms, with or without 9298714Sjkim * modification, are permitted provided that the following conditions 10298714Sjkim * are met: 11298714Sjkim * 1. Redistributions of source code must retain the above copyright 12298714Sjkim * notice, this list of conditions and the following disclaimer. 13298714Sjkim * 2. Redistributions in binary form must reproduce the above copyright 14298714Sjkim * notice, this list of conditions and the following disclaimer in the 15298714Sjkim * documentation and/or other materials provided with the distribution. 16298714Sjkim * 3. Neither the name of the University nor the names of its contributors 17298714Sjkim * may be used to endorse or promote products derived from this software 18298714Sjkim * without specific prior written permission. 19298714Sjkim * 20298714Sjkim * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21298714Sjkim * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22298714Sjkim * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23298714Sjkim * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24298714Sjkim * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25298714Sjkim * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26298714Sjkim * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27298714Sjkim * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28298714Sjkim * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29298714Sjkim * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30298714Sjkim * SUCH DAMAGE. 31298714Sjkim */ 32298714Sjkim 33298714Sjkim#if defined(LIBC_SCCS) && !defined(lint) 34298714Sjkimstatic char sccsid[] = "@(#)strncat.c 8.1 (Berkeley) 6/4/93"; 35298714Sjkim#endif /* LIBC_SCCS and not lint */ 36298714Sjkim#include <sys/cdefs.h> 37298714Sjkim__FBSDID("$FreeBSD$"); 38298714Sjkim 39298714Sjkim#include <sys/libkern.h> 40298714Sjkim 41298714Sjkim/* 42298714Sjkim * Concatenate src on the end of dst. At most strlen(dst)+n+1 bytes 43298714Sjkim * are written at dst (at most n+1 bytes being appended). Return dst. 44298714Sjkim */ 45298714Sjkimchar * 46298714Sjkimstrncat(char *dst, const char *src, size_t n) 47298714Sjkim{ 48298714Sjkim 49298714Sjkim if (n != 0) { 50298714Sjkim char *d = dst; 51298714Sjkim const char *s = src; 52298714Sjkim 53298714Sjkim while (*d != 0) 54298714Sjkim d++; 55298714Sjkim do { 56298714Sjkim if ((*d = *s++) == 0) 57298714Sjkim break; 58298714Sjkim d++; 59298714Sjkim } while (--n != 0); 60298714Sjkim *d = 0; 61298714Sjkim } 62298714Sjkim return (dst); 63298714Sjkim} 64