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
11

NAME

13       fstat — get file status
14

SYNOPSIS

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

DESCRIPTION

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

RETURN VALUE

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

ERRORS

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

EXAMPLES

78   Obtaining File Status Information
79       The following example shows how to obtain file status information for a
80       file  named  /home/cnd/mod1.   The structure variable buffer is defined
81       for  the  stat  structure.  The  /home/cnd/mod1  file  is  opened  with
82       read/write privileges and is passed to the open file descriptor fildes.
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‐2008, Section 4.8, 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, 2013 Edition, Standard for Information Technology
112       -- Portable Operating System Interface (POSIX),  The  Open  Group  Base
113       Specifications Issue 7, Copyright (C) 2013 by the Institute of Electri‐
114       cal and Electronics Engineers,  Inc  and  The  Open  Group.   (This  is
115       POSIX.1-2008  with  the  2013  Technical Corrigendum 1 applied.) In the
116       event of any discrepancy between this version and the original IEEE and
117       The  Open Group Standard, the original IEEE and The Open Group Standard
118       is the referee document. The original Standard can be  obtained  online
119       at http://www.unix.org/online.html .
120
121       Any  typographical  or  formatting  errors that appear in this page are
122       most likely to have been introduced during the conversion of the source
123       files  to  man page format. To report such errors, see https://www.ker
124       nel.org/doc/man-pages/reporting_bugs.html .
125
126
127
128IEEE/The Open Group                  2013                            FSTAT(3P)
Impressum