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

2011年(14)

我的朋友
最近访客

分类: IT职场

2011-01-13 04:06:31

  1. #include<stdio.h>
  2. #include<stdlib.h>
  3. #include<sys/stat.h>
  4. #include<sys/types.h>
  5. #include<unistd.h>
  6. #include<fcntl.h>
  7. int flen(int fd)
  8. {
  9.         struct stat stat_res;
  10.         if(fstat(fd, &stat_res) < 0)
  11.         {
  12.                 perror("fstat() error");
  13.                 exit(1);
  14.         }
  15.         return stat_res.st_size;
  16. }
  17. int main(int argc, char **argv)
  18. {
  19.         int fd;
  20.         if(argc < 2)
  21.         {
  22.                 fprintf(stderr, "Usage...\n");
  23.                 exit(1);
  24.         }
  25.         fd = open(argv[1], O_RDONLY);
  26.         {
  27.                 if(fd < 0)
  28.                 {
  29.                         perror("open() error");
  30.                         exit(1);
  31.                 }
  32.                 printf("%d\n", flen(fd));
  33.                 close(fd);
  34.                 return 0;
  35.         }

阅读(221) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~