Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

chmod(2)

chown(2)

link(2)

mknod(2)

mount(3)

open(2)

pipe(2)

symlink(2)

utime(2)

stat(2)  —  System Calls

OSF

NAME

stat, fstat, lstat − Provides information about a file

SYNOPSIS

#include <sys/stat.h> #include <sys/types.h> int stat(
const char ∗path,
struct stat ∗buffer ); int lstat(
const char ∗path,
struct stat ∗buffer ); int fstat(
int filedes,
struct stat ∗buffer );

PARAMETERS

pathSpecifies the pathname identifying the file. 

filedesSpecifies the file descriptor identifying the open file. 

bufferPoints to the stat structure in which information is returned. The stat structure is described in the sys/stat.h header file. 

DESCRIPTION

The stat() function obtains information about the file named by the path parameter. Read, write, or execute permission for the named file is not required, but all directories listed in the pathname leading to the file must be searchable.  The file information is written to the area specified by the buffer parameter, which is a pointer to a stat structure, defined in sys/stat.h. 

The fstat() function is like the stat() function except that the information obtained is about an open file referenced by the filedes parameter. 

The lstat() function is like the stat() function except in the case where the named file is a symbolic link.  In this case, the lstat() function returns information about the link, while the stat() and fstat() functions return information about the file the link references.  In the case of a symbolic link, the stat() functions set the st_size field of the stat structure to the length of the symbolic link, and sets the st_mode field to indicate the file type. 

The stat(), lstat() , and fstat() functions update any time-related fields associated with the file before writing into the stat structure. 

NOTES

AES Support Level:
Full use (stat(), fstat()) Trial use (lstat())

RETURN VALUES

Upon successful completion, a value of 0 (zero) is returned. Otherwise, a value of -1 is returned and errno is set to indicate the error. 

ERRORS

If the stat() or lstat() function fails, errno may be set to one of the following values:

[ENOENT]The file named by the path parameter does not exist or is an empty string. 

[ELOOP]Too many links were encountered in translating path. 

[ENAMETOOLONG]
The length of the path parameter exceeds PATH_MAX or a pathname component is longer than NAME_MAX. 

[EACCES]Search permission is denied for a component of the path parameter. 

[ENOTDIR]A component of the path parameter is not a directory. 

[EFAULT]Either the buffer parameter or the path parameter points to a location outside of the allocated address space of the process. 

If the fstat() function fails, errno may be set to one of the following values:

[EBADF]The filedes parameter is not a valid file descriptor. 

[EFAULT]The buffer parameter points to a location outside of the allocated address space of the process. 

RELATED INFORMATION

Functions: chmod(2), chown(2), link(2), mknod(2), mount(3), open(2), pipe(2), symlink(2), utime(2)

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026