From a5be2253f456b29cd5a32bffaf9f1ab8c4d20081 Mon Sep 17 00:00:00 2001 From: Alejandro Colomar Date: Mon, 4 Dec 2023 13:58:53 +0100 Subject: string_copying.7: Consistently list strtcpy() after stpecpy() And put it next to strlcpy(3bsd), which is very similar to strtcpy(). Signed-off-by: Alejandro Colomar --- man7/string_copying.7 | 86 +++++++++++++++++++++++++-------------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/man7/string_copying.7 b/man7/string_copying.7 index b8ea98ecc..ad2d889af 100644 --- a/man7/string_copying.7 +++ b/man7/string_copying.7 @@ -7,8 +7,8 @@ .SH NAME stpcpy, strcpy, strcat, -strtcpy, stpecpy, +strtcpy, strlcpy, strlcat, stpncpy, strncpy, @@ -314,10 +314,10 @@ List of functions: .BR strcpy (3), .BR strcat (3) .IP \[bu] -.BR strtcpy () -.IP \[bu] .BR stpecpy () .IP \[bu] +.BR strtcpy () +.IP \[bu] .BR strlcpy (3bsd), .BR strlcat (3bsd) .PD @@ -370,18 +370,6 @@ The return value is useless. .IP .BR stpcpy (3) is a faster alternative to these functions. -.\" ----- DESCRIPTION :: Functions :: strtcpy() -----------------------/ -.TP -.BR strtcpy () -Copy the input string into a destination string. -If the destination buffer isn't large enough to hold the copy, -the resulting string is truncated -(but it is guaranteed to be null-terminated). -It returns the length of the string, -or \-1 if it truncated. -.IP -This function is not provided by any library; -see EXAMPLES for a reference implementation. .\" ----- DESCRIPTION :: Functions :: stpecpy() -----------------------/ .TP .BR stpecpy () @@ -396,6 +384,18 @@ Truncation needs to be detected only once after the last chained call. .IP This function is not provided by any library; see EXAMPLES for a reference implementation. +.\" ----- DESCRIPTION :: Functions :: strtcpy() -----------------------/ +.TP +.BR strtcpy () +Copy the input string into a destination string. +If the destination buffer isn't large enough to hold the copy, +the resulting string is truncated +(but it is guaranteed to be null-terminated). +It returns the length of the string, +or \-1 if it truncated. +.IP +This function is not provided by any library; +see EXAMPLES for a reference implementation. .\" ----- DESCRIPTION :: Functions :: strlcpy(3bsd), strlcat(3bsd) ----/ .TP .BR strlcpy (3bsd) @@ -582,15 +582,6 @@ strcat(buf, "!"); len = strlen(buf); puts(buf); .EE -.\" ----- EXAMPLES :: strtcpy() ---------------------------------------/ -.TP -.BR strtcpy () -.EX -len = strtcpy(buf, "Hello world!", sizeof(buf)); -if (len == \-1) - goto toolong; -puts(buf); -.EE .\" ----- EXAMPLES :: stpecpy() ---------------------------------------/ .TP .BR stpecpy () @@ -607,6 +598,15 @@ if (p == end) { len = p \- buf; puts(buf); .EE +.\" ----- EXAMPLES :: strtcpy() ---------------------------------------/ +.TP +.BR strtcpy () +.EX +len = strtcpy(buf, "Hello world!", sizeof(buf)); +if (len == \-1) + goto toolong; +puts(buf); +.EE .\" ----- EXAMPLES :: strlcpy(3bsd), strlcat(3bsd) --------------------/ .TP .BR strlcpy (3bsd) @@ -706,25 +706,6 @@ Here are reference implementations for functions not provided by libc. .EX /* This code is in the public domain. */ \& -.\" ----- EXAMPLES :: Implementations :: strtcpy() --------------------/ -ssize_t -.IR strtcpy "(char *restrict dst, const char *restrict src, size_t dsize)" -{ - bool trunc; - size_t dlen, slen; -\& - if (dsize == 0) - return \-1; -\& - slen = strnlen(src, dsize); - trunc = (slen == dsize); - dlen = slen \- trunc; -\& - stpcpy(mempcpy(dst, src, dlen), ""); - - return trunc ? \-1 : slen; -} -\& .\" ----- EXAMPLES :: Implementations :: stpecpy() --------------------/ char * .IR stpecpy "(char *dst, char end[0], const char *restrict src)" @@ -744,6 +725,25 @@ char * \& return stpcpy(mempcpy(dst, src, dlen), "") + trunc; } +\& +.\" ----- EXAMPLES :: Implementations :: strtcpy() --------------------/ +ssize_t +.IR strtcpy "(char *restrict dst, const char *restrict src, size_t dsize)" +{ + bool trunc; + size_t dlen, slen; +\& + if (dsize == 0) + return \-1; +\& + slen = strnlen(src, dsize); + trunc = (slen == dsize); + dlen = slen \- trunc; +\& + stpcpy(mempcpy(dst, src, dlen), ""); + + return trunc ? \-1 : slen; +} .\" ----- SEE ALSO :: -------------------------------------------------/ .SH SEE ALSO .BR bzero (3), -- cgit v1.2.3