]> git.ipfire.org Git - thirdparty/systemd.git/blob - src/basic/umask-util.h
tree-wide: drop license boilerplate
[thirdparty/systemd.git] / src / basic / umask-util.h
1 /* SPDX-License-Identifier: LGPL-2.1+ */
2 #pragma once
3
4 /***
5 This file is part of systemd.
6
7 Copyright 2010 Lennart Poettering
8 ***/
9
10 #include <stdbool.h>
11 #include <sys/stat.h>
12 #include <sys/types.h>
13
14 #include "macro.h"
15
16 static inline void umaskp(mode_t *u) {
17 umask(*u);
18 }
19
20 #define _cleanup_umask_ _cleanup_(umaskp)
21
22 struct _umask_struct_ {
23 mode_t mask;
24 bool quit;
25 };
26
27 static inline void _reset_umask_(struct _umask_struct_ *s) {
28 umask(s->mask);
29 };
30
31 #define RUN_WITH_UMASK(mask) \
32 for (_cleanup_(_reset_umask_) struct _umask_struct_ _saved_umask_ = { umask(mask), false }; \
33 !_saved_umask_.quit ; \
34 _saved_umask_.quit = true)