glibc: strlcpy

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/

From this point of view, the process of introducing glibc into strlcpy and strlcat is still very slow and long. Why hasn't it been put in yet? In fact, it is still very convenient to use.

The version in 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;
}

Guess you like

Origin blog.csdn.net/qq_36428903/article/details/132920690