Standards / Extensions | C or C++ | Dependencies |
---|---|---|
POSIX.1 |
both |
#define _POSIX_SOURCE
#include <sys/stat.h>
int fstat(int fildes, struct stat *info);
Large file support for z/OS UNIX files: Large z/OS UNIX files are supported automatically for AMODE 64 C/C++ applications. AMODE 31 C/C++ applications must be compiled with the option LANGLVL(LONGLONG) and define the _LARGE_FILES feature test macro before any headers are included to enable this function to operate on z/OS UNIX files that are larger than 2 GB in size. File size and offset fields are enlarged to 63 bits in width. Therefore, any other function operating on the file is required to define the _LARGE_FILES feature test macro as well.
If successful, fstat() returns 0.
The file size in bytes or the number of blocks allocated to the file or the file serial number cannot be represented correctly in the structure pointed to by info.
⁄* CELEBF47
This example gets status information for the file called temp.file.
*⁄
#define _POSIX_SOURCE
#include <fcntl.h>
#include <sys⁄types.h>
#include <sys⁄stat.h>
#include <unistd.h>
#undef _POSIX_SOURCE
#include <stdio.h>
#include <time.h>
main() {
char fn[]="temp.file";
struct stat info;
int fd;
if ((fd = creat(fn, S_IWUSR)) < 0)
perror("creat() error");
else {
if (fstat(fd, &info) != 0)
perror("fstat() error");
else {
puts("fstat() returned:");
printf(" inode: %d\n", (int) info.st_ino);
printf(" dev id: %d\n", (int) info.st_dev);
printf(" mode: %08x\n", info.st_mode);
printf(" links: %d\n", info.st_nlink);
printf(" uid: %d\n", (int) info.st_uid);
printf(" gid: %d\n", (int) info.st_gid);
printf("created: %s", ctime(&info.st_createtime));
}
close(fd);
unlink(fn);
}
}
fstat() returned:
inode: 3057
dev id: 1
mode: 03000080
links: 1
uid: 25
gid: 500
created: Fri Jun 16 16:03:16 2001