dev_t 和 ino_t 是否必须是整数类型? [英] Are dev_t and ino_t required to be integer types?

查看:64
本文介绍了dev_t 和 ino_t 是否必须是整数类型?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

glibc 的文档仍然是整数类型(不比 unsigned int 窄),但我没有找到说明它们必须是整数类型的标准参考(另见 time_t).

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).

所以最后,问题变成了:是

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);
}

便携.

推荐答案

POSIX 标准要求 dev_t 为整数类型,ino_t 为无符号整数.

POSIX standard requires dev_t to be an integer type and ino_t to be an unsigned integer.

dev_t 应为整数类型.

dev_t shall be an integer type.

fsblkcnt_t、fsfilcnt_t 和 ino_t 应定义为无符号整数类型.

fsblkcnt_t, fsfilcnt_t, and ino_t shall be defined as unsigned integer types.

由于 intmax_tuintmax_t 应该是最大宽度"整数,因此您的代码是安全的.以防万一 st_dev 碰巧为负,您可以将其写为:

Since intmax_t and uintmax_t are supposed to be the "greatest width" integers, your code is safe. Just to be sure in case st_dev happens to be negative, you could write it as:

    printf("%jd %ju\n", (intmax_t)st.st_dev, (uintmax_t)st.st_ino);

否则,您的代码是安全的.

Otherwise, your code is safe.

这篇关于dev_t 和 ino_t 是否必须是整数类型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆