Gets information about an open file.
Compatibility:This function is compatible with the following targets:
|
EMB/RTOS
|
|
#include <stat.h>
int fstat(int fildes, struct stat *buf);Parameters:
Parameters for this facility are:
This function gets information on the file associated with fildes and puts the information in the structure that buf points to. The structure contains the fields listed in "Stat Structure and Definitions."
#include <stdio.h>
#include <time.h>
#include <unix.h>
int main(void)
{
struct stat info;
int fd;
fd = open("mytest", O_WRONLY | O_CREAT | O_TRUNC);
write(fd, "Hello world!\n", 13);
fstat(fd, &info);
/* Get information on the open 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));
close(fd);
return 0;
}
This program may print the following:
File mode: 0x800
File ID: 0x5ACA
Volume ref. no.: 0xFFFFFFFF
Number of links: 1
User ID: 200
Device type: 0
File size: 13