1FSTAT(3P)                  POSIX Programmer's Manual                 FSTAT(3P)
2
3
4

PROLOG

6       This  manual  page is part of the POSIX Programmer's Manual.  The Linux
7       implementation of this interface may differ (consult the  corresponding
8       Linux  manual page for details of Linux behavior), or the interface may
9       not be implemented on Linux.
10

NAME

12       fstat — get file status
13

SYNOPSIS

15       #include <sys/stat.h>
16
17       int fstat(int fildes, struct stat *buf);
18

DESCRIPTION

20       The fstat() function shall obtain information about an open file  asso‐
21       ciated  with the file descriptor fildes, and shall write it to the area
22       pointed to by buf.
23
24       If fildes references a shared memory object, the  implementation  shall
25       update in the stat structure pointed to by the buf argument the st_uid,
26       st_gid, st_size, and st_mode fields, and  only  the  S_IRUSR,  S_IWUSR,
27       S_IRGRP,  S_IWGRP,  S_IROTH,  and  S_IWOTH file permission bits need be
28       valid.  The implementation may update other fields and flags.
29
30       If fildes references a typed memory object,  the  implementation  shall
31       update in the stat structure pointed to by the buf argument the st_uid,
32       st_gid, st_size, and st_mode fields, and  only  the  S_IRUSR,  S_IWUSR,
33       S_IRGRP,  S_IWGRP,  S_IROTH,  and  S_IWOTH file permission bits need be
34       valid. The implementation may update other fields and flags.
35
36       The buf argument is a pointer  to  a  stat  structure,  as  defined  in
37       <sys/stat.h>, into which information is placed concerning the file.
38
39       For  all  other  file types defined in this volume of POSIX.1‐2017, the
40       structure members st_mode, st_ino,  st_dev,  st_uid,  st_gid,  st_atim,
41       st_ctim,  and st_mtim shall have meaningful values and the value of the
42       st_nlink member shall be set to the number of links to the file.
43
44       An implementation that provides additional or alternative  file  access
45       control  mechanisms may, under implementation-defined conditions, cause
46       fstat() to fail.
47
48       The fstat() function shall update any time-related fields (as described
49       in the Base Definitions volume of POSIX.1‐2017, Section 4.9, File Times
50       Update), before writing into the stat structure.
51

RETURN VALUE

53       Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
54       returned and errno set to indicate the error.
55

ERRORS

57       The fstat() function shall fail if:
58
59       EBADF  The fildes argument is not a valid file descriptor.
60
61       EIO    An I/O error occurred while reading from the file system.
62
63       EOVERFLOW
64              The  file size in bytes or the number of blocks allocated to the
65              file or the file serial number cannot be  represented  correctly
66              in the structure pointed to by buf.
67
68       The fstat() function may fail if:
69
70       EOVERFLOW
71              One  of  the  values  is  too  large to store into the structure
72              pointed to by the buf argument.
73
74       The following sections are informative.
75

EXAMPLES

77   Obtaining File Status Information
78       The following example shows how to obtain file status information for a
79       file  named  /home/cnd/mod1.   The structure variable buffer is defined
80       for  the  stat  structure.  The  /home/cnd/mod1  file  is  opened  with
81       read/write privileges and is passed to the open file descriptor fildes.
82
83
84           #include <sys/types.h>
85           #include <sys/stat.h>
86           #include <fcntl.h>
87
88           struct stat buffer;
89           int         status;
90           ...
91           fildes = open("/home/cnd/mod1", O_RDWR);
92           status = fstat(fildes, &buffer);
93

APPLICATION USAGE

95       None.
96

RATIONALE

98       None.
99

FUTURE DIRECTIONS

101       None.
102

SEE ALSO

104       fstatat()
105
106       The  Base  Definitions  volume of POSIX.1‐2017, Section 4.9, File Times
107       Update, <sys_stat.h>, <sys_types.h>
108
110       Portions of this text are reprinted and reproduced in  electronic  form
111       from  IEEE Std 1003.1-2017, Standard for Information Technology -- Por‐
112       table Operating System Interface (POSIX), The Open Group Base  Specifi‐
113       cations  Issue  7, 2018 Edition, Copyright (C) 2018 by the Institute of
114       Electrical and Electronics Engineers, Inc and The Open Group.   In  the
115       event of any discrepancy between this version and the original IEEE and
116       The Open Group Standard, the original IEEE and The Open Group  Standard
117       is  the  referee document. The original Standard can be obtained online
118       at http://www.opengroup.org/unix/online.html .
119
120       Any typographical or formatting errors that appear  in  this  page  are
121       most likely to have been introduced during the conversion of the source
122       files to man page format. To report such errors,  see  https://www.ker
123       nel.org/doc/man-pages/reporting_bugs.html .
124
125
126
127IEEE/The Open Group                  2017                            FSTAT(3P)
Impressum