lstat (C System Call)

lstat is a system call that is used to determine information about a file based on its filename.

lstat is exactly the same as the stat system call. The only difference between the two is when the filename refers to a link. When this is the case, lstat returns information about the link itself, whereas stat returns information about the actual file.

Required Include Files

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

Function Definition

int lstat(const char *path, struct stat *buf);
Field Description
const char *path The file path of the file that is being inquired. This can be both relative and absolute.
struct stat *buf A structure where data about the file will be stored. A detailed look at all of the fields in this structure can be found in the struct stat page.
return value Returns a negative value on failure.

Code Snippet

The code for using lstat is exactly the same as the code for using stat. As mentioned before, the only difference between the two functions is when the target is a symbolic link.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License