Chinaunix首页 | 论坛 | 博客
  • 博客访问: 257458
  • 博文数量: 52
  • 博客积分: 406
  • 博客等级: 一等列兵
  • 技术积分: 549
  • 用 户 组: 普通用户
  • 注册时间: 2012-04-21 12:34
个人简介

......

文章分类

全部博文(52)

文章存档

2014年(1)

2013年(32)

2012年(19)

我的朋友

分类: LINUX

2013-11-02 15:58:10

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);


阅读(1348) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~