diff options
Diffstat (limited to '')
-rw-r--r-- | src/lib/libc/string/strncat.3 | 132 |
1 files changed, 0 insertions, 132 deletions
diff --git a/src/lib/libc/string/strncat.3 b/src/lib/libc/string/strncat.3 deleted file mode 100644 index d314a9999a..0000000000 --- a/src/lib/libc/string/strncat.3 +++ /dev/null | |||
@@ -1,132 +0,0 @@ | |||
1 | .\" $OpenBSD: strncat.3,v 1.4 2014/04/19 16:50:46 jmc 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: April 19 2014 $ | ||
35 | .Dt STRNCAT 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm strncat | ||
39 | .Nd concatenate a string with part of another | ||
40 | .Sh SYNOPSIS | ||
41 | .In string.h | ||
42 | .Ft char * | ||
43 | .Fn strncat "char *dst" "const char *append" "size_t count" | ||
44 | .Sh DESCRIPTION | ||
45 | The | ||
46 | .Fn strncat | ||
47 | function appends not more than | ||
48 | .Fa count | ||
49 | characters of the string | ||
50 | .Fa append | ||
51 | to the end of the string found in the buffer | ||
52 | .Fa dst . | ||
53 | Space for the terminating | ||
54 | .Ql \e0 | ||
55 | should not be included in | ||
56 | .Fa count . | ||
57 | .Pp | ||
58 | Bounds checking must be performed manually with great care. | ||
59 | If the buffer | ||
60 | .Fa dst | ||
61 | is not large enough to hold the result, | ||
62 | subsequent memory will be damaged. | ||
63 | .Sh RETURN VALUES | ||
64 | The | ||
65 | .Fn strncat | ||
66 | function returns the pointer | ||
67 | .Fa dst . | ||
68 | .Sh EXAMPLES | ||
69 | The following example shows how to use | ||
70 | .Fn strncat | ||
71 | in conjunction with | ||
72 | .Xr strncpy 3 : | ||
73 | .Bd -literal -offset indent | ||
74 | char buf[BUFSIZ]; | ||
75 | char *base, *suffix; | ||
76 | |||
77 | (void)strncpy(buf, base, sizeof(buf) - 1); | ||
78 | buf[sizeof(buf) - 1] = '\e0'; | ||
79 | (void)strncat(buf, suffix, sizeof(buf) - 1 - strlen(buf)); | ||
80 | .Ed | ||
81 | .Pp | ||
82 | The above will copy as many characters from | ||
83 | .Va base | ||
84 | to | ||
85 | .Va buf | ||
86 | as will fit. | ||
87 | It then appends as many characters from | ||
88 | .Va suffix | ||
89 | as will fit. | ||
90 | If either | ||
91 | .Va base | ||
92 | or | ||
93 | .Va suffix | ||
94 | are too large, truncation will occur without detection. | ||
95 | .Pp | ||
96 | The above example shows dangerous coding patterns, including an | ||
97 | inability to detect truncation. | ||
98 | .Fn strncat | ||
99 | and | ||
100 | .Fn strncpy | ||
101 | are dangerously easy to misuse. | ||
102 | The | ||
103 | .Xr strlcpy 3 | ||
104 | and | ||
105 | .Xr strlcat 3 | ||
106 | functions are safer for this kind of operation: | ||
107 | .Bd -literal -offset indent | ||
108 | if (strlcpy(buf, base, sizeof(buf)) >= sizeof(buf) || | ||
109 | strlcat(buf, suffix, sizeof(buf)) >= sizeof(buf)) | ||
110 | goto toolong; | ||
111 | |||
112 | .Ed | ||
113 | or for greatest portability, | ||
114 | .Bd -literal -offset indent | ||
115 | if (snprintf(buf, sizeof(buf), "%s%s", | ||
116 | base, suffix) >= sizeof(buf)) | ||
117 | goto toolong; | ||
118 | .Ed | ||
119 | .Sh SEE ALSO | ||
120 | .Xr strlcpy 3 , | ||
121 | .Xr wcscat 3 , | ||
122 | .Xr wcslcpy 3 | ||
123 | .Sh STANDARDS | ||
124 | The | ||
125 | .Fn strncat | ||
126 | function conforms to | ||
127 | .St -ansiC . | ||
128 | .Sh HISTORY | ||
129 | The | ||
130 | .Fn strncat | ||
131 | function first appeared in | ||
132 | .At v7 . | ||