From 062d999e00c36692605b1ac394ffcfbb340e1771 Mon Sep 17 00:00:00 2001 From: millert <> Date: Thu, 19 Dec 2013 20:52:37 +0000 Subject: Split out strncpy and strncat from strcpy and strcat manuals. Requested by deraadt@ --- src/lib/libc/string/strcpy.3 | 98 +++++--------------------------------------- 1 file changed, 10 insertions(+), 88 deletions(-) (limited to 'src/lib/libc/string/strcpy.3') 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 @@ -.\" $OpenBSD: strcpy.3,v 1.19 2013/09/25 21:49:31 millert Exp $ +.\" $OpenBSD: strcpy.3,v 1.20 2013/12/19 20:52:37 millert Exp $ .\" .\" Copyright (c) 1990, 1991 The Regents of the University of California. .\" All rights reserved. @@ -31,52 +31,31 @@ .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF .\" SUCH DAMAGE. .\" -.Dd $Mdocdate: September 25 2013 $ +.Dd $Mdocdate: December 19 2013 $ .Dt STRCPY 3 .Os .Sh NAME -.Nm strcpy , -.Nm strncpy -.Nd copy strings +.Nm strcpy +.Nd copy a string .Sh SYNOPSIS .In string.h .Ft char * .Fn strcpy "char *dst" "const char *src" -.Ft char * -.Fn strncpy "char *dst" "const char *src" "size_t len" .Sh DESCRIPTION The .Fn strcpy -and -.Fn strncpy -functions copy the string +function copies the string .Fa src to .Fa dst (including the terminating .Ql \e0 character). -.Pp -The -.Fn strncpy -function copies not more than -.Fa len -characters into -.Fa dst , -appending -.Ql \e0 -characters if -.Fa src -is less than -.Fa len -characters long, and -.Em not -terminating +The string .Fa dst -if the length of +must be at least as large as .Fa src -is greater than or equal to -.Fa len . +to hold the result. .Pp If the .Fa src @@ -86,63 +65,8 @@ strings overlap, the behavior is undefined. .Sh RETURN VALUES The .Fn strcpy -and -.Fn strncpy -functions return +function returns .Fa dst . -.Sh EXAMPLES -The following sets -.Va chararray -to -.Dq abc\e0\e0\e0 : -.Bd -literal -offset indent -(void)strncpy(chararray, "abc", 6); -.Ed -.Pp -The following sets -.Va chararray -to -.Dq abcdef -and does -.Em not -NUL terminate -.Va chararray -because the length of the source string is greater than or equal to the -length parameter. -.Fn strncpy -.Em only -NUL terminates the destination string when the length of the source -string is less than the length parameter. -.Bd -literal -offset indent -(void)strncpy(chararray, "abcdefgh", 6); -.Ed -.Pp -The following copies as many characters from -.Va input -to -.Va buf -as will fit and NUL terminates the result. -Because -.Fn strncpy -does -.Em not -guarantee to NUL terminate the string itself, it must be done by hand. -.Bd -literal -offset indent -char buf[BUFSIZ]; - -(void)strncpy(buf, input, sizeof(buf) - 1); -buf[sizeof(buf) - 1] = '\e0'; -.Ed -.Pp -Note that -.Xr strlcpy 3 -is a better choice for this kind of operation. -The equivalent using -.Xr strlcpy 3 -is simply: -.Bd -literal -offset indent -(void)strlcpy(buf, input, sizeof(buf)); -.Ed .Sh SEE ALSO .Xr bcopy 3 , .Xr memccpy 3 , @@ -150,6 +74,7 @@ is simply: .Xr memmove 3 , .Xr strcat 3 , .Xr strlcpy 3 , +.Xr strncpy 3 , .Xr wcscpy 3 , .Xr wcslcpy 3 .Sh STANDARDS @@ -164,7 +89,4 @@ The .Fn strcpy function first appeared in the Programmer's Workbench (PWB/UNIX) and was ported to -.At v7 ; -.Fn strncpy -first appeared in .At v7 . -- cgit v1.2.3-55-g6feb