Difference between lstat fstat and stat in C

uzr picture uzr · Oct 1, 2015 · Viewed 22.7k times · Source

Im writing a school assignment in C to search through a file system for directories, regular files and symlinks. For now i use lstat to get information about items.

So whats the difference between lstat fstat and stat system calls?

Answer

user619271 picture user619271 · May 17, 2016

I was also searching for stat vs lstat vs fstat and although there is already an answer to this question, I'd like to see it formatted like that:

lstat() is identical to stat(), except that if pathname is a symbolic link, then it returns information about the link itself, not the file that it refers to.

fstat() is identical to stat(), except that the file about which information is to be retrieved is specified by a file descriptor (instead of a file name).

http://man7.org/linux/man-pages/man2/stat.2.html