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.375
1 files changed, 56 insertions, 19 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3
index 5357d65754..5b878c3e8c 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.9 2003/06/02 20:18:38 millert 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,8 +49,7 @@ The
53.Fn strcat 49.Fn strcat
54and 50and
55.Fn strncat 51.Fn strncat
56functions 52functions append a copy of the null-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 null-terminated string
60.Fa s , 55.Fa s ,
@@ -66,29 +61,71 @@ 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.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
81.Sh SEE ALSO 117.Sh SEE ALSO
82.Xr bcopy 3 , 118.Xr bcopy 3 ,
83.Xr memccpy 3 , 119.Xr memccpy 3 ,
84.Xr memcpy 3 , 120.Xr memcpy 3 ,
85.Xr memmove 3 , 121.Xr memmove 3 ,
86.Xr strcpy 3 122.Xr strcpy 3 ,
123.Xr strlcat 3 ,
124.Xr strlcpy 3
87.Sh STANDARDS 125.Sh STANDARDS
88The 126The
89.Fn strcat 127.Fn strcat
90and 128and
91.Fn strncat 129.Fn strncat
92functions 130functions conform to
93conform to
94.St -ansiC . 131.St -ansiC .