c - 打印文件/目录的信息(inode)

标签 c inode fstat

我想打印一个目录的一些信息。我的代码是:

#include <stdio.h>
#include <stdlib.h>
#include <fcntl.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <dirent.h>
#include <time.h>
#include <string.h>

int main (int argc, char *argv[])
{
    struct stat fileStat;
    int fd=0;
    if ( ( fd = open (argv[1] , O_RDONLY) ) == -1){
        perror ( "open " );
        exit (1) ;
    }

    if(fstat(fd, &fileStat)<0) return 1;

    printf("Information for %s\n",argv[1]);
    printf("---------------------------\n");
    --->printf("File Size: \t\t%d bytes\n",fileStat.st_size);
    printf("Number of Links: \t%d\n",fileStat.st_nlink);
    --->printf("File inode: \t\t%d\n",fileStat.st_ino);

    return 0;
}

我收到一些警告:

inode_test.c:24:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__off_t’ [-Wformat]

inode_test.c:26:5: warning: format ‘%d’ expects argument of type ‘int’, but argument 2 has type ‘__ino_t’ [-Wformat]

箭头表示每个警告所在的行。你能帮我吗?提前致谢!

最佳答案

我找到了答案。这些格式是 long unsigned int。所以它是 %lu。无论如何感谢@haccks 的帮助!

关于c - 打印文件/目录的信息(inode),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22575727/

相关文章:

C函数修改inode?

c - 没有 df -i 的 inode 使用

c 使用 fstat 问题比较文件大小

freebsd - fstat - freebsd 系统上的文件描述符总数?

c - 将动态分配结构的元素置零或清除的有效方法

创建二维结构

c - 有没有办法在 C 中为 i_block 创建迭代器风格的函数?

c - C中lstat fstat和stat的区别

python - 我可以阻止 C++ dll 在 Python Ctypes 中加载吗?

c - GL_POINTS 和 GL_POINT 有什么区别