diff options
Diffstat (limited to 'src/lib/libc/string/strcat.3')
-rw-r--r-- | src/lib/libc/string/strcat.3 | 79 |
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 |
54 | and | 50 | and |
55 | .Fn strncat | 51 | .Fn strncat |
56 | functions | 52 | functions append a copy of the NUL-terminated string |
57 | append a copy of the null-terminated string | ||
58 | .Fa append | 53 | .Fa append |
59 | to the end of the null-terminated string | 54 | to the end of the NUL-terminated string |
60 | .Fa s , | 55 | .Fa s , |
61 | then add a terminating | 56 | then 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 |
67 | The | 62 | The |
68 | .Fn strncat | 63 | .Fn strncat |
69 | function | 64 | function appends not more than |
70 | appends not more than | ||
71 | .Fa count | 65 | .Fa count |
72 | characters. | 66 | characters where space for the terminating |
67 | .Ql \e0 | ||
68 | should not be included in | ||
69 | .Fa count . | ||
73 | .Sh RETURN VALUES | 70 | .Sh RETURN VALUES |
74 | The | 71 | The |
75 | .Fn strcat | 72 | .Fn strcat |
76 | and | 73 | and |
77 | .Fn strncat | 74 | .Fn strncat |
78 | functions | 75 | functions return the pointer |
79 | return the pointer | ||
80 | .Fa s . | 76 | .Fa s . |
77 | .Sh EXAMPLES | ||
78 | The following appends | ||
79 | .Dq Li abc | ||
80 | to | ||
81 | .Va 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 | .Va input | ||
103 | to | ||
104 | .Va buf | ||
105 | as will fit. | ||
106 | It then appends as many characters from | ||
107 | .Va suffix | ||
108 | as will fit (or none | ||
109 | if there is no space). | ||
110 | For operations like this, the | ||
111 | .Xr strlcpy 3 | ||
112 | and | ||
113 | .Xr strlcat 3 | ||
114 | functions 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 |
88 | The | 128 | The |
89 | .Fn strcat | 129 | .Fn strcat |
90 | and | 130 | and |
91 | .Fn strncat | 131 | .Fn strncat |
92 | functions | 132 | functions conform to |
93 | conform to | ||
94 | .St -ansiC . | 133 | .St -ansiC . |