diff options
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
-rw-r--r-- | src/lib/libc/string/strcpy.3 | 83 |
1 files changed, 56 insertions, 27 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 index 1ca12c2707..428e474d43 100644 --- a/src/lib/libc/string/strcpy.3 +++ b/src/lib/libc/string/strcpy.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: @(#)strcpy.3 5.4 (Berkeley) 6/29/91 | 32 | .\" $OpenBSD: strcpy.3,v 1.15 2007/05/31 19:19:32 jmc Exp $ |
37 | .\" $Id: strcpy.3,v 1.1.1.1 1995/10/18 08:42:22 deraadt Exp $ | ||
38 | .\" | 33 | .\" |
39 | .Dd June 29, 1991 | 34 | .Dd $Mdocdate: May 31 2007 $ |
40 | .Dt STRCPY 3 | 35 | .Dt STRCPY 3 |
41 | .Os BSD 4 | 36 | .Os |
42 | .Sh NAME | 37 | .Sh NAME |
43 | .Nm strcpy | 38 | .Nm strcpy , |
39 | .Nm strncpy | ||
44 | .Nd copy strings | 40 | .Nd copy strings |
45 | .Sh SYNOPSIS | 41 | .Sh SYNOPSIS |
46 | .Fd #include <string.h> | 42 | .Fd #include <string.h> |
@@ -53,8 +49,7 @@ The | |||
53 | .Fn strcpy | 49 | .Fn strcpy |
54 | and | 50 | and |
55 | .Fn strncpy | 51 | .Fn strncpy |
56 | functions | 52 | functions copy the string |
57 | copy the string | ||
58 | .Fa src | 53 | .Fa src |
59 | to | 54 | to |
60 | .Fa dst | 55 | .Fa dst |
@@ -62,7 +57,6 @@ to | |||
62 | .Ql \e0 | 57 | .Ql \e0 |
63 | character). | 58 | character). |
64 | .Pp | 59 | .Pp |
65 | The | ||
66 | .Fn strncpy | 60 | .Fn strncpy |
67 | copies not more than | 61 | copies not more than |
68 | .Fa len | 62 | .Fa len |
@@ -78,45 +72,80 @@ characters long, and | |||
78 | .Em not | 72 | .Em not |
79 | terminating | 73 | terminating |
80 | .Fa dst | 74 | .Fa dst |
81 | if | 75 | if the length of |
82 | .Fa src | 76 | .Fa src |
83 | is more than | 77 | is greater than or equal to |
84 | .Fa len | 78 | .Fa len . |
85 | characters long. | ||
86 | .Sh RETURN VALUES | 79 | .Sh RETURN VALUES |
87 | The | 80 | The |
88 | .Fn strcpy | 81 | .Fn strcpy |
89 | and | 82 | and |
90 | .Fn strncpy | 83 | .Fn strncpy |
91 | functions | 84 | functions return |
92 | return | ||
93 | .Fa dst . | 85 | .Fa dst . |
94 | .Sh EXAMPLES | 86 | .Sh EXAMPLES |
95 | The following sets | 87 | The following sets |
96 | .Dq Li chararray | 88 | .Va chararray |
97 | to | 89 | to |
98 | .Dq Li abc\e0\e0\e0 : | 90 | .Dq abc\e0\e0\e0 : |
99 | .Bd -literal -offset indent | 91 | .Bd -literal -offset indent |
100 | (void)strncpy(chararray, "abc", 6). | 92 | (void)strncpy(chararray, "abc", 6); |
101 | .Ed | 93 | .Ed |
102 | .Pp | 94 | .Pp |
103 | The following sets | 95 | The following sets |
104 | .Dq Li chararray | 96 | .Va chararray |
105 | to | 97 | to |
106 | .Dq Li abcdef : | 98 | .Dq abcdef |
99 | and does | ||
100 | .Em not | ||
101 | NUL terminate | ||
102 | .Va chararray | ||
103 | because the length of the source string is greater than or equal to the | ||
104 | length parameter. | ||
105 | .Fn strncpy | ||
106 | .Em only | ||
107 | NUL terminates the destination string when the length of the source | ||
108 | string is less than the length parameter. | ||
107 | .Bd -literal -offset indent | 109 | .Bd -literal -offset indent |
108 | (void)strncpy(chararray, "abcdefgh", 6); | 110 | (void)strncpy(chararray, "abcdefgh", 6); |
109 | .Ed | 111 | .Ed |
112 | .Pp | ||
113 | The following copies as many characters from | ||
114 | .Va input | ||
115 | to | ||
116 | .Va buf | ||
117 | as will fit and NUL terminates the result. | ||
118 | Because | ||
119 | .Fn strncpy | ||
120 | does | ||
121 | .Em not | ||
122 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
123 | .Bd -literal -offset indent | ||
124 | char buf[BUFSIZ]; | ||
125 | |||
126 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
127 | buf[sizeof(buf) - 1] = '\e0'; | ||
128 | .Ed | ||
129 | .Pp | ||
130 | Note that | ||
131 | .Xr strlcpy 3 | ||
132 | is a better choice for this kind of operation. | ||
133 | The equivalent using | ||
134 | .Xr strlcpy 3 | ||
135 | is simply: | ||
136 | .Bd -literal -offset indent | ||
137 | (void)strlcpy(buf, input, sizeof(buf)); | ||
138 | .Ed | ||
110 | .Sh SEE ALSO | 139 | .Sh SEE ALSO |
111 | .Xr bcopy 3 , | 140 | .Xr bcopy 3 , |
112 | .Xr memccpy 3 , | 141 | .Xr memccpy 3 , |
113 | .Xr memcpy 3 , | 142 | .Xr memcpy 3 , |
114 | .Xr memmove 3 | 143 | .Xr memmove 3 , |
144 | .Xr strlcpy 3 | ||
115 | .Sh STANDARDS | 145 | .Sh STANDARDS |
116 | The | 146 | The |
117 | .Fn strcpy | 147 | .Fn strcpy |
118 | and | 148 | and |
119 | .Fn strncpy | 149 | .Fn strncpy |
120 | functions | 150 | functions conform to |
121 | conform to | ||
122 | .St -ansiC . | 151 | .St -ansiC . |