Unix编程之int fstat(int fildes,struct stat *buf);
发布时间:2013-07-23 14:42:32 所属栏目:Unix 来源:站长网
导读:/* * fstat(由文件描述词取得文件状态) * 相关函数 stat,lstat,chmod,chown,readlink,utime * 表头文件 * #includesys/stat.h * #includeunistd.h * 定
/*
* fstat(由文件描述词取得文件状态) * 相关函数 stat,lstat,chmod,chown,readlink,utime * 表头文件 * #include<sys/stat.h> * #include<unistd.h> * 定义函数 * int fstat(int fildes,struct stat *buf); * 函数说明 fstat()用来将参数fildes所指的文件状态,复制到参数buf所指的 结构中(struct stat)。 * Fstat()与stat()作用完全相同,不同处在于传入的参数为已打开的文件描述词. * 返回值 执行成功则返回0,失败返回-1,错误代码存于errno 。 */ /* 范例 */ #include <sys/stat.h> #include <unistd.h> #include <stdio.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> int main(int argc, char *argv) { struct stat buf; int fd; fd = open ( "/etc/passwd", O_RDONLY ); fstat ( fd, &buf ); printf ( "/etc/passwd file size: %dn", buf.st_size ); return 0; } /* 执行 /etc/passwd file size = 705 */ (编辑:佛山站长网) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |