> On 22 Dec 2022, at 21:42, Alejandro Colomar via Libc-alpha wrote: > > Glibc didn't provide any function that copies a string with truncation. > > It only provided strncpy(3) and stpncpy(3), which copy from a string > into a null-padded character sequence at the destination fixed-width > buffer, with truncation. > > Those old functions, which don't produce a string, have been misused for > a long time as a poor-man's replacement for strlcpy(3), but doing that > is a source of bugs, since it's hard to calculate the right size that > should be passed to the function, and it's also necessary to explicitly > terminate the buffer with a null byte. Detecting truncation is yet > another problem. > > stpecpy(3), described in the new string_copying(7) manual page, is > similar to OpenBSD's strlcpy(3)/strlcat(3), but: > > - It's simpler to implement. > - It's faster. > - It's simpler to detect truncation. Given strlcpy and strlcat are in POSIX next and therefore bar some extraordinary event will be in glibc, I think we should probably wait until those two land, then see if there's still an appetite for stpecpy in glibc.