Your Browser is not longer supported

Please use Google Chrome, Mozilla Firefox or Microsoft Edge to view the page correctly
Loading...

{{viewport.spaceProperty.prod}}

lstat, lstat64, lstatx, lstat64x - query file status

&pagelevel(4)&pagelevel

Syntax

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

int lstat (const char *path, struct stat *buf);
int lstat64 (const char *path, struct stat64 *buf);

CRTE111A30

int lstatx(const char *path, struct statx *buf);
int lstat64x(const char *path, struct stat64x *buf); (End)

Description

Like stat(), lstat() returns file attributes, except that if path points to a symbolic link, lstat() outputs information on the link, while stat() outputs information on the file to which the link refers.

buf is a pointer to a stat structure to which the information on the specified file is written.

There is no difference in functionality between lstat() and lstat64() except that lstat64() returns the file status in a stat64 structure.

The functions with the suffix x behave like the functions of the same name without a suffix, except that they return the file status in a corresponding stat structure with suffix x and therefore will work correctly after 01/19/2038 03:14:07 UTC.

The stat structure contains the following elements:

mode_t    st_mode;    /* File mode (see mknod()) */
ino_t     st_ino;     /* Inode number */
dev_t     st_dev;     /* Device ID which contains a directory entry for
                         this file */
dev_t     st_rdev;    /* Device ID, defined for character-special or
                         block-special files only */
nlink_t   st_nlink;   /* Number of links */
uid_t     st_uid;     /* User ID of the file owner */
gid_t     st_gid;     /* Group ID of the file owner */
off_t     st_size;    /* File size in bytes */
time_t    st_atime;   /* Time of the last access */
time_t    st_mtime;   /* Time of the last data modification */
time_t    st_ctime;   /* Time of the last change of file status
                         The time is measured in seconds as of
                         January 1, 1970, 00:00:00 */
long      st_blksize; /* Preferred I/O block size */
blkcnt_t st_blocks;  /* Number of assigned st_blksize blocks */

The elements of the structure stat64 structure are defined like the stat structure except for the following components:

ino64_t st_ino
off64_t st_size and
blkcnt64_t st_blocks

The elements of the structures statx and stat64x are defined like those of the structures stat bzw. stat64with the exception of the following components:

time64_t    st_atime;
time64_t    st_mtime;
time64_t    st_ctime; 

In addition to the modes described in mknod(), st_mode can also be S_IFLNK if the file is a symbolic link.

The st_size component contains the length of the pathname in the symbolic link. Trailing zeros are not counted. The contents of all remaining components of the stat
structure are undefined.

Return val.

0

if successful.


-1

if an error occurs. errno is set to indicate the error.

Errors

lstat(), lstat64(), lstatx() and lstat64x will fail if: 

 

EACCES

Search permission is denied for a component of the path.

 

EIO

An I/O error occurred when reading from or writing to the file system.

 

ELOOP

Too many symbolic links were encountered in resolving path.

 

ENAMETOOLONG 



The length of the pathname exceeds{PATH_MAX}, or the length of a component of the pathname exceeds {NAME_MAX}.

 

ENOTDIR

A component of the pathname prefix is not a directory.

 

ENOENT

A component of the pathname does not exist, or path points to an empty string.

 

EOVERFLOW

A component is too large to be stored in the structure pointed to by buf.

 

BS2000

 

EINVAL

An attempt was made to access a BS2000 file.

 

ENAMETOOLONG 



The resolving of symbolic links in the pathname leads to an interim result whose length exceeds {PATH_MAX}.

 

EFAULT

buf or path point to an invalid address.

 

EINTR

A signal was caught during the lstat() or lstat64() system call. (End)


lstat() and lstat64() fail when the following applies: 
Extension

 

EOVERFLOW

A timestamp is too large for a time-t component (this will happen after 01/19/2038 03:14:07 a.m. UTC)(End)


lstatx() and lstat64x() fail when the following applies: 

 

EINVAL

POSIX-BC correction status < A47.

See also

chmod(), chown(), creat(), fstat(), link(), mknod(), stat(), unlink(), write(), fcntl.h, sys/stat.h, sys/types.h.