The
stpcpy ();
and
strcpy ();
functions
copy the string
Fa src
to
Fa dst
(including the terminating
`\0'
character.)
The
strncpy ();
function copies at most
Fa len
characters from
Fa src
into
Fa dst .
If
Fa src
is less than
Fa len
characters long,
the remainder of
Fa dst
is filled with
`\0'
characters.
Otherwise,
Fa dst
is
not
terminated.
RETURN VALUES
The
strcpy ();
and
strncpy ();
functions
return
Fa dst .
The
stpcpy ();
function returns a pointer to the terminating
`\0'
character of
Fa dst .
Note that it does
notNUL
terminate
chararray
because the length of the source string is greater than or equal
to the length argument.
The following copies as many characters from
input
to
buf
as will fit and
NUL
terminates the result.
Because
strncpy ();
does
not
guarantee to
NUL
terminate the string itself, this must be done explicitly.
This could be better achieved using
strlcpy(3),
as shown in the following example:
"(void)strlcpy(buf, input, sizeof(buf));"
Note that because
strlcpy(3)
is not defined in any standards, it should
only be used when portability is not a concern.
SECURITY CONSIDERATIONS
The
strcpy ();
function is easily misused in a manner which enables malicious users
to arbitrarily change a running program's functionality through a
buffer overflow attack.
(See
the FSA
and
Sx EXAMPLES . )
The
strcpy ();
and
strncpy ();
functions
conform to
St -isoC .
The
stpcpy ();
function is an MS-DOS and GNUism.
The
stpcpy ();
function
conforms to no standard.
HISTORY
The
stpcpy ();
function first appeared in
Fx 4.4 ,
coming from 1998-vintage Linux.