From 91db3b69136f1404a207dcc96f733db8d03677f0 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Fri, 15 Dec 2023 15:18:15 +0100 Subject: string_copying.7: stpecpy(): Return NULL on truncation This makes it simpler to test the return value, and since it sets errno to find out the reason, we don't need a complex return value. Now that (dst == end) shouldn't happen, use ENOBUFS to report that error. Signed-off-by: Alejandro Colomar --- man7/string_copying.7 | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/man7/string_copying.7 b/man7/string_copying.7 index cc8904493..451389220 100644 --- a/man7/string_copying.7 +++ b/man7/string_copying.7 @@ -469,9 +469,12 @@ A pointer to the terminating null character in the destination string. .TP .BR stpecpy () A pointer to the terminating null character in the destination string, -except when truncation occurs; -if truncation occurs, -it returns a pointer to the end of the destination buffer. +on success. +On error, +NULL is returned, +and +.I errno +is set to indicate the error. .TP .BR mempcpy (3) .TQ @@ -480,13 +483,13 @@ A pointer to one after the last character in the destination character sequence. .TP .BR strtcpy () -The length of the string. -When truncation occurs, it returns \-1. -When -.I dsize -is -.BR 0 , -it also returns \-1. +The length of the string, +on success. +On error, +\-1 is returned, +and +.I errno +is set to indicate the error. .TP .BR strlcpy (3bsd) .TQ @@ -511,12 +514,7 @@ Most of these functions don't set .IR errno . .TP .BR stpecpy () -.RS -.TP -.B E2BIG -The string has been truncated. -.RE -.TP +.TQ .BR strtcpy () .RS .TP @@ -732,8 +730,10 @@ char * char *p; size_t dsize, dlen, slen; \& - if (dst == end) - return end; + if (dst == end) { + errno = ENOBUFS; + return NULL; + } if (dst == NULL) return NULL; \& @@ -745,7 +745,7 @@ char * p = stpcpy(mempcpy(dst, src, dlen), ""); if (trunc) errno = E2BIG; - return p + trunc; + return trunc ? NULL : p; } \& .\" ----- EXAMPLES :: Implementations :: strtcpy() --------------------/ -- cgit v1.2.3