Debian Codegraph @

src/basic/umask-util.h

raw
1 /* SPDX-License-Identifier: LGPL-2.1-or-later */
2 #pragma once
3
4 #include <sys/stat.h>
5
6 #include "basic-forward.h"
7
8 static inline void umaskp(mode_t *u) {
9 umask(*u);
10 }
11
12 #define _cleanup_umask_ _cleanup_(umaskp)
13
14 /* We make use of the fact here that the umask() syscall uses only the lower 9 bits of mode_t, although
15 * mode_t has space for the file type in the bits further up. We simply OR in the file type mask S_IFMT to
16 * distinguish the first and the second iteration of the WITH_UMASK() loop, so that we can run the first one,
17 * and exit on the second. */
18
19 assert_cc((S_IFMT & 0777) == 0);
20
21 #define WITH_UMASK(mask) \
22 for (_cleanup_umask_ mode_t _saved_umask_ = umask(mask) | S_IFMT; \
23 FLAGS_SET(_saved_umask_, S_IFMT); \
24 _saved_umask_ &= 0777)
25
26 #define BLOCK_WITH_UMASK(mask) \
27 _unused_ _cleanup_umask_ mode_t _saved_umask_ = umask(mask);