1.\" Copyright (c) 1990, 1991 The Regents of the University of California. 2.\" All rights reserved. 3.\" 4.\" This code is derived from software contributed to Berkeley by 5.\" Chris Torek and the American National Standards Committee X3, 6.\" on Information Processing Systems. 7.\" 8.\" Redistribution and use in source and binary forms, with or without 9.\" modification, are permitted provided that the following conditions 10.\" are met: 11.\" 1. Redistributions of source code must retain the above copyright 12.\" notice, this list of conditions and the following disclaimer. 13.\" 2. Redistributions in binary form must reproduce the above copyright 14.\" notice, this list of conditions and the following disclaimer in the 15.\" documentation and/or other materials provided with the distribution. 16.\" 3. Neither the name of the University nor the names of its contributors 17.\" may be used to endorse or promote products derived from this software 18.\" without specific prior written permission. 19.\" 20.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 23.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 30.\" SUCH DAMAGE. 31.\" 32.\" $OpenBSD: strcat.3,v 1.9 2003/06/02 20:18:38 millert Exp $ 33.\" 34.Dd July 8, 1997 35.Dt STRCAT 3 36.Os 37.Sh NAME 38.Nm strcat , 39.Nm strncat 40.Nd concatenate strings 41.Sh SYNOPSIS 42.Fd #include <string.h> 43.Ft char * 44.Fn strcat "char *s" "const char *append" 45.Ft char * 46.Fn strncat "char *s" "const char *append" "size_t count" 47.Sh DESCRIPTION 48The 49.Fn strcat 50and 51.Fn strncat 52functions append a copy of the null-terminated string 53.Fa append 54to the end of the null-terminated string 55.Fa s , 56then add a terminating 57.Ql \e0 . 58The string 59.Fa s 60must have sufficient space to hold the result. 61.Pp 62The 63.Fn strncat 64function appends not more than 65.Fa count 66characters where space for the terminating 67.Ql \e0 68should not be included in 69.Fa count . 70.Sh RETURN VALUES 71The 72.Fn strcat 73and 74.Fn strncat 75functions return the pointer 76.Fa s . 77.Sh EXAMPLES 78The following appends 79.Dq Li abc 80to 81.Dq Li chararray : 82.Bd -literal -offset indent 83char *letters = "abcdefghi"; 84 85(void)strncat(chararray, letters, 3); 86.Ed 87.Pp 88The following example shows how to use 89.Fn strncat 90safely in conjunction with 91.Xr strncpy 3 . 92.Bd -literal -offset indent 93char buf[BUFSIZ]; 94char *input, *suffix; 95 96(void)strncpy(buf, input, sizeof(buf) - 1); 97buf[sizeof(buf) - 1] = '\e0'; 98(void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); 99.Ed 100.Pp 101The above will copy as many characters from 102.Dq Li input 103to 104.Dq Li buf 105as will fit. 106It then appends as many characters from suffix as will fit (or none 107if there is no space). 108For operations like this, the 109.Xr strlcpy 3 110and 111.Xr strlcat 3 112functions are a better choice, as shown below. 113.Bd -literal -offset indent 114(void)strlcpy(buf, input, sizeof(buf)); 115(void)strlcat(buf, suffix, sizeof(buf)); 116.Ed 117.Sh SEE ALSO 118.Xr bcopy 3 , 119.Xr memccpy 3 , 120.Xr memcpy 3 , 121.Xr memmove 3 , 122.Xr strcpy 3 , 123.Xr strlcat 3 , 124.Xr strlcpy 3 125.Sh STANDARDS 126The 127.Fn strcat 128and 129.Fn strncat 130functions conform to 131.St -ansiC . 132