LinuxSir.cn,穿越时空的Linuxsir!

 找回密码
 注册
搜索
热搜: shell linux mysql
查看: 636|回复: 1

文件大小属性

[复制链接]
发表于 2005-11-29 15:02:31 | 显示全部楼层 |阅读模式
您好!请教个问题:
>if(stat("/etc/fstab",&statbuf)==-1)
>{
>   printf("Get stat on %s Error:%s\n","/etc/fstab",strerror(errno));
>   return -1;
>}
>printf("file size:%ld bytes\n",statbuf.st_size);
>
>我用这段代码读取文件大小属性,我试过好几个文件,读出来的结果都是1,请问为什
>么?我这样做对吗?
>谢谢!
发表于 2005-11-29 19:09:15 | 显示全部楼层

  1. #include <stdio.h>
  2. #include <stdlib.h>

  3. #include <sys/stat.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>

  6. /**@
  7. *ident
  8. *
  9. *
  10. * */


  11. int main(int argc, char *argv[])
  12. {
  13.     struct stat buf;

  14.     stat("/etc/fstab",&buf);
  15.     printf("size is %d\n", buf.st_size);
  16.     return 0;
  17. }
复制代码

结果

  1. debian:/home/hedes/test# ./test
  2. size is 367
复制代码
回复 支持 反对

使用道具 举报

您需要登录后才可以回帖 登录 | 注册

本版积分规则

快速回复 返回顶部 返回列表