diff options
Diffstat (limited to 'src/lib/libc/string/strcat.3')
-rw-r--r-- | src/lib/libc/string/strcat.3 | 131 |
1 files changed, 131 insertions, 0 deletions
diff --git a/src/lib/libc/string/strcat.3 b/src/lib/libc/string/strcat.3 new file mode 100644 index 0000000000..5b878c3e8c --- /dev/null +++ b/src/lib/libc/string/strcat.3 | |||
@@ -0,0 +1,131 @@ | |||
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 | ||
48 | The | ||
49 | .Fn strcat | ||
50 | and | ||
51 | .Fn strncat | ||
52 | functions append a copy of the null-terminated string | ||
53 | .Fa append | ||
54 | to the end of the null-terminated string | ||
55 | .Fa s , | ||
56 | then add a terminating | ||
57 | .Ql \e0 . | ||
58 | The string | ||
59 | .Fa s | ||
60 | must have sufficient space to hold the result. | ||
61 | .Pp | ||
62 | The | ||
63 | .Fn strncat | ||
64 | function appends not more than | ||
65 | .Fa count | ||
66 | characters where space for the terminating | ||
67 | .Ql \e0 | ||
68 | should not be included in | ||
69 | .Fa count . | ||
70 | .Sh RETURN VALUES | ||
71 | The | ||
72 | .Fn strcat | ||
73 | and | ||
74 | .Fn strncat | ||
75 | functions return the pointer | ||
76 | .Fa s . | ||
77 | .Sh EXAMPLES | ||
78 | The following appends | ||
79 | .Dq Li abc | ||
80 | to | ||
81 | .Dq Li chararray : | ||
82 | .Bd -literal -offset indent | ||
83 | char *letters = "abcdefghi"; | ||
84 | |||
85 | (void)strncat(chararray, letters, 3); | ||
86 | .Ed | ||
87 | .Pp | ||
88 | The following example shows how to use | ||
89 | .Fn strncat | ||
90 | safely in conjunction with | ||
91 | .Xr strncpy 3 . | ||
92 | .Bd -literal -offset indent | ||
93 | char buf[BUFSIZ]; | ||
94 | char *input, *suffix; | ||
95 | |||
96 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
97 | buf[sizeof(buf) - 1] = '\e0'; | ||
98 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
99 | .Ed | ||
100 | .Pp | ||
101 | The above will copy as many characters from | ||
102 | .Dq Li input | ||
103 | to | ||
104 | .Dq Li buf | ||
105 | as will fit. | ||
106 | It then appends as many characters from suffix as will fit (or none | ||
107 | if there is no space). | ||
108 | For operations like this, the | ||
109 | .Xr strlcpy 3 | ||
110 | and | ||
111 | .Xr strlcat 3 | ||
112 | functions 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 | ||
126 | The | ||
127 | .Fn strcat | ||
128 | and | ||
129 | .Fn strncat | ||
130 | functions conform to | ||
131 | .St -ansiC . | ||