setmode(3bsd)
π setmode(3bsd) π
okay bestie, so this is a LOCAL manual page for getmode, setmode β the two little icons that modify mode bits β¨
π NAME π
getmode, setmode β modify mode bits π
π LIBRARY π
Utility functions from BSD systems (libbsd, -lbsd) π¦
β¨ SYNOPSIS β¨
#include <unistd.h>
(See libbsd(7) for include usage.)
void *
setmode(const char *mode_str);
mode_t
getmode(const void *set, mode_t mode);
π DESCRIPTION π
so. setmode() is the girl who takes a string representation of a file mode change, compiles it into binary form, and hands you back an abstract representation you can then pass to getmode(). that string can be a numeric (octal) one or a symbolic string in the form chmod(1) accepts β and it can represent either an exact mode to set or a change to make to the existing mode. either way, slay π
then getmode() takes the file permission bits you gave it as mode, adjusts them according to that compiled change representation set, and returns the adjusted mode. important: only the permission bits get altered, but other parts of the file mode β the type especially β may be examined. so like, it's peeking but not touching, iykyk π
now here's the tea π because some of the possible symbolic values are defined relative to the file creation mask, setmode() may call umask(2), temporarily changing the mask. if that happens, the file creation mask will be restored before setmode() returns. BUT β and this is the part where you need to listen β if the calling program changes the value of its file creation mask after calling setmode(), then setmode() must be called again to recompile the mode string, if getmode() is to modify future file modes correctly. no shortcuts bestie π
if the mode you passed to setmode() is invalid, setmode() returns NULL. that's it, that's the whole vibe check π
and the value returned from setmode() is obtained from malloc() and should be returned to the system with free() when the program is done with it β generally after a call to getmode(). free your girls, periodt π«Ά
π EXAMPLES π
the effects of the shell command βchmod a+x myscript.shβ can be duplicated as follows:
const char *file = "myscript.sh";
struct stat st;
mode_t newmode;
stat(file, &st);
newmode = getmode(setmode("a+x"), st.st_mode);
chmod(file, newmode);
iconic behavior honestly π
π ERRORS π
setmode() may fail and set errno for any of the errors specified for the library routines malloc(3) or strtol(3). and on top of that, setmode() will fail and set errno to:
[EINVAL]β Themodeargument does not represent a valid mode. (invalid input, we don't know her π)
π SEE ALSO π
chmod(1), stat(2), umask(2), malloc(3)
π§ HISTORY π§
getmode() and setmode() first appeared in 4.4BSD. ancient. vintage. legendary. β
π BUGS π
the type of set should really be some opaque struct type used only by these functions rather than void *. yeah. we know. we're all thinking it π
and that's the whole page, bestie!! this one came to you from the good people at Debian, dated January 4, 2009 β so yeah, she's been serving accurate documentation since before some of us could read. mwah πβ¨π
π¦ where this page comes from
- alpine 3.22: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.23: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- alpine 3.24: libbsd-doc 0.12.2-r0 Β· BSD-3-Clause
- arch rolling: libbsd 0.12.2-2 Β· custom
- debian bookworm: libbsd-dev 0.11.7-2
- debian trixie: libbsd-dev 0.12.2-2
- epel 10: libbsd-devel 0.12.2-4.el10_0 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- epel 9: libbsd-devel 0.12.2-1.el9 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 43: libbsd-devel 0.12.2-6.fc43 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- fedora 44: libbsd-devel 0.12.2-7.fc44 Β· Beerware AND BSD-2-Clause AND BSD-3-Clause AND ISC AND libutil-David-Nugent AND MIT AND LicenseRef-Fedora-Public-Domain
- nixos 26.05: libbsd 0.12.2
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- opensuse-leap 16.0: libbsd-devel 0.11.7-160000.3.2 Β· BSD-3-Clause
- ubuntu noble: libbsd-dev 0.12.1-1build1
- ubuntu noble: libbsd-dev 0.12.1-1build1.1
- ubuntu questing: libbsd-dev 0.12.2-2build1
- ubuntu resolute: libbsd-dev 0.12.2-2build2
- ubuntu stonking: libbsd-dev 0.12.2-3
- Copyright (c) 1989, 1991, 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms