简体   繁体   English

dev_t和ino_t是否必须是整数类型?

[英]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_tuintmax_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.

相关问题 如何打印像ino_t这样的未知大小的类型? - How to print types of unknown size like ino_t? 为什么sys / stat.h不使用-std = c1x定义ino_t? - Why won't sys/stat.h define ino_t with -std=c1x? 从macOS上的dev_t获取设备文件系统路径 - Get device filesystem path from dev_t on macOS 如何在dev_t和主要/次要设备号之间转换? - How to convert between a dev_t and major/minor device numbers? 在 Posix 中如何使用 dev_t 类型? - In Posix how is type dev_t getting used? 警告:格式&#39;%s&#39;需要类型为&#39;char *&#39;的参数,但是参数2的类型为&#39;__dev_t&#39;[-Wformat =] - warning: format ‘%s’ expects argument of type ‘char *’, but argument 2 has type ‘__dev_t’ [-Wformat=] 为什么不要求所有最小宽度整数类型(最多64位)都存在? - Why isn't the existence of all minimum-width integer types (up to 64 bits) required? uint8_t数组中整数(或其他)类型的字节对齐 - Byte Alignment for integer (or other) types in a uint8_t array int8_t和char:在指针之间转换为具有不同符号的整数类型 - 但它没有 - int8_t and char: converts between pointers to integer types with different sign - but it doesn't 为什么C提供的整数类型对于基本上任何项目都不够好? - Why aren't the C-supplied integer types good enough for basically any project?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM