.TH fstat() "" "" "System Call (libc)"
.PC "Find attributes of an open file"
.B "#include <sys/stat.h>"
\fBint fstat(\fIfd, statptr\^\fB)\fR
\fBint \fIfd\^\fB; struct stat *\fIstatptr\^\fB;\fR
.PP
.B fstat()
examines the attributes of an open file.
.I fd
is the descriptor of the open file or pipe you wish to examine.
.I statptr
points to a structure of type
.BR stat ,
which is defined in the header file
.BR <stat.h> ;
.B fstat()
writes into it the attributes of the file or pipe to which
.I fd
points, including protection information, file type, and file size.
.PP
.B fstat()
returns zero if all goes well.
If an error occurs (e.g.,
.I fd
is not found or
.I statptr
is invalid), it returns \-1.
.SH Example
For an example of how to use this function, see the Lexicon entry for
.BR pipe() .
.SH "See Also"
.Xr "chmod()," chmod.s
.Xr "chown()," chown.s
.Xr "libc," libc
.Xr "ls," ls
.Xr "open()," open
.Xr "stat()," stat
.Xr "stat.h" stat.h
.br
\*(PX Standard, \(sc5.6.2
.SH Notes
.B fstat()
differs from the related function
.B stat()
mainly in that it accesses a file through its descriptor,
which was returned by a successful call to
.BR open() ,
whereas
.B stat()
takes the file's path name and opens the file itself before it checks
its status.
