c - 定义 "needs to be at least XX bytes long"是否包含空终止符,还是应该使用 XX+1?

标签 c manpage

我想知道,当您看到一个 API 说字符缓冲区应该至少 XXX 字节长时,它是否包括空终止字符? 并不是说我介意节省一个字节,但是这件事让我很烦……(这里没有双重含义!)

来自 if_indextoname 的 Mac OS X 联机帮助页:

The if_indextoname() function maps the interface index specified in ifindex to it corresponding name, which is copied into the buffer pointed to by ifname, which must be of at least IFNAMSIZ bytes.

最佳答案

字符缓冲区是一个以NUL 结尾的字符串。因此缓冲区需要足够大以容纳字符串,包括 NUL

关于c - 定义 "needs to be at least XX bytes long"是否包含空终止符,还是应该使用 XX+1?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33531185/

相关文章:

c - C中 float 的更快输入输出

c - 纯C : trim all characters in a string after a word occurs

bash - 在 bash 中快速搜索命令选项

c - 如何在 ubuntu 服务器中为 STREAMS 安装 IOCTL 手册页?

signals - 带有 posix 信号列表的手册页?

c - 内部静态数组(K&R month_name() 函数)

c - 为什么我的动态字符串指针数组会导致段错误?

c - 当订阅者未连接时,MQTT 以 Qos 2 发布

linux - 命令和系统调用名称后的数字在 *nix 中是什么意思?

manpage - 编写手册页的最佳方式?