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.12 2007/05/31 19:19:32 jmc Exp $ 33.\" 34.Dd $Mdocdate: May 31 2007 $ 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 NUL-terminated string 53.Fa append 54to the end of the NUL-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.Va 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.Va input 103to 104.Va buf 105as will fit. 106It then appends as many characters from 107.Va suffix 108as will fit (or none 109if there is no space). 110For operations like this, the 111.Xr strlcpy 3 112and 113.Xr strlcat 3 114functions are a better choice, as shown below. 115.Bd -literal -offset indent 116(void)strlcpy(buf, input, sizeof(buf)); 117(void)strlcat(buf, suffix, sizeof(buf)); 118.Ed 119.Sh SEE ALSO 120.Xr bcopy 3 , 121.Xr memccpy 3 , 122.Xr memcpy 3 , 123.Xr memmove 3 , 124.Xr strcpy 3 , 125.Xr strlcat 3 , 126.Xr strlcpy 3 127.Sh STANDARDS 128The 129.Fn strcat 130and 131.Fn strncat 132functions conform to 133.St -ansiC . 134