.\" 2007-06-15, Marc Boyer <marc.boyer@enseeiht.fr> + mtk
.\" Improve discussion of strncpy().
.\"
-.TH STRCPY 3 2012-07-19 "GNU" "Linux Programmer's Manual"
+.TH STRCPY 3 2014-05-21 "GNU" "Linux Programmer's Manual"
.SH NAME
strcpy, strncpy \- copy a string
.SH SYNOPSIS
.SH DESCRIPTION
The
.BR strcpy ()
-function copies the string pointed to by \fIsrc\fP,
+function copies the string pointed to by
+.IR src ,
including the terminating null byte (\(aq\\0\(aq),
-to the buffer pointed to by \fIdest\fP.
+to the buffer pointed to by
+.IR dest .
The strings may not overlap, and the destination string
-\fIdest\fP must be large enough to receive the copy.
+.I dest
+must be large enough to receive the copy.
.IR "Beware of buffer overruns!"
(See BUGS.)
.PP
The
.BR strncpy ()
function is similar, except that at most
-\fIn\fP bytes of \fIsrc\fP are copied.
+.I n
+bytes of
+.I src
+are copied.
.BR Warning :
If there is no null byte
-among the first \fIn\fP bytes of \fIsrc\fP,
-the string placed in \fIdest\fP will not be null-terminated.
+among the first
+.I n
+bytes of
+.IR src ,
+the string placed in
+.I dest
+will not be null-terminated.
.PP
If the length of
.I src
and
.BR strncpy ()
functions return a pointer to
-the destination string \fIdest\fP.
+the destination string
+.IR dest .
+.SH ATTRIBUTES
+.SS Multithreading (see pthreads(7))
+The
+.BR strcpy ()
+and
+.BR strncpy ()
+functions are thread-safe.
.SH CONFORMING TO
SVr4, 4.3BSD, C89, C99.
.SH NOTES
.BR strncpy ()
to be inefficient and error prone.
If the programmer knows (i.e., includes code to test!)
-that the size of \fIdest\fP is greater than
-the length of \fIsrc\fP, then
+that the size of
+.I dest
+is greater than
+the length of
+.IR src ,
+then
.BR strcpy ()
can be used.
written to media or transmitted to another process via an
interprocess communication technique).
-If there is no terminating null byte in the first \fIn\fP
-bytes of \fIsrc\fP,
+If there is no terminating null byte in the first
+.I n
+bytes of
+.IR src ,
.BR strncpy ()
-produces an unterminated string in \fIdest\fP.
-You can force termination using something like the following:
+produces an unterminated string in
+.IR dest .
+If
+.I buf
+has length
+.IR buflen ,
+you can force termination using something like the following:
.in +4n
.nf
-strncpy(buf, str, n);
-if (n > 0)
- buf[n \- 1]= \(aq\\0\(aq;
+strncpy(buf, str, buflen \- 1);
+if (buflen > 0)
+ buf[buflen \- 1]= \(aq\\0\(aq;
.fi
.in
.PP
-(Of course, the above technique ignores the fact that
-information contained in
+(Of course, the above technique ignores the fact that, if
.I src
-is lost in the copying to
+contains more than
+.I "buflen\ \-\ 1"
+bytes, information is lost in the copying to
.IR dest .)
-
+.\"
+.SS strlcpy()
Some systems (the BSDs, Solaris, and others) provide the following function:
size_t strlcpy(char *dest, const char *src, size_t size);
.BR string (3),
.BR wcscpy (3),
.BR wcsncpy (3)
+.SH COLOPHON
+This page is part of release 3.79 of the Linux
+.I man-pages
+project.
+A description of the project,
+information about reporting bugs,
+and the latest version of this page,
+can be found at
+\%http://www.kernel.org/doc/man\-pages/.