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++ Language Reference - fstat 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  Always 1
   st_rdev   Same as st_dev
   st_size   Size of open file in bytes
   st_atime  Time of last modification
   st_mtime  Same as st_atime
   st_ctime  Same as st_atime

   There  are  three  other fields st_ino, st_vid,  st_gid  in  the  stat
   structure not mentioned that have no meaningful values under DOS. They
   are set to 0. They are provided for UNIX compatibility.

   Note that fstat can now be called from a C++ file.

   Example
   #include <dos.h>
   #include <sys\stat.h>
   #include <stdio.h>
   #include <io.h>
   #include <time.h>
   #include <errno.h>
   struct stat buf;
   int fh, result;
   main()
   {
        fh = open("file.dat",O_RDONLY);
        result = fstat(fh,&buf);
        if(result != 0)
             printf("Bad file handle\n");
        else
        {
             printf("File size : %ld\n",buf.st_size);
             printf("Drive number : %d\n",buf.st_dev);
             printf("Time modified : %s",
             ctime(&buf.st_atime));
        }
   }
   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

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