1stat(2) System Calls Manual stat(2)
2
3
4
6 stat, fstat, lstat, fstatat - get file status
7
9 Standard C library (libc, -lc)
10
12 #include <sys/stat.h>
13
14 int stat(const char *restrict pathname,
15 struct stat *restrict statbuf);
16 int fstat(int fd, struct stat *statbuf);
17 int lstat(const char *restrict pathname,
18 struct stat *restrict statbuf);
19
20 #include <fcntl.h> /* Definition of AT_* constants */
21 #include <sys/stat.h>
22
23 int fstatat(int dirfd, const char *restrict pathname,
24 struct stat *restrict statbuf, int flags);
25
26 Feature Test Macro Requirements for glibc (see feature_test_macros(7)):
27
28 lstat():
29 /* Since glibc 2.20 */ _DEFAULT_SOURCE
30 || _XOPEN_SOURCE >= 500
31 || /* Since glibc 2.10: */ _POSIX_C_SOURCE >= 200112L
32 || /* glibc 2.19 and earlier */ _BSD_SOURCE
33
34 fstatat():
35 Since glibc 2.10:
36 _POSIX_C_SOURCE >= 200809L
37 Before glibc 2.10:
38 _ATFILE_SOURCE
39
41 These functions return information about a file, in the buffer pointed
42 to by statbuf. No permissions are required on the file itself, but—in
43 the case of stat(), fstatat(), and lstat()—execute (search) permission
44 is required on all of the directories in pathname that lead to the
45 file.
46
47 stat() and fstatat() retrieve information about the file pointed to by
48 pathname; the differences for fstatat() are described below.
49
50 lstat() is identical to stat(), except that if pathname is a symbolic
51 link, then it returns information about the link itself, not the file
52 that the link refers to.
53
54 fstat() is identical to stat(), except that the file about which infor‐
55 mation is to be retrieved is specified by the file descriptor fd.
56
57 The stat structure
58 All of these system calls return a stat structure (see stat(3type)).
59
60 Note: for performance and simplicity reasons, different fields in the
61 stat structure may contain state information from different moments
62 during the execution of the system call. For example, if st_mode or
63 st_uid is changed by another process by calling chmod(2) or chown(2),
64 stat() might return the old st_mode together with the new st_uid, or
65 the old st_uid together with the new st_mode.
66
67 fstatat()
68 The fstatat() system call is a more general interface for accessing
69 file information which can still provide exactly the behavior of each
70 of stat(), lstat(), and fstat().
71
72 If the pathname given in pathname is relative, then it is interpreted
73 relative to the directory referred to by the file descriptor dirfd
74 (rather than relative to the current working directory of the calling
75 process, as is done by stat() and lstat() for a relative pathname).
76
77 If pathname is relative and dirfd is the speci