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