/*
* fstat(由文件描述词取得文件状态)
* 相关函数 stat,lstat,chmod,chown,readlink,utime
* 表头文件
* #include
* #include
* 定义函数
* int fstat(int fildes,struct stat *buf);
* 函数说明 fstat()用来将参数fildes所指的文件状态,复制到参数buf所指的结构中(struct stat)。
* Fstat()与stat()作用完全相同,不同处在于传入的参数为已打开的文件描述词.
* 返回值 执行成功则返回0,失败返回-1,错误代码存于errno。
*/

/* 范例 */

   
   
   
   
  1. #include   
  2. #include   
  3. #include   
  4. #include    
  5. #include   
  6. #include   
  7.  
  8. int main(int argc, char *argv)  
  9. {  
  10.     struct stat buf;  
  11.     int fd;  
  12.     fd = open ( "/etc/passwd", O_RDONLY );  
  13.     fstat ( fd, &buf );  
  14.     printf ( "/etc/passwd file size: %d\n", buf.st_size );  
  15.     return 0;  
  16. }  


 
/* 执行 /etc/passwd file size = 705 */