[问题]请问如何用c语言来获取一份文件的大小,权限等属性?

软件和网站开发以及相关技术探讨
回复
billycatcat
帖子: 49
注册时间: 2007-10-06 11:02
来自: 广东佛山

[问题]请问如何用c语言来获取一份文件的大小,权限等属性?

#1

帖子 billycatcat » 2008-03-20 10:20

请问如何用c语言来获取一份文件的大小,权限等属性?
用文件流与文件建立关联之后怎样实现阿?
头像
iblicf
帖子: 3766
注册时间: 2007-01-15 17:15

#2

帖子 iblicf » 2008-03-20 10:23

代码: 全选

man fstat 
           struct stat {
               dev_t     st_dev;     /* ID of device containing file */
               ino_t     st_ino;     /* inode number */
               mode_t    st_mode;    /* protection */
               nlink_t   st_nlink;   /* number of hard links */
               uid_t     st_uid;     /* user ID of owner */
               gid_t     st_gid;     /* group ID of owner */
               dev_t     st_rdev;    /* device ID (if special file) */
               off_t     st_size;    /* total size, in bytes */
               blksize_t st_blksize; /* blocksize for filesystem I/O */
               blkcnt_t  st_blocks;  /* number of blocks allocated */
               time_t    st_atime;   /* time of last access */
               time_t    st_mtime;   /* time of last modification */
               time_t    st_ctime;   /* time of last status change */
           };
参见 APUE
billycatcat
帖子: 49
注册时间: 2007-10-06 11:02
来自: 广东佛山

#3

帖子 billycatcat » 2008-03-20 10:43

谢谢 原来就是那个fstat 呵呵
头像
titainium
帖子: 689
注册时间: 2006-12-02 12:25

#4

帖子 titainium » 2008-03-20 12:01

看一看《Linux/Unix实践编程教程》吧,里面东西很实用。
Titainium
yuffey
帖子: 193
注册时间: 2007-09-06 16:24
来自: 中国上海

#5

帖子 yuffey » 2008-03-20 13:27

收藏中。。。
billycatcat
帖子: 49
注册时间: 2007-10-06 11:02
来自: 广东佛山

#6

帖子 billycatcat » 2008-03-20 21:50

titainium 写了:看一看《Linux/Unix实践编程教程》吧,里面东西很实用。
谢谢教导 最近在看 《Linux程序设计 3rd》 感觉知识点讲得全,但实践时有时就摸不着头脑
billycatcat
帖子: 49
注册时间: 2007-10-06 11:02
来自: 广东佛山

#7

帖子 billycatcat » 2008-03-20 22:48

iblicf 写了:

代码: 全选

man fstat 
           struct stat {
               dev_t     st_dev;     /* ID of device containing file */
               ino_t     st_ino;     /* inode number */
               mode_t    st_mode;    /* protection */
               nlink_t   st_nlink;   /* number of hard links */
               uid_t     st_uid;     /* user ID of owner */
               gid_t     st_gid;     /* group ID of owner */
               dev_t     st_rdev;    /* device ID (if special file) */
               off_t     st_size;    /* total size, in bytes */
               blksize_t st_blksize; /* blocksize for filesystem I/O */
               blkcnt_t  st_blocks;  /* number of blocks allocated */
               time_t    st_atime;   /* time of last access */
               time_t    st_mtime;   /* time of last modification */
               time_t    st_ctime;   /* time of last status change */
           };
参见 APUE

你好 文件大小通过printf()能正确输出
但文件权限该怎样输出才能显示 -rwxr--r--类似的模式
回复