1.\" $OpenBSD: strcat.3,v 1.13 2011/07/25 00:38:52 schwarze Exp $ 2.\" 3.\" Copyright (c) 1990, 1991 The Regents of the University of California. 4.\" All rights reserved. 5.\" 6.\" This code is derived from software contributed to Berkeley by 7.\" Chris Torek and the American National Standards Committee X3, 8.\" on Information Processing Systems. 9.\" 10.\" Redistribution and use in source and binary forms, with or without 11.\" modification, are permitted provided that the following conditions 12.\" are met: 13.\" 1. Redistributions of source code must retain the above copyright 14.\" notice, this list of conditions and the following disclaimer. 15.\" 2. Redistributions in binary form must reproduce the above copyright 16.\" notice, this list of conditions and the following disclaimer in the 17.\" documentation and/or other materials provided with the distribution. 18.\" 3. Neither the name of the University nor the names of its contributors 19.\" may be used to endorse or promote products derived from this software 20.\" without specific prior written permission. 21.\" 22.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 23.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 24.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 25.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 26.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 27.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 28.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 29.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 30.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 32.\" SUCH DAMAGE. 33.\" 34.Dd $Mdocdate: July 25 2011 $ 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 strlcpy 3 , 126.Xr wcscat 3 , 127.Xr wcslcpy 3 128.Sh STANDARDS 129The 130.Fn strcat 131and 132.Fn strncat 133functions conform to 134.St -ansiC . 135.Sh HISTORY 136The 137.Fn strcat 138and 139.Fn strncat 140functions first appeared in 141.At v7 . 142