免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 3783 | 回复: 0
打印 上一主题 下一主题

[新手入门] 1--stat、fstat和lstat函数(UNIX) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-04-26 09:33 |只看该作者 |倒序浏览
    #include
    #include
    int stat(const char* pathname,struct stat *buf);
    int fstat(int filedes,struct stat *buf);
    int lstat(const char *pathname,struct stat *buf);
                       三个函数的返回:若成功则为0,若出错则为-1
    给定一个pathname,stat函数返回一个与此命名文件有关的信息结构,fstat函数获得已在描述符filedes上打开的文件的有关信息。lstat函数类似于stat,但是当命名的文件是一个符号连接时,lstat返回该符号连接的有关信息,而不是由该符号连接引用的文件的信息。
    第二个参数是个指针,它指向一个我们应提供的结构。这些函数填写由buf指向的结构。该结构的实际定义可能随实现而有所不同,但其基本形式是:
struct stat{
mode_t st_mode;   /*file tpye &mode (permissions)*/
ino_t  st_ino;     /*i=node number (serial number)*/
dev_t  st_rdev;   /*device number for special files*/
nlink_t st_nlink; /*number of links*/
uid_t    st_uid;  /*user id of owner*/
gid_t    st_gid;  /*group ID of owner*/
off_t   st_size;  /*size in bytes for regular files*/
time_t  st_atime; /*time of last access*/
time_t st_mtime;  /*time of last modification*/
time_t  st_ctime; /*time of last file status change*/
long st_blksize;  /*best I/O block size */
long  st_blocks;  /*number of 512-byte blocks allocated*/
};
   注意,除最后两个以外,其他各成员都为基本系统数据类型。我们将说明此结构的每个成员以了解文件属性。
   
使用stat函数最多的可能是ls-l命令,用其可以获得有关一个文件的所有信息。

本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/34065/showart_286521.html
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP