Syntax
#include <sys\types.h> #include <sys\stat.h> int stat(const char *pathname, struct stat *buffer) ;Description
stat stores information about the file or directory specified by pathname in the structure to which buffer points. The stat structure, defined in <sys\stat.h>, contains the following fields:
Field
st_dev
Note: In earlier releases of C Set ++, stat began with an underscore (_stat). Because it is defined by the X/Open standard, the underscore has been removed. For compatibility, The Developer's Toolkit will map _stat to stat for you.
stat returns the value 0 if the file status information is obtained. A return value of -1 indicates an error, and errno is set to ENOENT, indicating that the file name or path name could not be found.
This example requests that the status information for the file test.exe be placed into the structure buf. If the request is successful and the file is executable, the example runs test.exe.
#include <sys\types.h>#include <sys\stat.h> #include <process.h> #include <stdio.h> int main(void) { struct stat buf; if (0 == stat("test.exe", &buf)) { if ((buf.st_mode&S_IFREG) && (buf.st_mode&S_IEXEC)) execl("test.exe", "test", NULL); /* file is executable */ } else printf("File could not be found\n"); return 0; /**************************************************************************** The source for test.exe is: #include <stdio.h> int main(void) { puts("test.exe is an executable file"); } The output should be: test.exe is an executable file ****************************************************************************/ }Related Information