diff options
author | Alejandro Colomar <alx@kernel.org> | 2023-12-15 14:52:58 +0100 |
---|---|---|
committer | Alejandro Colomar <alx@kernel.org> | 2023-12-17 13:35:22 +0100 |
commit | e0e96d263039a5cf0e085a361eccf426db2f9d21 (patch) | |
tree | 34ce4495e2d8f5e2587992c432ae21db06d2f08f | |
parent | 6bf3937fcfd57029d4ac953937d5c3a5f21de5bb (diff) |
string_copying.7: stpecpy(), strtcpy(): Set errno on failure
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r-- | man7/string_copying.7 | 40 |
1 files changed, 36 insertions, 4 deletions
diff --git a/man7/string_copying.7 b/man7/string_copying.7 index 02e379a7d..cc8904493 100644 --- a/man7/string_copying.7 +++ b/man7/string_copying.7 @@ -505,6 +505,29 @@ The .I dst pointer, which is useless. +.\" ----- ERRORS ------------------------------------------------------/ +.SH ERRORS +Most of these functions don't set +.IR errno . +.TP +.BR stpecpy () +.RS +.TP +.B E2BIG +The string has been truncated. +.RE +.TP +.BR strtcpy () +.RS +.TP +.B ENOBUFS +.I dsize +was +.BR 0 . +.TP +.B E2BIG +The string has been truncated. +.RE .\" ----- NOTES :: strscpy(9) -----------------------------------------/ .SH NOTES The Linux kernel has an internal function for copying strings, @@ -513,7 +536,9 @@ which is identical to .BR strtcpy (), except that it returns .B \-E2BIG -instead of \-1. +instead of \-1 +and it doesn't set +.IR errno . .\" ----- CAVEATS :: --------------------------------------------------/ .SH CAVEATS Don't mix chain calls to truncating and non-truncating functions. @@ -704,6 +729,7 @@ char * .IR stpecpy "(char *dst, char end[0], const char *restrict src)" { bool trunc; + char *p; size_t dsize, dlen, slen; \& if (dst == end) @@ -716,7 +742,10 @@ char * trunc = (slen == dsize); dlen = slen \- trunc; \& - return stpcpy(mempcpy(dst, src, dlen), "") + trunc; + p = stpcpy(mempcpy(dst, src, dlen), ""); + if (trunc) + errno = E2BIG; + return p + trunc; } \& .\" ----- EXAMPLES :: Implementations :: strtcpy() --------------------/ @@ -726,15 +755,18 @@ ssize_t bool trunc; size_t dlen, slen; \& - if (dsize == 0) + if (dsize == 0) { + errno = ENOBUFS; return \-1; + } \& slen = strnlen(src, dsize); trunc = (slen == dsize); dlen = slen \- trunc; \& stpcpy(mempcpy(dst, src, dlen), ""); - + if (trunc) + errno = E2BIG; return trunc ? \-1 : slen; } .\" ----- SEE ALSO :: -------------------------------------------------/ |