Retro video games delivered to your door every month!
Click above to get retro games delivered to your door ever month!
X-Hacker.org- libc - <b>fstat</b> http://www.X-Hacker.org [<<Previous Entry] [^^Up^^] [Next Entry>>] [Menu] [About The Guide]
fstat
=====

Syntax
------

     #include <sys/stat.h>
     
     int fstat(int file, struct stat *sbuf);

Description
-----------

This function obtains the status of the open file FILE and stores it in
SBUF.  stat: for the description of `struct stat' fields.   

Return Value
------------

Zero on success, nonzero on failure (and ERRNO set).

Example
-------

     struct stat s;
     fstat(fileno(stdin), &s);
     if (S_ISREG(s.st_mode))
       puts("STDIN is a redirected disk file");
     else if (S_ISCHR(s.st_mode))
       puts("STDIN is a character device");

Bugs
----

If a file was open in write-only mode, its execute mode bits might be
incorrectly reported as if the file were non-executable.  This is
because some executables are only recognized by reading their first two
bytes, which cannot be done for files open in write-only mode.

For `fstat()' to return valid info, you should make sure that all the
data written to the file has been delivered to the operating system,
e.g. by calling `fflush()'.  Otherwise, the buffering of the library
I/O functions might cause stale info to be returned.

Implementation Notes
--------------------

Supplying a 100% Unix-compatible `f?stat()' functions under DOS is an
implementation nightmare.  The following notes describe some of the
obscure points specific to their behavior in DJGPP.

1. The `drive' for character devices (like `con', `/dev/nul' and others
is returned as -1.  For drives networked by Novell Netware, it is
returned as -2.

2. The starting cluster number of a file serves as its inode number.
For files whose starting cluster number is inaccessible (empty files,
files on networked drives, etc.) the `st_inode' field will be `invented'
in a way which guarantees that no two different files will get the same
inode number (thus it is unique).  This invented inode will also be
different from any real cluster number of any local file.  However, only
for local, non-empty files/directories the inode is guaranteed to be
consistent between `stat()' and `fstat()' function calls.

3. The WRITE access mode bit is set only for the user (unless the file
is read-only, hidden or system).  EXECUTE bit is set for directories,
files which can be executed from the DOS prompt (batch files, .com,
.dll and .exe executables) or run by go32 extender.  For files which
reside on networked drives under Novell Netware, this can sometimes
fail, in which case only the read access bit is set.

4. Size of directories is reported as the number of its files (sans `.'
and `..' entries) multiplied by 32 bytes (the size of directory entry).

5. Time stamp for root directories is taken from the volume label entry,
if that's available; otherwise, it is reported as 1-Jan-1980.

6. The variable _djstat_flags: controls what hard-to-get fields   
of `struct stat' are needed by the application.


See Also: stat _djstat_flags

Online resources provided by: http://www.X-Hacker.org --- NG 2 HTML conversion by Dave Pearson