FCHMOD(3POSIX)
π FCHMOD β POSIX Programmer's Manual, bestie edition π
okay so quick vibe check before we even start: this page is literally from the POSIX Programmer's Manual (that's the manual name, hi, welcome, it's iconic). But real talk β the Linux implementation of this interface may differ, so go peek at the matching Linux manual page for the actual Linux behavior, or the interface might justβ¦ not be implemented on Linux at all. π So keep that in mind, bestie.
β¨ NAME β¨
fchmod β change mode of a file π
(that's it. that's the name. short, sweet, main character energy.)
π SYNOPSIS π
#include <sys/stat.h>
int fchmod(int fildes, mode_t mode);
like. look at it. two args. fildes and mode. so clean. β¨
π¦ DESCRIPTION π¦
So here's the tea, bestie. fchmod() shall be equivalent to chmod() β with one glow-up: instead of naming the file by path, you name it by file descriptor, fildes. That's literally the whole difference. You already have the fd open, you just vibe-check its permissions directly. π
Now, the specifics, because we do NOT skip specifics in this house:
- If
fildesreferences a shared memory object, thenfchmod()need only affect theS_IRUSR,S_IWUSR,S_IRGRP,S_IWGRP,S_IROTH, andS_IWOTHfile permission bits. Just those six. Not a bit more. periodt. - If
fildesreferences a typed memory object, the behavior offchmod()is unspecified. π« (translation: don't do that and expect anything, it's giving chaos) - If
fildesrefers to a socket, the behavior offchmod()is unspecified. same energy. don't. - If
fildesrefers to a STREAM (one that'sfattach()-ed into the file system name space) the call returns successfully, doing nothing. yes literally. it just smiles and nods. π
π RETURN VALUE π
- Slayed? π Upon successful completion,
fchmod()shall return0. - Not slayed? It shall return
-1and seterrnoto indicate the error. (the error is inerrno, go look, it's right there)
π₯ ERRORS π₯
the "shall fail" girlies (these are guaranteed):
EBADFβ Thefildesargument is not an open file descriptor. bestie that fd is not a thing. πEPERMβ The effective user ID does not match the owner of the file and the process does not have appropriate privileges. no permission, no party. βEROFSβ The file referred to byfildesresides on a read-only file system. it said read-only and it MEANT it. π
the "may fail" girlies (sometimes, depending):
EINTRβ Thefchmod()function was interrupted by a signal. rude, honestly. π€EINVALβ The value of themodeargument is invalid. that mode is not giving what it needs to give. π«EINVALβ Thefildesargument refers to a pipe and the implementation disallows execution offchmod()on a pipe. (yesEINVALshows up twice, that's not a typo, both of them are real, we don't merge them π )
Also: the following sections are informative. meaning: cute context, not requirements. noted. π«Ά
πΈ EXAMPLES πΈ
Changing the Current Permissions for a File
Okay so this example is chef's kiss, it shows you how to change the permissions for a file named /home/cnd/mod1 so that the owner and group have read/write/execute permissions, but the world only has read/write permissions. here's the whole thing, verbatim, no cap:
#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);
look at those flags. S_IRWXU | S_IRWXG | S_IROTH | S_IWOTH. we love a bitwise moment. π
π§ APPLICATION USAGE π§
None. literally nothing. we said what we said. π
π RATIONALE π
None. again. nothing. the reasoning is a mystery, the vibes are immaculate. β¨
π FUTURE DIRECTIONS π
None. the future isβ¦ exactly the same. slay. π
π SEE ALSO π
go read these next, bestie, they're all connected, iykyk:
chmod(),chown(),creat(),fcntl(),fstatat(),fstatvfs(),mknod(),open(),read(),write()
Also 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 .
and that's the whole page, bestie π«Ά this manual page came to you from IEEE/The Open Group, dated 2017, and it lives under the name FCHMOD(3POSIX) β that's the source, the version and the date, all folded into one cute little sign-off. bye, love u, go chmod responsibly. π
π¦ where this page comes from
- debian bookworm: manpages-posix-dev 2017a-2 Β· Other
- debian trixie: manpages-posix-dev 2017a-2 Β· Other
- ubuntu jammy: manpages-posix-dev 2017a-2 Β· Other
- ubuntu noble: manpages-posix-dev 2017a-2 Β· Other
- ubuntu resolute: manpages-posix-dev 2017a-2build1 Β· Other
- ubuntu stonking: manpages-posix-dev 2017a-2.1 Β· Other
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms