summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-12-15 15:18:15 +0100
committerAlejandro Colomar <alx@kernel.org>2023-12-17 13:35:22 +0100
commit91db3b69136f1404a207dcc96f733db8d03677f0 (patch)
tree7dcb512ab79c37b6ddbe41ea76f32df8c6995d99
parente0e96d263039a5cf0e085a361eccf426db2f9d21 (diff)
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 <alx@kernel.org>
-rw-r--r--man7/string_copying.738
1 files 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() --------------------/