get information about a file or directory
#include <sys/stat.h> int stat( const char *path, struct stat *buf );
The stat() function obtains information about the file or directory referenced in path. This information is placed in the structure located at the address indicated by buf.
This function follows symbolic links and gives you information about the resulting file or directory. If you want information about the link itself, use lstat() instead. |
The file <sys/stat.h> contains definitions for the structure stat.
At least the following macros are defined in the <sys/stat.h> header file:
The value m supplied to the macros is the value of the st_mode field of a stat structure. The macro evaluates to a nonzero value if the test is true, and zero if the test is false.
The access permissions for the file or directory are specified as a combination of bits in the st_mode field of a stat structure. These bits are defined in the <sys/stat.h> header file, and are described in the section on this file in the Header Files chapter. The following bits are also encoded in the st_mode field:
#include <stdio.h> #include <sys/stat.h> void main() { struct stat buf; if( stat( "file", &buf ) != -1 ) { printf( "File size = %d\n", buf.st_size ); } }
Safety: | |
---|---|
Interrupt handler | No |
Signal handler | No |
Thread | Yes |
errno, fstat(), fsys_stat(), fsys_fstat(), lstat()