.\" 2007-06-08 mtk: Added example program
.\" 2007-07-05 mtk: Added details on underlying system call interfaces
.\"
-.TH STAT 2 2014-03-19 "Linux" "Linux Programmer's Manual"
+.TH STAT 2 2014-05-10 "Linux" "Linux Programmer's Manual"
.SH NAME
stat, fstat, lstat, fstatat \- get file status
.SH SYNOPSIS
.sp
.BR lstat ():
.RS 4
-_BSD_SOURCE || _XOPEN_SOURCE\ >=\ 500 ||
+/* glibc 2.19 and earlier */ _BSD_SOURCE ||
+.br
+/* Since glibc 2.20 */_DEFAULT_SOURCE ||
+.br
+_XOPEN_SOURCE\ >=\ 500 ||
_XOPEN_SOURCE\ &&\ _XOPEN_SOURCE_EXTENDED
.br
|| /* Since glibc 2.10: */ _POSIX_C_SOURCE\ >=\ 200112L
is changed by writing or by setting inode information
(i.e., owner, group, link count, mode, etc.).
.PP
-The following POSIX macros are defined to check the file type using the
+The following mask values are defined for the file type component of the
.I st_mode
field:
+.in +4n
+.TS
+lB l l.
+S_IFMT 0170000 bit mask for the file type bit fields
+
+S_IFSOCK 0140000 socket
+S_IFLNK 0120000 symbolic link
+S_IFREG 0100000 regular file
+S_IFBLK 0060000 block device
+S_IFDIR 0040000 directory
+S_IFCHR 0020000 character device
+S_IFIFO 0010000 FIFO
+.TE
+.in
+.PP
+Thus, to test for a regular file (for example), one could write:
+
+.nf
+.in +4n
+stat(pathname, &sb);
+if ((sb.st_mode & S_IFMT) == S_IFREG) {
+ /* Handle regular file */
+}
+.in
+.fi
+.PP
+Because tests of the above form are common, additional
+macros are defined by POSIX to allow the test of the file type in
+.I st_mode
+to be written more concisely:
.RS 4
.TP 1.2i
.BR S_ISREG (m)
socket? (Not in POSIX.1-1996.)
.RE
.PP
-The following flags are defined for the
+The preceding code snippet could thus be rewritten as:
+
+.nf
+.in +4n
+stat(pathname, &sb);
+if (S_ISREG(sb.st_mode)) {
+ /* Handle regular file */
+}
+.in
+.fi
+.PP
+The definitions of most of the above file type test macros
+are provided if any of the following feature test macros are defined:
+.BR _BSD_SOURCE
+(in glibc 2.19 and earlier),
+.BR _SVID_SOURCE
+(in glibc 2.19 and earlier),
+or
+.BR _DEFAULT_SOURCE
+(in glibc 2.20 and later).
+In addition, definitions of all of the above macros except
+.BR S_IFSOCK
+and
+.BR S_ISSOCK ()
+are provided if
+.BR _XOPEN_SOURCE
+is defined.
+The definition of
+.BR S_IFSOCK
+can also be exposed by defining
+.BR _XOPEN_SOURCE
+with a value of 500 or greater.
+
+The definition of
+.BR S_ISSOCK ()
+is exposed if any of the following feature test macros is defined:
+.BR _BSD_SOURCE
+(in glibc 2.19 and earlier),
+.BR _DEFAULT_SOURCE
+(in glibc 2.20 and later),
+.BR _XOPEN_SOURCE
+with a value of 500 or greater, or
+.BR _POSIX_C_SOURCE
+with a value of 200112L or greater.
+.PP
+The following mask values are defined for
+the file permissions component of the
.I st_mode
field:
.in +4n
.TS
lB l l.
-S_IFMT 0170000 bit mask for the file type bit fields
-S_IFSOCK 0140000 socket
-S_IFLNK 0120000 symbolic link
-S_IFREG 0100000 regular file
-S_IFBLK 0060000 block device
-S_IFDIR 0040000 directory
-S_IFCHR 0020000 character device
-S_IFIFO 0010000 FIFO
S_ISUID 0004000 set-user-ID bit
S_ISGID 0002000 set-group-ID bit (see below)
S_ISVTX 0001000 sticky bit (see below)
-S_IRWXU 00700 mask for file owner permissions
-S_IRUSR 00400 owner has read permission
-S_IWUSR 00200 owner has write permission
-S_IXUSR 00100 owner has execute permission
-S_IRWXG 00070 mask for group permissions
-S_IRGRP 00040 group has read permission
-S_IWGRP 00020 group has write permission
-S_IXGRP 00010 group has execute permission
-S_IRWXO 00007 T{
+
+S_IRWXU 00700 mask for file owner permissions
+S_IRUSR 00400 owner has read permission
+S_IWUSR 00200 owner has write permission
+S_IXUSR 00100 owner has execute permission
+
+S_IRWXG 00070 mask for group permissions
+S_IRGRP 00040 group has read permission
+S_IWGRP 00020 group has write permission
+S_IXGRP 00010 group has execute permission
+
+S_IRWXO 00007 T{
mask for permissions for others (not in group)
T}
-S_IROTH 00004 others have read permission
-S_IWOTH 00002 others have write permission
-S_IXOTH 00001 others have execute permission
+S_IROTH 00004 others have read permission
+S_IWOTH 00002 others have write permission
+S_IXOTH 00001 others have execute permission
.TE
.in
.P
The set-group-ID bit
.RB ( S_ISGID )
has several special uses.
-For a directory it indicates that BSD semantics is to be used
+For a directory, it indicates that BSD semantics is to be used
for that directory: files created there inherit their group ID from
the directory, not from the effective group ID of the creating process,
and directories created there will also get the
POSIX.1-1996, but both are present in POSIX.1-2001;
the former is from SVID 4, the latter from SUSv2.
.LP
-UNIX V7 (and later systems) had
+UNIX\ V7 (and later systems) had
.BR S_IREAD ,
.BR S_IWRITE ,
.BR S_IEXEC ,
Nanosecond timestamps are supported on XFS, JFS, Btrfs, and
ext4 (since Linux 2.6.23).
.\" commit ef7f38359ea8b3e9c7f2cae9a4d4935f55ca9e80
-Nanosecond timestamps are not supported in ext2, ext3, and Resierfs.
+Nanosecond timestamps are not supported in ext2, ext3, and Reiserfs.
On filesystems that do not support subsecond timestamps,
the nanosecond fields are returned with the value 0.
.SS Underlying kernel interface
.BR capabilities (7),
.BR symlink (7)
.SH COLOPHON
-This page is part of release 3.65 of the Linux
+This page is part of release 3.67 of the Linux
.I man-pages
project.
A description of the project,
-and information about reporting bugs,
+information about reporting bugs,
+and the latest version of this page,
can be found at
\%http://www.kernel.org/doc/man\-pages/.