1. 函数原型int fstat(int fd, struct stat *buf);
2. 需要包含头文件
#include
#include
#include
3. 函数功能: These functions return information about a file, 把一个文件的信息放在结构struct stat 中
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 file system I/O */
blkcnt_t st_blocks; /* number of 512B 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 */
};
4. 函数返回值, On success, zero is returned. On error, -1 is returned, and errno is set appropriately.
5. exemple
struct stat fileAttribute;
if(fstat(fd, &fileAttribute) < 0)
printf("fstat func failed\n");
printf("fd size :%d\n", fileAttribute.st_size);
阅读(1454) | 评论(0) | 转发(0) |