Gets information about a file.
Compatibility:This function is compatible with the following targets:
|
EMB/RTOS
|
|
#include <stat.h>
int stat(const char *path, struct stat *buf);Parameters:
Parameters for this facility are:
This function gets information on the file specified in path and puts the information in the structure that buf points to. The structure contains the fields listed in "Stat Structure and Definitions."
If it is successful, stat() returns zero.
#include <stdio.h>
#include <time.h>
#include <unix.h>
int main(void)
{
struct stat info;
stat("Akbar:System Folder:System", &info);
/* Get information on the System file. */
printf("File mode: 0x%lX\n", info.st_mode);
printf("File ID: 0x%lX\n", info.st_ino);
printf("Volume ref. no.: 0x%lX\n", info.st_dev);
printf("Number of links: %hd\n", info.st_nlink);
printf("User ID: %lu\n", info.st_uid);
printf("Group ID: %lu\n", info.st_gid);
printf("File size: %ld\n", info.st_size);
printf("Access time: %s", ctime(&info.st_atime));
printf("Modification time: %s", ctime(&info.st_mtime));
printf("Creation time: %s", ctime(&info.st_ctime));
return 0;
}
This program may print the following:
File mode: 0x800
File ID: 0x4574
Volume ref. no.: 0x0
Number of links: 1
User ID: 200
Group ID: 100
File size: 30480
Access time: Mon Apr 17 19:46:37 1995
Modification time: Mon Apr 17 19:46:37 1995
Creation time: Fri Oct 7 12:00:00 1994