当前位置:首页 > 编程笔记 > 正文
已解决

glibc: strlcpy

来自网友在路上 153853提问 提问时间:2023-09-22 22:12:25阅读次数: 53

最佳答案 问答题库538位专家为你答疑解惑

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;
}
查看全文

99%的人还看了

猜你感兴趣

版权申明

本文"glibc: strlcpy":http://eshow365.cn/6-11686-0.html 内容来自互联网,请自行判断内容的正确性。如有侵权请联系我们,立即删除!