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>stat</b> 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         Total 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 <stdio.h>
   #include <time.h>
   #include <sys\stat.h>
   #include <string.h>
   #include <stdlib.h>

   int main()
   {
       char *date;
       int ret;

       struct stat buf;
       if((ret = stat("file.dat",&buf))!=0)
           {
               fprintf(stderr,"stat failure error %d",ret);
               exit(EXIT_FAILURE);
           }
       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 EXIT_SUCCESS;
   }

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