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_IRUSR
  • S_IWUSR
  • S_IRGRP
  • S_IWGRP
  • S_IROTH
  • S_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() returns 0. slay.
  • otherwise it returns -1 and sets errno to tell you what went wrong. 😭

πŸ’œ ERRORS πŸ’œ

fchmod() shall fail if:

  • EBADF β€” the fildes argument 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 by fildes resides on a read-only file system. frozen. can't touch. 🧊

fchmod() may fail if:

  • EINTR β€” the fchmod() function was interrupted by a signal. rude, honestly. 😀
  • EINVAL β€” the value of the mode argument is invalid.
  • EINVAL β€” the fildes argument refers to a pipe and the implementation disallows execution of fchmod() on a pipe. yes it's EINVAL twice, 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> πŸ“š


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