summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/strcat.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/strcat.3')
-rw-r--r--src/lib/libc/string/strcat.379
1 files changed, 59 insertions, 20 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3
index 5357d65754..b81e724917 100644
--- a/src/lib/libc/string/strcat.3
+++ b/src/lib/libc/string/strcat.3
@@ -13,11 +13,7 @@
13.\" 2. Redistributions in binary form must reproduce the above copyright 13.\" 2. Redistributions in binary form must reproduce the above copyright
14.\" notice, this list of conditions and the following disclaimer in the 14.\" notice, this list of conditions and the following disclaimer in the
15.\" documentation and/or other materials provided with the distribution. 15.\" documentation and/or other materials provided with the distribution.
16.\" 3. All advertising materials mentioning features or use of this software 16.\" 3. Neither the name of the University nor the names of its contributors
17.\" must display the following acknowledgement:
18.\" This product includes software developed by the University of
19.\" California, Berkeley and its contributors.
20.\" 4. Neither the name of the University nor the names of its contributors
21.\" may be used to endorse or promote products derived from this software 17.\" may be used to endorse or promote products derived from this software
22.\" without specific prior written permission. 18.\" without specific prior written permission.
23.\" 19.\"
@@ -33,14 +29,14 @@
33.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
34.\" SUCH DAMAGE. 30.\" SUCH DAMAGE.
35.\" 31.\"
36.\" from: @(#)strcat.3 5.6 (Berkeley) 6/29/91 32.\" $OpenBSD: strcat.3,v 1.11 2005/08/06 03:21:36 jaredy Exp $
37.\" $Id: strcat.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $
38.\" 33.\"
39.Dd June 29, 1991 34.Dd July 8, 1997
40.Dt STRCAT 3 35.Dt STRCAT 3
41.Os 36.Os
42.Sh NAME 37.Sh NAME
43.Nm strcat 38.Nm strcat ,
39.Nm strncat
44.Nd concatenate strings 40.Nd concatenate strings
45.Sh SYNOPSIS 41.Sh SYNOPSIS
46.Fd #include <string.h> 42.Fd #include <string.h>
@@ -53,10 +49,9 @@ The
53.Fn strcat 49.Fn strcat
54and 50and
55.Fn strncat 51.Fn strncat
56functions 52functions append a copy of the NUL-terminated string
57append a copy of the null-terminated string
58.Fa append 53.Fa append
59to the end of the null-terminated string 54to the end of the NUL-terminated string
60.Fa s , 55.Fa s ,
61then add a terminating 56then add a terminating
62.Ql \e0 . 57.Ql \e0 .
@@ -66,29 +61,73 @@ must have sufficient space to hold the result.
66.Pp 61.Pp
67The 62The
68.Fn strncat 63.Fn strncat
69function 64function appends not more than
70appends not more than
71.Fa count 65.Fa count
72characters. 66characters where space for the terminating
67.Ql \e0
68should not be included in
69.Fa count .
73.Sh RETURN VALUES 70.Sh RETURN VALUES
74The 71The
75.Fn strcat 72.Fn strcat
76and 73and
77.Fn strncat 74.Fn strncat
78functions 75functions return the pointer
79return the pointer
80.Fa s . 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
81.Sh SEE ALSO 119.Sh SEE ALSO
82.Xr bcopy 3 , 120.Xr bcopy 3 ,
83.Xr memccpy 3 , 121.Xr memccpy 3 ,
84.Xr memcpy 3 , 122.Xr memcpy 3 ,
85.Xr memmove 3 , 123.Xr memmove 3 ,
86.Xr strcpy 3 124.Xr strcpy 3 ,
125.Xr strlcat 3 ,
126.Xr strlcpy 3
87.Sh STANDARDS 127.Sh STANDARDS
88The 128The
89.Fn strcat 129.Fn strcat
90and 130and
91.Fn strncat 131.Fn strncat
92functions 132functions conform to
93conform to
94.St -ansiC . 133.St -ansiC .