diff options
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
-rw-r--r-- | src/lib/libc/string/strcpy.3 | 162 |
1 files changed, 162 insertions, 0 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3 new file mode 100644 index 0000000000..400eeee622 --- /dev/null +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -0,0 +1,162 @@ | |||
1 | .\" $OpenBSD: strcpy.3,v 1.16 2011/07/25 00:38:53 schwarze 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: July 25 2011 $ | ||
35 | .Dt STRCPY 3 | ||
36 | .Os | ||
37 | .Sh NAME | ||
38 | .Nm strcpy , | ||
39 | .Nm strncpy | ||
40 | .Nd copy strings | ||
41 | .Sh SYNOPSIS | ||
42 | .Fd #include <string.h> | ||
43 | .Ft char * | ||
44 | .Fn strcpy "char *dst" "const char *src" | ||
45 | .Ft char * | ||
46 | .Fn strncpy "char *dst" "const char *src" "size_t len" | ||
47 | .Sh DESCRIPTION | ||
48 | The | ||
49 | .Fn strcpy | ||
50 | and | ||
51 | .Fn strncpy | ||
52 | functions copy the string | ||
53 | .Fa src | ||
54 | to | ||
55 | .Fa dst | ||
56 | (including the terminating | ||
57 | .Ql \e0 | ||
58 | character). | ||
59 | .Pp | ||
60 | The | ||
61 | .Fn strncpy | ||
62 | function copies not more than | ||
63 | .Fa len | ||
64 | characters into | ||
65 | .Fa dst , | ||
66 | appending | ||
67 | .Ql \e0 | ||
68 | characters if | ||
69 | .Fa src | ||
70 | is less than | ||
71 | .Fa len | ||
72 | characters long, and | ||
73 | .Em not | ||
74 | terminating | ||
75 | .Fa dst | ||
76 | if the length of | ||
77 | .Fa src | ||
78 | is greater than or equal to | ||
79 | .Fa len . | ||
80 | .Sh RETURN VALUES | ||
81 | The | ||
82 | .Fn strcpy | ||
83 | and | ||
84 | .Fn strncpy | ||
85 | functions return | ||
86 | .Fa dst . | ||
87 | .Sh EXAMPLES | ||
88 | The following sets | ||
89 | .Va chararray | ||
90 | to | ||
91 | .Dq abc\e0\e0\e0 : | ||
92 | .Bd -literal -offset indent | ||
93 | (void)strncpy(chararray, "abc", 6); | ||
94 | .Ed | ||
95 | .Pp | ||
96 | The following sets | ||
97 | .Va chararray | ||
98 | to | ||
99 | .Dq abcdef | ||
100 | and does | ||
101 | .Em not | ||
102 | NUL terminate | ||
103 | .Va chararray | ||
104 | because the length of the source string is greater than or equal to the | ||
105 | length parameter. | ||
106 | .Fn strncpy | ||
107 | .Em only | ||
108 | NUL terminates the destination string when the length of the source | ||
109 | string is less than the length parameter. | ||
110 | .Bd -literal -offset indent | ||
111 | (void)strncpy(chararray, "abcdefgh", 6); | ||
112 | .Ed | ||
113 | .Pp | ||
114 | The following copies as many characters from | ||
115 | .Va input | ||
116 | to | ||
117 | .Va buf | ||
118 | as will fit and NUL terminates the result. | ||
119 | Because | ||
120 | .Fn strncpy | ||
121 | does | ||
122 | .Em not | ||
123 | guarantee to NUL terminate the string itself, it must be done by hand. | ||
124 | .Bd -literal -offset indent | ||
125 | char buf[BUFSIZ]; | ||
126 | |||
127 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
128 | buf[sizeof(buf) - 1] = '\e0'; | ||
129 | .Ed | ||
130 | .Pp | ||
131 | Note that | ||
132 | .Xr strlcpy 3 | ||
133 | is a better choice for this kind of operation. | ||
134 | The equivalent using | ||
135 | .Xr strlcpy 3 | ||
136 | is simply: | ||
137 | .Bd -literal -offset indent | ||
138 | (void)strlcpy(buf, input, sizeof(buf)); | ||
139 | .Ed | ||
140 | .Sh SEE ALSO | ||
141 | .Xr bcopy 3 , | ||
142 | .Xr memccpy 3 , | ||
143 | .Xr memcpy 3 , | ||
144 | .Xr memmove 3 , | ||
145 | .Xr strcat 3 , | ||
146 | .Xr strlcpy 3 , | ||
147 | .Xr wcscpy 3 , | ||
148 | .Xr wcslcpy 3 | ||
149 | .Sh STANDARDS | ||
150 | The | ||
151 | .Fn strcpy | ||
152 | and | ||
153 | .Fn strncpy | ||
154 | functions conform to | ||
155 | .St -ansiC . | ||
156 | .Sh HISTORY | ||
157 | The | ||
158 | .Fn strcpy | ||
159 | and | ||
160 | .Fn strncpy | ||
161 | functions first appeared in | ||
162 | .At v7 . | ||