方法1:
long get_file_size(char *filename)
{
/*
i do not think that is a good idea ,as it calls too much syscall
*/
FILE *fp=NULL;
unsigned int counter=0;
fp=fopen(filename,"r");
if(fp==NULL)
{
//printf("open fail\n");
return 0;
}
fseek(fp,0L,2);
counter=ftell(fp);
rewind(fp);
fclose(fp);
return counter;
}
方法2:
long get_file_size(char *filename)
{
struct stat info;
if((NULL!=filename)&&(0==stat(filename,&info)))
return info.st_size;
else
return 0;/**/
}
/*
阅读(807) | 评论(0) | 转发(1) |