Chinaunix首页 | 论坛 | 博客
  • 博客访问: 7534
  • 博文数量: 14
  • 博客积分: 250
  • 博客等级: 二等列兵
  • 技术积分: 95
  • 用 户 组: 普通用户
  • 注册时间: 2011-01-13 01:08
文章分类
文章存档

2011年(14)

我的朋友
最近访客

分类: IT职场

2011-01-13 02:58:06

  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <stdint.h>
  4. #include <sys/stat.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. static off_t flen(FILE *fp)
  8. {
  9.         struct stat statres;
  10.         if(fstat(fileno(fp), &statres) < 0)
  11.         {
  12.                 return -1;
  13.         }
  14.         return statres.st_size;
  15. }
  16. int main(int argc, char **argv)
  17. {
  18.         FILE *fp;
  19.         off_t len;
  20.         if(argc < 2)
  21.         {
  22.                 fprintf(stderr, "Usage...\n");
  23.                 exit(1);
  24.         }
  25.         fp = fopen(argv[1], "rb");
  26.         if((fp == NULL))
  27.         {
  28.                 return -1;
  29.         }
  30.         len = flen(fp);
  31.         if(len < 0)
  32.         {
  33.                 perror("flen()error");
  34.                 exit(1);
  35.         }
  36.         else
  37.         {
  38.                 printf("%lld\n", (int64_t)len);
  39.                 fclose(fp);
  40.                 exit(0);
  41.         }
  42. }
  43. ~
阅读(274) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~