嵌入式 精确获取文件的大小


int main(int argc, char * argv[])
{
 FILE *fp;
 int buf_size = 0;
 if(argc < 2)
 {
  printf("%s %d The num of param is Two !\n",__FUNCTION__,__LINE__);
  return -1;
 }

 char *jpg_buffer = NULL;

 if(strlen(argv[1]) > 0)
 {
  fp = fopen(argv[1],"rb");
  if(fp == NULL)
  {
   printf("%s %d Open file failed !\n",__FUNCTION__,__LINE__);
  }

   fseek(fp, 0, SEEK_END);   
   buf_size = ftell(fp);
   jpg_buffer = (char *)malloc((buf_size)*sizeof(char *));
   
   fseek(fp, 0, SEEK_SET);
  
   fread(jpg_buffer,buf_size,1,fp);

   printf("%s %d The szie of jpg is %d !\n",__FUNCTION__,__LINE__,buf_size);
 }
 
 fclose(fp);

#ifndef KJ_QRCODE_MEM
 joseph_qrcode_analysis(argv[1]);
#else
 if((buf_size > 0) && (jpg_buffer != NULL))
 {
  printf("%s %d Read jpg form Mem !\n",__FUNCTION__,__LINE__);
  joseph_qrcode_analysis_mem(jpg_buffer,buf_size);
 }
 
#endif
 free(jpg_buffer);
 jpg_buffer = NULL;
 return 0;
}

你可能感兴趣的:(嵌入式 精确获取文件的大小)