]>
git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/umask-util.h
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
10 static inline void umaskp(mode_t
*u
) {
14 #define _cleanup_umask_ _cleanup_(umaskp)
16 /* We make use of the fact here that the umask() concept is using only the lower 9 bits of mode_t, although
17 * mode_t has space for the file type in the bits further up. We simply OR in the file type mask S_IFMT to
18 * distinguish the first and the second iteration of the RUN_WITH_UMASK() loop, so that we can run the first
19 * one, and exit on the second. */
21 assert_cc((S_IFMT
& 0777) == 0);
23 #define RUN_WITH_UMASK(mask) \
24 for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
25 FLAGS_SET(_saved_umask_, S_IFMT); \
26 _saved_umask_ &= 0777)
28 #define BLOCK_WITH_UMASK(mask) \
29 _unused_ _cleanup_umask_ mode_t _saved_umask_ = umask(mask);