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 - stat http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
   stat

   Usage
   #include <sys\stat.h>
   int stat(char *path,struct stat *buf);

   Description
   stat gets information about a file or directory specified by path  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: stat can now be called from a C++ file.

   Example
   #include <stdio.h>
   #include <time.h>
   #include <sys\stat.h>
   #include <string.h>
   #include <stdlib.h>
   main()
   {
   char *date;
   int ret;
   struct stat buf;
        if((ret = stat("file.dat",&buf))!=0)
        {
             fprintf(stderr,"stat failure error %d",ret);
             abort();
        }
        date = asctime(localtime(&buf.st_ctime));
        printf("\n %s\n",date);
        printf("\n %d mode\n",buf.st_mode);
        printf("\n %ld size\n",buf.st_size);
   }

   Return Value
   stat  returns 0 if the status information is retrieved. On  error  the
   function returns -1 and errno is set.


See Also: fstat filesize

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