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.398
1 files changed, 10 insertions, 88 deletions
diff --git a/src/lib/libc/string/strcpy.3 b/src/lib/libc/string/strcpy.3
index 798c7e8d99..849184d1f5 100644
--- a/src/lib/libc/string/strcpy.3
+++ b/src/lib/libc/string/strcpy.3
@@ -1,4 +1,4 @@
1.\" $OpenBSD: strcpy.3,v 1.19 2013/09/25 21:49:31 millert Exp $ 1.\" $OpenBSD: strcpy.3,v 1.20 2013/12/19 20:52:37 millert Exp $
2.\" 2.\"
3.\" Copyright (c) 1990, 1991 The Regents of the University of California. 3.\" Copyright (c) 1990, 1991 The Regents of the University of California.
4.\" All rights reserved. 4.\" All rights reserved.
@@ -31,52 +31,31 @@
31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
32.\" SUCH DAMAGE. 32.\" SUCH DAMAGE.
33.\" 33.\"
34.Dd $Mdocdate: September 25 2013 $ 34.Dd $Mdocdate: December 19 2013 $
35.Dt STRCPY 3 35.Dt STRCPY 3
36.Os 36.Os
37.Sh NAME 37.Sh NAME
38.Nm strcpy , 38.Nm strcpy
39.Nm strncpy 39.Nd copy a string
40.Nd copy strings
41.Sh SYNOPSIS 40.Sh SYNOPSIS
42.In string.h 41.In string.h
43.Ft char * 42.Ft char *
44.Fn strcpy "char *dst" "const char *src" 43.Fn strcpy "char *dst" "const char *src"
45.Ft char *
46.Fn strncpy "char *dst" "const char *src" "size_t len"
47.Sh DESCRIPTION 44.Sh DESCRIPTION
48The 45The
49.Fn strcpy 46.Fn strcpy
50and 47function copies the string
51.Fn strncpy
52functions copy the string
53.Fa src 48.Fa src
54to 49to
55.Fa dst 50.Fa dst
56(including the terminating 51(including the terminating
57.Ql \e0 52.Ql \e0
58character). 53character).
59.Pp 54The string
60The
61.Fn strncpy
62function copies not more than
63.Fa len
64characters into
65.Fa dst ,
66appending
67.Ql \e0
68characters if
69.Fa src
70is less than
71.Fa len
72characters long, and
73.Em not
74terminating
75.Fa dst 55.Fa dst
76if the length of 56must be at least as large as
77.Fa src 57.Fa src
78is greater than or equal to 58to hold the result.
79.Fa len .
80.Pp 59.Pp
81If the 60If the
82.Fa src 61.Fa src
@@ -86,63 +65,8 @@ strings overlap, the behavior is undefined.
86.Sh RETURN VALUES 65.Sh RETURN VALUES
87The 66The
88.Fn strcpy 67.Fn strcpy
89and 68function returns
90.Fn strncpy
91functions return
92.Fa dst . 69.Fa dst .
93.Sh EXAMPLES
94The following sets
95.Va chararray
96to
97.Dq abc\e0\e0\e0 :
98.Bd -literal -offset indent
99(void)strncpy(chararray, "abc", 6);
100.Ed
101.Pp
102The following sets
103.Va chararray
104to
105.Dq abcdef
106and does
107.Em not
108NUL terminate
109.Va chararray
110because the length of the source string is greater than or equal to the
111length parameter.
112.Fn strncpy
113.Em only
114NUL terminates the destination string when the length of the source
115string is less than the length parameter.
116.Bd -literal -offset indent
117(void)strncpy(chararray, "abcdefgh", 6);
118.Ed
119.Pp
120The following copies as many characters from
121.Va input
122to
123.Va buf
124as will fit and NUL terminates the result.
125Because
126.Fn strncpy
127does
128.Em not
129guarantee to NUL terminate the string itself, it must be done by hand.
130.Bd -literal -offset indent
131char buf[BUFSIZ];
132
133(void)strncpy(buf, input, sizeof(buf) - 1);
134buf[sizeof(buf) - 1] = '\e0';
135.Ed
136.Pp
137Note that
138.Xr strlcpy 3
139is a better choice for this kind of operation.
140The equivalent using
141.Xr strlcpy 3
142is simply:
143.Bd -literal -offset indent
144(void)strlcpy(buf, input, sizeof(buf));
145.Ed
146.Sh SEE ALSO 70.Sh SEE ALSO
147.Xr bcopy 3 , 71.Xr bcopy 3 ,
148.Xr memccpy 3 , 72.Xr memccpy 3 ,
@@ -150,6 +74,7 @@ is simply:
150.Xr memmove 3 , 74.Xr memmove 3 ,
151.Xr strcat 3 , 75.Xr strcat 3 ,
152.Xr strlcpy 3 , 76.Xr strlcpy 3 ,
77.Xr strncpy 3 ,
153.Xr wcscpy 3 , 78.Xr wcscpy 3 ,
154.Xr wcslcpy 3 79.Xr wcslcpy 3
155.Sh STANDARDS 80.Sh STANDARDS
@@ -164,7 +89,4 @@ The
164.Fn strcpy 89.Fn strcpy
165function first appeared in the Programmer's Workbench (PWB/UNIX) 90function first appeared in the Programmer's Workbench (PWB/UNIX)
166and was ported to 91and was ported to
167.At v7 ;
168.Fn strncpy
169first appeared in
170.At v7 . 92.At v7 .