summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAlejandro Colomar <alx@kernel.org>2023-12-15 15:25:36 +0100
committerAlejandro Colomar <alx@kernel.org>2023-12-17 13:35:23 +0100
commit39b26ae2036ff051f8109ad250ab507fd01f91f0 (patch)
tree2843edd6c71f3d646e3df66bdd4f7d5bed102e08
parent91db3b69136f1404a207dcc96f733db8d03677f0 (diff)
string_copying.7: stpecpy(): Reimplement as a wrapper of strtcpy()
Signed-off-by: Alejandro Colomar <alx@kernel.org>
-rw-r--r--man7/string_copying.719
1 files changed, 3 insertions, 16 deletions
diff --git a/man7/string_copying.7 b/man7/string_copying.7
index 451389220..daf9723e8 100644
--- a/man7/string_copying.7
+++ b/man7/string_copying.7
@@ -726,26 +726,13 @@ Here are reference implementations for functions not provided by libc.
char *
.IR stpecpy "(char *dst, char end[0], const char *restrict src)"
{
- bool trunc;
- char *p;
- size_t dsize, dlen, slen;
+ size_t dlen;
\&
- if (dst == end) {
- errno = ENOBUFS;
- return NULL;
- }
if (dst == NULL)
return NULL;
\&
- dsize = end \- dst;
- slen = strnlen(src, dsize);
- trunc = (slen == dsize);
- dlen = slen \- trunc;
-\&
- p = stpcpy(mempcpy(dst, src, dlen), "");
- if (trunc)
- errno = E2BIG;
- return trunc ? NULL : p;
+ dlen = strtcpy(dst, src, end \- dst);
+ return (dlen == \-1) ? NULL : dst + dlen;
}
\&
.\" ----- EXAMPLES :: Implementations :: strtcpy() --------------------/