|
NAME
LIBRARYStandard C Library (libc, -lc) SYNOPSIS
char *
char *
char *
char *
DESCRIPTIONThe
The
If src is less than
len characters long, the remainder of
dst is filled with
‘
Otherwise, dst is not terminated.
\0’ characters.For all of
RETURN VALUESThe EXAMPLESThe following sets chararray to
“ char chararray[6]; (void)strncpy(chararray, "abc", sizeof(chararray)); The following sets chararray to
“ char chararray[6]; (void)strncpy(chararray, "abcdefgh", sizeof(chararray)); Note that it does not NUL 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 char buf[1024]; (void)strncpy(buf, input, sizeof(buf) - 1); buf[sizeof(buf) - 1] = '\0'; This could be better achieved using strlcpy(3), as shown in the following example: (void)strlcpy(buf, input,
sizeof(buf));STANDARDSThe HISTORYThe SECURITY CONSIDERATIONSAll of the functions documented in this manual page are easily misused in a manner which enables malicious users to arbitrarily change a running program's functionality through a buffer overflow attack. It is strongly suggested that the
For some, but not all, fixed-length records, non-terminated
strings may be both valid and desirable. In that specific case, the
|