diff options
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
-rw-r--r-- | src/lib/libc/string/strcpy.3 | 150 |
1 files changed, 150 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..8304508df6 --- /dev/null +++ b/src/lib/libc/string/strcpy.3 | |||
@@ -0,0 +1,150 @@ | |||
1 | .\" Copyright (c) 1990, 1991 The Regents of the University of California. | ||
2 | .\" All rights reserved. | ||
3 | .\" | ||
4 | .\" This code is derived from software contributed to Berkeley by | ||
5 | .\" Chris Torek and the American National Standards Committee X3, | ||
6 | .\" on Information Processing Systems. | ||
7 | .\" | ||
8 | .\" Redistribution and use in source and binary forms, with or without | ||
9 | .\" modification, are permitted provided that the following conditions | ||
10 | .\" are met: | ||
11 | .\" 1. Redistributions of source code must retain the above copyright | ||
12 | .\" notice, this list of conditions and the following disclaimer. | ||
13 | .\" 2. Redistributions in binary form must reproduce the above copyright | ||
14 | .\" notice, this list of conditions and the following disclaimer in the | ||
15 | .\" documentation and/or other materials provided with the distribution. | ||
16 | .\" 3. Neither the name of the University nor the names of its contributors | ||
17 | .\" may be used to endorse or promote products derived from this software | ||
18 | .\" without specific prior written permission. | ||
19 | .\" | ||
20 | .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | ||
21 | .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
23 | .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | ||
24 | .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | ||
26 | .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | ||
27 | .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | ||
28 | .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | ||
29 | .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | ||
30 | .\" SUCH DAMAGE. | ||
31 | .\" | ||
32 | .\" $OpenBSD: strcpy.3,v 1.12 2003/06/02 20:18:38 millert Exp $ | ||
33 | .\" | ||
34 | .Dd June 29, 1991 | ||
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 | .Fn strncpy | ||
61 | copies not more than | ||
62 | .Fa len | ||
63 | characters into | ||
64 | .Fa dst , | ||
65 | appending | ||
66 | .Ql \e0 | ||
67 | characters if | ||
68 | .Fa src | ||
69 | is less than | ||
70 | .Fa len | ||
71 | characters long, and | ||
72 | .Em not | ||
73 | terminating | ||
74 | .Fa dst | ||
75 | if the length of | ||
76 | .Fa src | ||
77 | is greater than or equal to | ||
78 | .Fa len . | ||
79 | .Sh RETURN VALUES | ||
80 | The | ||
81 | .Fn strcpy | ||
82 | and | ||
83 | .Fn strncpy | ||
84 | functions return | ||
85 | .Fa dst . | ||
86 | .Sh EXAMPLES | ||
87 | The following sets | ||
88 | .Va chararray | ||
89 | to | ||
90 | .Dq abc\e0\e0\e0 : | ||
91 | .Bd -literal -offset indent | ||
92 | (void)strncpy(chararray, "abc", 6); | ||
93 | .Ed | ||
94 | .Pp | ||
95 | The following sets | ||
96 | .Va chararray | ||
97 | to | ||
98 | .Dq abcdef | ||
99 | and does | ||
100 | .Em not | ||
101 | null terminate | ||
102 | .Va chararray | ||
103 | because the source string is >= the length parameter. | ||
104 | .Fn strncpy | ||
105 | .Em only | ||
106 | null terminates the destination string when the length of the source | ||
107 | string is less than the length parameter. | ||
108 | .Bd -literal -offset indent | ||
109 | (void)strncpy(chararray, "abcdefgh", 6); | ||
110 | .Ed | ||
111 | .Pp | ||
112 | The following copies as many characters from | ||
113 | .Va input | ||
114 | to | ||
115 | .Va buf | ||
116 | as will fit and null terminates the result. | ||
117 | Because | ||
118 | .Fn strncpy | ||
119 | does | ||
120 | .Em not | ||
121 | guarantee to null terminate the string itself, we must do this by hand. | ||
122 | .Bd -literal -offset indent | ||
123 | char buf[BUFSIZ]; | ||
124 | |||
125 | (void)strncpy(buf, input, sizeof(buf) - 1); | ||
126 | buf[sizeof(buf) - 1] = '\e0'; | ||
127 | .Ed | ||
128 | .Pp | ||
129 | Note that | ||
130 | .Xr strlcpy 3 | ||
131 | is a better choice for this kind of operation. | ||
132 | The equivalent using | ||
133 | .Xr strlcpy 3 | ||
134 | is simply: | ||
135 | .Bd -literal -offset indent | ||
136 | (void)strlcpy(buf, input, sizeof(buf)); | ||
137 | .Ed | ||
138 | .Sh SEE ALSO | ||
139 | .Xr bcopy 3 , | ||
140 | .Xr memccpy 3 , | ||
141 | .Xr memcpy 3 , | ||
142 | .Xr memmove 3 , | ||
143 | .Xr strlcpy 3 | ||
144 | .Sh STANDARDS | ||
145 | The | ||
146 | .Fn strcpy | ||
147 | and | ||
148 | .Fn strncpy | ||
149 | functions conform to | ||
150 | .St -ansiC . | ||