Do dev_t and ino_t need to be integer types?

The glibc documentation remains intact (no narrower than unsigned int), but I cannot find a reference to the standard which says that they must be intact (see also time_t).

So, at the end the question arises: 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.

+5
source share
2 answers

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

dev_t must be an integer type.

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

Since intmax_t and uintmax_t must be integers of the greatest width, your code is safe. To make sure st_dev is negative, you can write it as:

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

Otherwise, your code will be safe.

+6
source

From the current POSIX specifications :

dev_t must be an integer type.

[...]

ino_t must be defined as unsigned integer types

+2
source

Source: https://habr.com/ru/post/1274595/


All Articles