@@ -904,10 +904,6 @@ non-null bytes followed by zero or more null bytes. It needs to set
all @var{size} bytes of the destination, even when @var{size} is much
greater than the length of @var{from}. As noted below, this function
is generally a poor choice for processing text.
-
-See @code{strlcpy} below for an alternative which null-terminates the
-destination string as long as the destination buffer does not have
-length zero.
@end deftypefun
@comment wchar.h
@@ -1111,15 +1107,13 @@ This function is similar to @code{strcpy}, but copies at most
@var{size} bytes from the string @var{from} into the destination
array @var{to}, including a terminating null byte.
-If @var{size} is zero, nothing is written to @var{to}.
-
If @var{size} is greater than the length of the string @var{from},
this function copies all of the string @var{from} to the destination
array @var{to}, including the terminating null byte. Like other
string functions such as @code{strcpy}, but unlike @code{strncpy}, any
remaining bytes in the destination array remain unchanged.
-If @var{size} is less than or equal to the the length of the string
+If @var{size} is nonzero and less than or equal to the the length of the string
@var{from}, this function copies only the first @samp{@var{size} - 1}
bytes to the destination array @var{to}, and writes a terminating null
byte to the last byte of the array.
@@ -1128,14 +1122,15 @@ The return value @var{result} of @code{strlcpy} is the length of the
string @var{from}. This means that @samp{@var{result} >= @var{size}} is
true whenever truncation occurs.
-The behavior of @code{strlcpy} is undefined if the strings overlap.
+The behavior of @code{strlcpy} is undefined if @var{size} is zero, or
+if the source and destination strings overlap.
As noted below, this function is generally a poor choice for processing
-text. Using @code{strlcpy} instead of @code{strcpy} is a way to avoid
-bugs caused by writing past the end of the allocated space for @var{to}.
-Unlike @code{strncpy}, @code{strlcpy} ensures that the destination
-string is always null-terminated (unless the array size is zero), and it
-does not fill the remaining part of the array with null bytes.
+text. Unlike @code{strncpy}, @code{strlcpy} requires @var{size} to be
+nonzero and the source string to be null-terminated, computes the
+source string's length, ensures that the destination is
+null-terminated, and does not fill the remaining part of the destination
+with null bytes.
This function is derived from BSD.
@end deftypefun
@@ -1145,38 +1140,33 @@ This function is derived from BSD.
@deftypefun size_t strlcat (char *restrict @var{to}, const char *restrict @var{from}, size_t @var{size})
@safety{@prelim{}@mtsafe{}@assafe{}@acsafe{}}
This function appends the string @var{from} to the
-string @var{to}, limiting the total length of the result string at
+string @var{to}, limiting the total size of the result string at
@var{to} (including the null terminator) to @var{size}.
-If array @var{to} contains a null terminator among the first @var{size}
-bytes, this function copies as much as possible of the string @var{from}
-into the array at @var{to} of @var{size} bytes, starting at the
-terminating null byte of the original string @var{to}. In effect, this
-appends the string @var{from} to the string @var{to}. In this case, the
-resulting array at @var{to} will contain a null terminator, but the
-result string can be truncated (not all bytes in @var{from} are copied).
-
-If the array @var{to} does not contain a null terminator among the first
-@var{size} bytes, the array @var{to} is not modified, and it will not
-contain a null terminator after this function returns. This also covers
-the case when @var{size} is zero.
+This function copies as much as possible of the string @var{from} into
+the array at @var{to} of @var{size} bytes, starting at the terminating
+null byte of the original string @var{to}. In effect, this appends
+the string @var{from} to the string @var{to}. Although the resulting
+string will contain a null terminator, it can be truncated (not all
+bytes in @var{from} are copied).
-This function returns the length of the untruncated string: the length
-of @var{from} plus the length of the string @var{to} (if there is a null
-terminator within the first @var{size} bytes of the array @var{to}), or
-the length of @var{from} plus @var{size} (if the array @var{to} of
-@var{size} bytes does not contain a null terminator).
+This function returns the sum of the original length of @var{to} and
+the length of @var{from}. This means that truncation occurs unless
+the returned value is less than @var{size}.
-The behavior of @code{strlcat} is undefined if the strings overlap.
+The behavior is undefined if @var{to} does not contain a null byte in
+its first @var{size} bytes, or if the source and resulting destination
+strings overlap.
As noted below, this function is generally a poor choice for processing
text. Also, this function has significant performance issues.
-@xref{Concatenating Strings}. Using @code{strlcat} instead of
-@code{strcat} is a way to avoid bugs caused by writing past the end of
-the allocated space for @var{to}. Unlike @code{strncat}, @var{size}
-specifies the maximum total length of the result string (including its
+@xref{Concatenating Strings}. Unlike @code{strncat}, @var{size}
+specifies the maximum total size of the result string (including its
null terminator), not the number of bytes copied from the source string
@var{from}.
+Also, unlike @code{strncat} this function requires the source and
+destination to be null-terminated, computes the source string's
+length, and keeps the destination null-terminated.
This function is derived from BSD.
@end deftypefun