summaryrefslogtreecommitdiff
path: root/src/lib/libc/string/strcpy.3
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/string/strcpy.3')
-rw-r--r--src/lib/libc/string/strcpy.383
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
54and 50and
55.Fn strncpy 51.Fn strncpy
56functions 52functions copy the string
57copy the string
58.Fa src 53.Fa src
59to 54to
60.Fa dst 55.Fa dst
@@ -62,7 +57,6 @@ to
62.Ql \e0 57.Ql \e0
63character). 58character).
64.Pp 59.Pp
65The
66.Fn strncpy 60.Fn strncpy
67copies not more than 61copies not more than
68.Fa len 62.Fa len
@@ -78,45 +72,80 @@ characters long, and
78.Em not 72.Em not
79terminating 73terminating
80.Fa dst 74.Fa dst
81if 75if the length of
82.Fa src 76.Fa src
83is more than 77is greater than or equal to
84.Fa len 78.Fa len .
85characters long.
86.Sh RETURN VALUES 79.Sh RETURN VALUES
87The 80The
88.Fn strcpy 81.Fn strcpy
89and 82and
90.Fn strncpy 83.Fn strncpy
91functions 84functions return
92return
93.Fa dst . 85.Fa dst .
94.Sh EXAMPLES 86.Sh EXAMPLES
95The following sets 87The following sets
96.Dq Li chararray 88.Va chararray
97to 89to
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
103The following sets 95The following sets
104.Dq Li chararray 96.Va chararray
105to 97to
106.Dq Li abcdef : 98.Dq abcdef
99and does
100.Em not
101NUL terminate
102.Va chararray
103because the length of the source string is greater than or equal to the
104length parameter.
105.Fn strncpy
106.Em only
107NUL terminates the destination string when the length of the source
108string 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
113The following copies as many characters from
114.Va input
115to
116.Va buf
117as will fit and NUL terminates the result.
118Because
119.Fn strncpy
120does
121.Em not
122guarantee to NUL terminate the string itself, it must be done by hand.
123.Bd -literal -offset indent
124char buf[BUFSIZ];
125
126(void)strncpy(buf, input, sizeof(buf) - 1);
127buf[sizeof(buf) - 1] = '\e0';
128.Ed
129.Pp
130Note that
131.Xr strlcpy 3
132is a better choice for this kind of operation.
133The equivalent using
134.Xr strlcpy 3
135is 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
116The 146The
117.Fn strcpy 147.Fn strcpy
118and 148and
119.Fn strncpy 149.Fn strncpy
120functions 150functions conform to
121conform to
122.St -ansiC . 151.St -ansiC .