]> git.ipfire.org Git - thirdparty/man-pages.git/commitdiff
strncpy.3: Deprecate strncpy(3) in favor of stpncpy(3)
authorAlejandro Colomar <alx@kernel.org>
Sun, 4 Dec 2022 23:05:15 +0000 (00:05 +0100)
committerAlejandro Colomar <alx@kernel.org>
Sun, 4 Dec 2022 23:05:15 +0000 (00:05 +0100)
It is equivalent, but reports truncation.

Signed-off-by: Alejandro Colomar <alx@kernel.org>
man3/strncpy.3

index 619251b011510abae1853fb98fcf075f6a471f3f..b1fb165c33fd586602717ca24bfcc28bad60520b 100644 (file)
@@ -23,14 +23,17 @@ Standard C library
 .nf
 .B #include <string.h>
 .PP
-.BI "char *strncpy(char " dest "[restrict ." n "], \
-const char " src "[restrict ." n ],
-.BI "              size_t " n );
+.BI "[[deprecated]] char *strncpy(char " dest "[restrict ." n ],
+.BI "                             const char " src "[restrict ." n "], \
+size_t " n );
 .fi
 .SH DESCRIPTION
-.BI Note: " This is probably not the function you want to use."
+.BI Note: " This is not the function you want to use."
 For safe string copying, see
 .BR strlcpy (3bsd).
+For copying a string into a fixed-length buffer with zeroing of the rest,
+see
+.BR stpncpy (3).
 .PP
 The
 .BR strncpy ()
@@ -75,7 +78,11 @@ while ensuring that unused bytes in the destination buffer are zeroed out
 (perhaps to prevent information leaks if the buffer is to be
 written to media or transmitted to another process via an
 interprocess communication technique).
-But see CAVEATS below.
+But
+.BR stpncpy (3)
+is better for this purpose,
+since it detects truncation.
+See CAVEATS below.
 .SH RETURN VALUE
 The
 .BR strncpy ()
@@ -112,7 +119,9 @@ It's probably better to explicitly call
 .BR bzero (3)
 and
 .BR memccpy (3),
-since that allows detecting truncation.
+or
+.BR stpncpy (3)
+since they allow detecting truncation.
 .SH SEE ALSO
 .BR bzero (3),
 .BR memccpy (3),