您的位置:首页 > 运维架构 > Linux

linux系统调用之stat 计算一个文件大小

2014-01-09 21:40 387 查看
#include<stdio.h>
#include<stdlib.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>

int flen(char *fname)
{
struct stat f;

if(lstat(fname,&f) < 0) {
perror("lstat()");
exit(1);
}
return (f.st_size);

}
int main(int argc,char *argv[])
{
if(argc < 2) {
fprintf(stderr,"Usage...\n");
exit(1);
}

printf("%d\n",flen(argv[1]));
exit(0);
}
本文出自 “张沐槿” 博客,请务必保留此出处http://zhangmujin.blog.51cto.com/4471254/1350242
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: