为什么strcpy_s在我的系统中不存在

Why does strcpy_s not exist anywhere on my system?

本文关键字:系统 不存在 我的 strcpy 为什么      更新时间:2023-10-16

我在Debian 8系统上使用clang。我有标准的C++头。然而,没有定义strcpy_s的报头。为什么会这样?

# grep -iRHI 'strcpy_s' /usr 2>/dev/null
/usr/include/x86_64-linux-gnu/bits/string2.h:                ? __strcpy_small (dest, __strcpy_args (src),             
/usr/include/x86_64-linux-gnu/bits/string2.h:__STRING_INLINE char *__strcpy_small (char *, __uint16_t, __uint16_t,
/usr/include/x86_64-linux-gnu/bits/string2.h:__strcpy_small (char *__dest,
/usr/include/x86_64-linux-gnu/bits/string2.h:__STRING_INLINE char *__strcpy_small (char *, __STRING2_COPY_ARR2,
/usr/include/x86_64-linux-gnu/bits/string2.h:__strcpy_small (char *__dest,
/usr/src/broadcom-sta-6.30.223.248/src/include/bcmutils.h:#define bcm_strcpy_s(dst, noOfElements, src)            strcpy((dst), (src))

为什么strcpy_s在我的系统中不存在?

strcpy_s不是由C++标准库提供的。

然而strcpy_s是由C标准从C11开始指定的。但即使在C11中,strcpy_s也是可选的。所有标准库实现都不提供所有可选功能。因此,答案似乎是:因为你安装的C标准库中没有一个声明它

如何在系统中获取strcpy_s、strtok_s和所有其他安全字符串函数?

您需要找到一个实现它们的库,或者自己实现它们。

显然,这些不存在是因为它们不存在。我可以通过查找和安装它们来查找和安装;或者,通过自己对它们进行编码。显然,这是一个有用的解决方案,所以让投票开始吧。