https://zine.dev/2023/07/strlcpy-and-strlcat-added-to-glibc/
https://sourceware.org/git/?p=glibc.git;a=commit;h=454a20c8756c9c1d55419153255fc7692b3d2199
https://linux.die.net/man/3/strlcpy
https://lwn.net/Articles/612244/
从这里看,这个strlcpy、strlcat的引入glibc的过程还是很慢长。为什么一直没有放进来?其实还是很方便使用。
Kernel里的版本;
/*** strlcpy - Copy a C-string into a sized buffer* @dest: Where to copy the string to* @src: Where to copy the string from* @size: size of destination buffer** Compatible with ``*BSD``: the result is always a valid* NUL-terminated string that fits in the buffer (unless,* of course, the buffer size is zero). It does not pad* out the result like strncpy() does.*/
size_t strlcpy(char *dest, const char *src, size_t size)
{size_t ret = strlen(src);if (size) {size_t len = (ret >= size) ? size - 1 : ret;memcpy(dest, src, len);dest[len] = '\0';}return ret;
}