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