1FSTAT(P) POSIX Programmer's Manual FSTAT(P)
2
3
4
6 fstat - get file status
7
9 #include <sys/stat.h>
10
11 int fstat(int fildes, struct stat *buf);
12
13
15 The fstat() function shall obtain information about an open file asso‐
16 ciated with the file descriptor fildes, and shall write it to the area
17 pointed to by buf.
18
19 If fildes references a shared memory object, the implementation shall
20 update in the stat structure pointed to by the buf argument only the
21 st_uid, st_gid, st_size, and st_mode fields, and only the S_IRUSR,
22 S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits
23 need be valid. The implementation may update other fields and flags.
24
25 If fildes references a typed memory object, the implementation shall
26 update in the stat structure pointed to by the buf argument only the
27 st_uid, st_gid, st_size, and st_mode fields, and only the S_IRUSR,
28 S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits
29 need be valid. The implementation may update other fields and flags.
30
31 The buf argument is a pointer to a stat structure, as defined in
32 <sys/stat.h>, into which information is placed concerning the file.
33
34 The structure members st_mode, st_ino, st_dev, st_uid, st_gid,
35 st_atime, st_ctime, and st_mtime shall have meaningful values for all
36 other file types defined in this volume of IEEE Std 1003.1-2001. The
37 value of the member st_nlink shall be set to the number of links to the
38 file.
39
40 An implementation that provides additional or alternative file access
41 control mechanisms may, under implementation-defined conditions, cause
42 fstat() to fail.
43
44 The fstat() function shall update any time-related fields as described
45 in the Base Definitions volume of IEEE Std 1003.1-2001, Section 4.7,
46 File Times Update, before writing into the stat structure.
47
49 Upon successful completion, 0 shall be returned. Otherwise, -1 shall be
50 returned and errno set to indicate the error.
51
53 The fstat() function shall fail if:
54
55 EBADF The fildes argument is not a valid file descriptor.
56
57 EIO An I/O error occurred while reading from the file system.
58
59 EOVERFLOW
60 The file size in bytes or the number of blocks allocated to the
61 file or the file serial number cannot be represented correctly
62 in the structure pointed to by buf.
63
64
65 The fstat() function may fail if:
66
67 EOVERFLOW
68 One of the values is too large to store into the structure
69 pointed to by the buf argument.
70
71
72 The following sections are informative.
73
75 Obtaining File Status Information
76 The following example shows how to obtain file status information for a
77 file named /home/cnd/mod1. The structure variable buffer is defined for
78 the stat structure. The /home/cnd/mod1 file is opened with read/write
79 privileges and is passed to the open file descriptor fildes.
80
81
82 #include <sys/types.h>
83 #include <sys/stat.h>
84 #include <fcntl.h>
85
86
87 struct stat buffer;
88 int status;
89 ...
90 fildes = open("/home/cnd/mod1", O_RDWR);
91 status = fstat(fildes, &buffer);
92
94 None.
95
97 None.
98
100 None.
101
103 lstat() , stat() , the Base Definitions volume of IEEE Std 1003.1-2001,
104 <sys/stat.h>, <sys/types.h>
105
107 Portions of this text are reprinted and reproduced in electronic form
108 from IEEE Std 1003.1, 2003 Edition, Standard for Information Technology
109 -- Portable Operating System Interface (POSIX), The Open Group Base
110 Specifications Issue 6, Copyright (C) 2001-2003 by the Institute of
111 Electrical and Electronics Engineers, Inc and The Open Group. In the
112 event of any discrepancy between this version and the original IEEE and
113 The Open Group Standard, the original IEEE and The Open Group Standard
114 is the referee document. The original Standard can be obtained online
115 at http://www.opengroup.org/unix/online.html .
116
117
118
119IEEE/The Open Group 2003 FSTAT(P)