linux系統調用之stat 計算一個文件大小

#include
#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);
}
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章