FSTAT(3P)
๐ FSTAT(3P) โ get file status ๐
okay bestie, gather round, because we're reading a page straight out of the POSIX Programmer's Manual and it's lowkey iconic. โจ
PROLOG โ real talk before we even start: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go consult the corresponding Linux manual page for the deets on Linux behavior), or the interface might not even be implemented on Linux at all. ๐ no cap.
๐ธ NAME ๐ธ
fstat โ get file status. that's it. that's the whole vibe check. ๐
โจ SYNOPSIS โจ
#include <sys/stat.h>
int fstat(int fildes, struct stat *buf);
๐ฆ DESCRIPTION ๐ฆ
so the fstat() function shall obtain information about an open file associated with the file descriptor fildes, and shall write it to the area pointed to by buf. like, it's reading the file's whole aura and dumping it into your struct. ๐ฎ
if fildes references a shared memory object, the implementation shall update in the stat structure pointed to by the buf argument the st_uid, st_gid, st_size, and st_mode fields โ and only the S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be valid. The implementation may update other fields and flags. so like, don't come for the other fields, they're not required to be cute. ๐
if fildes references a typed memory object, the implementation shall update in the stat structure pointed to by the buf argument the st_uid, st_gid, st_size, and st_mode fields, and again only the S_IRUSR, S_IWUSR, S_IRGRP, S_IWGRP, S_IROTH, and S_IWOTH file permission bits need be valid. The implementation may update other fields and flags. same energy, different object type. โจ
the buf argument is a pointer to a stat structure, as defined in <sys/stat.h>, into which information is placed concerning the file. ๐ฅ
for all other file types defined in this volume of POSIX.1โ2017, the structure members st_mode, st_ino, st_dev, st_uid, st_gid, st_atim, st_ctim, and st_mtim shall have meaningful values, and the value of the st_nlink member shall be set to the number of links to the file. main character fields, all of them. ๐
an implementation that provides additional or alternative file access control mechanisms may, under implementation-defined conditions, cause fstat() to fail. so if it flops, it might not be its fault, iykyk.
the fstat() function shall update any time-related fields (as described in the Base Definitions volume of POSIX.1โ2017, Section 4.9, File Times Update), before writing into the stat structure. order matters, bestie. โณ
๐ฅ RETURN VALUE ๐ฅ
upon successful completion, 0 shall be returned. otherwise, -1 shall be returned and errno set to indicate the error. classic 0-or-flop situation. ๐ญ
๐ ERRORS ๐
the fstat() function shall fail if:
EBADFโ thefildesargument is not a valid file descriptor. bestie that's not a real fd, that's a fake one. ๐ซEIOโ an I/O error occurred while reading from the file system. the disk said "no <3".EOVERFLOWโ the file size in bytes or the number of blocks allocated to the file or the file serial number cannot be represented correctly in the structure pointed to bybuf. it's too big for the box, literally. ๐ฆ๐ฅ
the fstat() function may fail if:
EOVERFLOWโ one of the values is too large to store into the structure pointed to by thebufargument. yeah it's back, second verse same as the first. ๐ซ
heads up: the following sections are informative. so like, they're the bonus content, not the binding lore. ๐
๐ EXAMPLES ๐
Obtaining File Status Information
the following example shows how to obtain file status information for a file named /home/cnd/mod1. The structure variable buffer is defined for the stat structure. The /home/cnd/mod1 file is opened with read/write privileges and is passed to the open file descriptor fildes. look at her go ๐ซถ
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
struct stat buffer;
int status;
...
fildes = open("/home/cnd/mod1", O_RDWR);
status = fstat(fildes, &buffer);
๐ APPLICATION USAGE ๐
None. โ literally nothing to add, we said what we said. ๐
๐ง RATIONALE ๐ง
None. โ no thoughts, head empty, the rationale is simply that girl. โจ
โญ FUTURE DIRECTIONS โญ
None. โ no plans, no drama, no sequels. periodt. ๐ฌ
๐ SEE ALSO ๐
fstatat()- The Base Definitions volume of POSIX.1โ2017, Section 4.9, File Times Update,
<sys_stat.h>,<sys_types.h>
๐ COPYRIGHT ๐
portions of this text are reprinted and reproduced in electronic form from IEEE Std 1003.1-2017, Standard for Information Technology -- Portable Operating System Interface (POSIX), The Open Group Base Specifications Issue 7, 2018 Edition, Copyright (C) 2018 by the Institute of Electrical and Electronics Engineers, Inc and The Open Group. In the event of any discrepancy between this version and the original IEEE and The Open Group Standard, the original IEEE and The Open Group Standard is the referee document. The original Standard can be obtained online at http://www.opengroup.org/unix/online.html .
any typographical or formatting errors that appear in this page are most likely to have been introduced during the conversion of the source files to man page format. To report such errors, see https://www.kernel.org/doc/man-pages/reporting_bugs.html .
and that's the whole page bestie!! ๐ this one came to you courtesy of IEEE/The Open Group, dated 2017, and the page is FSTAT(3P). slay, stay hydrated, go call fstat() on something. ๐โจ๐ฆ
๐ฆ where this page comes from
- alpine 3.22: man-pages-posix 2017a-r0 ยท custom
- alpine 3.23: man-pages-posix 2017a-r0 ยท custom
- alpine 3.24: man-pages-posix 2017a-r0 ยท custom
- arch rolling: man-pages 6.19-1
- arch rolling: man-pages 6.20-1 ยท BSD-2-Clause AND BSD-3-Clause AND BSD-4.3TAHOE AND BSD-4-Clause-UC AND GPL-1.0-or-later AND GPL-2.0-only AND GPL-2.0-or-later AND GPL-3.0-or-later AND LGPL-3.0-linking-exception AND LGPL-3.0-or-later AND LicenseRef-Public-Domain AND LicenseRef-UltraPermissive AND Linux-man-pages-1-para AND Linux-man-pages-copyleft AND Linux-man-pages-copyleft-2-para AND Linux-man-pages-copyleft-var AND MIT AND Spencer-94
- nixpkgs unstable: man-pages-posix 2017a
- opensuse-leap 16.0: man-pages-posix 2017a-160000.4.1 ยท SUSE-IEEE
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms