stat

Retrieves the status of the specified file or directory.

Library:LibC
Classification:POSIX
Service:File and Directory I/O

Syntax

  #include <sys/stat.h>
   
  int stat (
     const char   *path,
     struct stat  *buf);
  

Parameters

path

(IN) Points to a string containing the path of the directory or file for which status is to be obtained.

buf

(OUT) Points to the structure containing information about the file.

Return Values

If successful, returns 0. Otherwise, returns -1 and sets errno to one of the following:

Decimal

Constant

Description

1

ENOENT

A component specified in path does not name an existing file or directory, or path is an empty string.

6

EACCES

Search permission is denied for a component of specified in path.

28

EIO

An I/O error occurred while reading from the file system.

65

ENAMETOOLONG

The length of the path parameter exceeds {PATH_MAX} or a path component is longer than {NAME_MAX}.

67

ENOTDIR

A component specified in the path parameter is not a directory.

81

EOVERFLOW

Either there is a value that is too large to store into the structure pointed to by the buf argument, or the file's size, its number of blocks, or its serial number cannot be stored correctly in the structure.

Remarks

The stat function returns information in the stat structure located at the address indicated by the buf parameter.

The caller must have permission to search all directories in the path parameter.

The sys/stat.h header file contains definitions for the stat structure and the fields are described in stat.