FCHMOD(3P)
πΈ fchmod(3P) β bestie edition πΈ
okay so this is FCHMOD(3P) from the POSIX Programmer's Manual, and we're gonna get you fluent in it, no cap. π
β¨ PROLOG β¨
real talk first: this manual page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ β so go check the corresponding Linux manual page for the deets on Linux behavior β or honestly the interface might not even be implemented on Linux at all. π
π NAME π
fchmod β change mode of a file. that's it, that's the whole job, and it slays.
π SYNOPSIS π
#include <sys/stat.h>
int fchmod(int fildes, mode_t mode);
π¦ DESCRIPTION π¦
so fchmod() is literally chmod()'s twin, except the file whose permissions get changed is specified by the file descriptor fildes instead of a path. same energy, different address. β¨
if fildes references a shared memory object, fchmod() only needs to affect these six bits, that's the whole list, don't @ me:
S_IRUSRS_IWUSRS_IRGRPS_IWGRPS_IROTHS_IWOTH
if fildes references a typed memory object, the behavior of fchmod() is unspecified. π«
if fildes refers to a socket, the behavior of fchmod() is unspecified too. we simply do not know, bestie.
if fildes refers to a STREAM (one that's been fattach()-ed into the file system name space), the call returns successfully, doing absolutely nothing. iconic behavior honestly. it showed up, it collected its 0, it left. π
π RETURN VALUE π
- on success?
fchmod()returns0. slay. - otherwise it returns
-1and setserrnoto tell you what went wrong. π
π ERRORS π
fchmod() shall fail if:
EBADFβ thefildesargument is not an open file descriptor. it's giving "who even are you". π«EPERMβ the effective user ID does not match the owner of the file and the process does not have appropriate privileges. no permission, no entry. πEROFSβ the file referred to byfildesresides on a read-only file system. frozen. can't touch. π§
fchmod() may fail if:
EINTRβ thefchmod()function was interrupted by a signal. rude, honestly. π€EINVALβ the value of themodeargument is invalid.EINVALβ thefildesargument refers to a pipe and the implementation disallows execution offchmod()on a pipe. yes it'sEINVALtwice, that's not a typo, that's just how it is. π
heads up: the following sections are informative. they're the vibes, not the rules.
π EXAMPLES π
Changing the Current Permissions for a File
here's how you change the permissions for a file named /home/cnd/mod1 so that the owner and group have read/write/execute, but the world only gets read/write. watch and learn π«Ά
#include <sys/stat.h>
#include <fcntl.h>
mode_t mode;
int fildes;
...
fildes = open("/home/cnd/mod1", O_RDWR);
fchmod(fildes, S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH);
π APPLICATION USAGE π
None. genuinely nothing to add, the girlies said "we're good". β¨
π§ RATIONALE π§
None. no thoughts, head empty. πΈ
β FUTURE DIRECTIONS β
None. the future is wide open and this page is not going to speculate. π«
π SEE ALSO π
chmod()chown()creat()fcntl()fstatat()fstatvfs()mknod()open()read()write()
and from the Base Definitions volume of POSIX.1β2017: <sys_stat.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 .
okay that's the whole thing, you're officially fluent, go change some file modes responsibly bestie π β¨
IEEE/The Open Group β 2017 π that's the source, the version, and the date, all wrapped up with a bow. mwah. π
π¦ 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