[英]Are dev_t and ino_t required to be integer types?
The documentation for glibc stays they are integer types (no narrower than unsigned int), but I'm not finding a standards reference that says they have to be an integer type (see also time_t). glibc的文档保持它们是整数类型(不比unsigned int窄),但我找不到标准引用,它说它们必须是整数类型(另请参见time_t)。
So in the end, the question becomes: Is 所以最后,问题变成:是
#include <stdio.h>
#include <stdint.h>
struct stat st;
if (stat("somefile", &st) == 0) {
printf("%ju %ju\n", (uintmax_t)st.st_dev, (uintmax_t)st.st_ino);
}
portable. 便携。
POSIX standard requires dev_t
to be an integer type and ino_t
to be an unsigned integer. POSIX标准要求dev_t
为整数类型,而ino_t
为无符号整数。
dev_t shall be an integer type. dev_t应为整数类型。
fsblkcnt_t, fsfilcnt_t, and ino_t shall be defined as unsigned integer types. fsblkcnt_t,fsfilcnt_t和ino_t应定义为无符号整数类型。
Since intmax_t
and uintmax_t
are supposed to be the "greatest width" integers, your code is safe. 由于intmax_t
和uintmax_t
应该是“最大宽度”整数,因此您的代码是安全的。 Just to be sure in case st_dev
happens to be negative, you could write it as: 为了确保st_dev
恰好是负数,你可以把它写成:
printf("%jd %ju\n", (intmax_t)st.st_dev, (uintmax_t)st.st_ino);
Otherwise, your code is safe. 否则,您的代码是安全的。
From the current POSIX specifications : 从目前的POSIX规格 :
dev_t shall be an integer type. dev_t应为整数类型。
[...] [...]
ino_t shall be defined as unsigned integer types ino_t应定义为无符号整数类型
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.