[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]


fstat

Gets information about an open file.

Compatibility:

This function is compatible with the following targets:

ANSI

BeOS

EMB/RTOS

Mac OS

Palm OS

Win32


Prototype:
#include <stat.h>
int fstat(int fildes, struct stat *buf);
Parameters:

Parameters for this facility are:

fildes  
int  
A file descriptor  
buf  
struct stat *  
The stat structure address  

Remarks:

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."

Return:

If it is successful, fstat() returns zero. If it encounters an error, fstat() returns -1 and sets errno.

See Also:

"stat"

Example of fstat() usage.:
#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


[ First ]  [ Previous ]  [ Next ]  [ Last ]  [ Manuals ]

Visit the Metrowerks website at: http://www.metrowerks.com
For assistance contact Metrowerks Technical Support at: cw_support@metrowerks.com
Copyright © 2000, Metrowerks Corp. All rights reserved.

Last updated: August 16, 2000