linux下使用fstat来计算文件的大小

#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>

int main()
{
    struct stat buf;
    int fd = open("/etc/passwd", O_RDONLY);
    fstat(fd, &buf);
    printf("/etc/passwd file size is [%d]\n", buf.st_size);

    return 0;
}

posted @ 2016-02-19 16:54  聚沙成塔  阅读(556)  评论(0编辑  收藏  举报