Chapter Contents

Previous

Next
fstat

fstat



Determine File Status by Descriptor

Portability: POSIX.1 conforming, UNIX compatible


SYNOPSIS
DESCRIPTION
RETURN VALUE
EXAMPLE
RELATED FUNCTIONS
SEE ALSO


SYNOPSIS

#include <sys/types.h>
#include <sys/stat.h>

int fstat(int filedes, struct stat *info);


DESCRIPTION

fstat gets status information for an HFS file and returns it in a stat structure, defined in <sys/stat.h> . The filedes file descriptor is the file descriptor for which status information is needed. filedes must be an open file descriptor associated with an USS HFS file. info is the area of memory in which the status information is stored.

The following macros (defined in <stat.h> ) are available:
S_ISBLK(mode) for block special files
S_ISCHR(mode) for character special files
S_ISDIR(mode) for directories
S_ISFIFO(mode) for pipes and FIFO special files
S_ISLNK(mode) for symbolic links
S_ISREG(mode) for regular files
S_ISSOCK(mode) for integrated sockets


RETURN VALUE

fstat returns a 0 if it is successful and a- 1 if it is not successful.


EXAMPLE

The following example illustrates a function that is called to determine whether two file descriptors access the same file. Note that in this example two different HFS files must either have different device numbers or different inode numbers:

#include <sys/types.h>
#include <sys/stat.h>
#include <stdio.h>

int samefile(int fd1, int fd2) {
   struct stat stat1, stat2;
   int rc;
   rc = fstat(fd1, &stat1);
   if (rc == -1) {
      perror("fstat error");
      return -1;
   }
   rc = fstat(fd2, &stat2);
   if (rc == -1) {
      perror("fstat error");
      return -1;
   }
   if (stat1.st_dev == stat2.st_dev && stat1.st_ino == stat2.st_ino)
      return 1;
   else return 0;
}


RELATED FUNCTIONS

fattr , lstat , stat


SEE ALSO


Chapter Contents

Previous

Next

Top of Page

Copyright © 2001 by SAS Institute Inc., Cary, NC, USA. All rights reserved.