Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- Zortech C++ 3.0r4 - <b>fstat</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fstat

Usage

   #include <sys\stat.h>
   int fstat(int fd,struct stat *buf);

Description

   fstat function gets information about an open file fd and stores it in

   the structure that buf points to. The structure stat contains the
   following fields:

   st_dev          Drive number of disk containing file fd or,
                   value of fd if fd is a device.
   st_mode         Bit mask containing mode information on the open file.
                   S_IFCHR     Set if fd refers to a device
                   S_IFREG     Set if fd refers to an ordinary file
                   S_IREAD     Set if file is open for reading.
                   S_IWRITE    Set if file is open for writing.
   st_nlink        Number of links (always 1)
   st_rdev         Same as st_dev
   st_size         Size of open file in bytes
   st_atime        Time last modified
   st_mtime        as above
   st_ctime        as above
   st_ino          Always 0.
   st_uid          Always 0.
   st_gid          Always 0.


Example 

   #include <dos.h>
   #include <sys\stat.h>
   #include <stdio.h>
   #include <io.h>
   #include <time.h>
   #include <errno.h>
   #include <stdlib.h>

   struct stat buf;
   int fh, result;

   int main()
   {
       fh = open("file.dat",O_RDONLY);
       result = fstat(fh,&buf);
       if(result != 0) {
           printf("Bad file handle\n");
           return EXIT_FAILURE;

       } else
           {
               printf("File size : %ld\n",buf.st_size);
               printf("Drive number : %d\n",buf.st_dev);
               printf("Time modified : %s",
               ctime(&buf.st_mtime));
           }
       return EXIT_SUCCESS;
   }

Return Value

   fstat returns a value of 0 if file information is successfully obtained.
   If a value of -1 is returned errno is set to EBADF indicating a bad file
   handle.

See Also

   stat, findfirst, findnext, isatty




See Also: stat findfirst findnext isatty

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson