如何打印" st_blksize" ubuntu中的数据?

时间:2015-01-18 05:07:23

标签: c ubuntu-14.04 system-calls stat

#include <stdio.h>
#include <sys/stat.h>
#include <stdlib.h>
#include <time.h>

int main(int argc, char*argv[])
{
    struct stat file;
    int n;
    if (argc != 2)
    {
        printf("Usage: ./a.out <filename>\n");
        exit(-1);
    }

    if ((n = stat(argv[1], &file)) == -1)
    {
        perror(argv[1]);
        exit(-1);
    }

    printf("Block size : %d\n", file.st_blksize);
}

最后一行给出错误

格式'%d'需要类型为'int'的参数,但参数2的类型为'__blksize_t'[-Wformat =]

如何打印出“st_blksize”数据?

1 个答案:

答案 0 :(得分:0)

实际上,st_blksizeunsigned long typedefed数据类型,因此使用

printf("Block size : %ld\n", file_st.blksize);