UMASK(3POSIX)
π UMASK(3POSIX) β the POSIX Programmer's Manual, bestie edition
okay so quick lil vibe check before we get into it: this page is part of the POSIX Programmer's Manual. The Linux implementation of this interface may differ (so like, go peek at the corresponding Linux manual page for the tea on Linux behavior), or honestly the interface might not even be implemented on Linux at all. no cap. π
β¨ NAME β¨
umask β set and get the file mode creation mask
π SYNOPSIS π
#include <sys/stat.h>
mode_t umask(mode_t cmask);
π¦ DESCRIPTION π¦
okay so the umask() function shall set the file mode creation mask of the process to cmask, and then hand you back the previous value of that mask. It's giving "here's the old one, I'm keeping the new one." π
Only the file permission bits of cmask are actually used (peep <sys/stat.h> for those). The meaning of all the other bits? implementation-defined, bestie. not our problem, not our business. π€·
So what even is the file mode creation mask of the process? It's the thing that turns off permission bits in the mode argument you supply when you call any of these lil guys:
open(),openat(),creat(),mkdir(),mkdirat(),mkfifo(), andmkfifoat()mknod(),mknodat()mq_open()sem_open()
And the rule is iconic and simple: bit positions that are set in cmask get cleared in the mode of the created file. that's it, that's the whole mechanic. β¨
π RETURN VALUE π
The file permission bits in the value returned by umask() shall be the previous value of the file mode creation mask. the state of any other bits in that value is unspecified β EXCEPT (and this part is important, don't skip it) a subsequent call to umask() with the returned value as cmask shall leave the state of the mask the same as its state before the first call, including any unspecified use of those bits. so it round-trips. slay. π«Ά
π ERRORS π
No errors are defined.
The following sections are informative.
πΈ EXAMPLES πΈ
None.
π APPLICATION USAGE π
None.
π RATIONALE π
okay so the lore: unsigned argument and return types for umask() were proposed at some point. and the glow-up? the return type and the argument were both changed to mode_t. periodt.
Also, historical implementations have made use of additional bits in cmask for their own implementation-defined purposes. so adding the text that the meaning of other bits of the field is implementation-defined is literally what lets those implementations conform to this volume of POSIX.1β2017. they get to keep their extra bits AND be compliant. main character energy fr fr. π₯
β FUTURE DIRECTIONS β
None.
π§ SEE ALSO π§
creat(), exec, mkdir(), mkfifo(), mknod(), mq_open(), open(), sem_open()
The Base Definitions volume of POSIX.1β2017, <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 .
fr if you spot a typo it's almost definitely a conversion oopsie, not a you problem π
okay that's the whole page, bestie β mwah π this was IEEE/The Open Group, 2017, and the page was UMASK(3POSIX). go forth and mask those modes 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