summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-01-01 19:49:35 +0100
committerAndreas Kling <kling@serenityos.org>2022-01-02 18:08:02 +0100
commitedd8f19a1b8bd8a6dc98388ef443d2628e44a831 (patch)
tree029783322aa2ce1e20f30a6dbd00ae3d5e29267e
parentc6ce606e47aadd1a9a826f2ddeb7ef346665ad1d (diff)
downloadserenity-edd8f19a1b8bd8a6dc98388ef443d2628e44a831.zip
LibCore: Add Core::UmaskScope to set and unset a temporary umask
-rw-r--r--Userland/Libraries/LibCore/UmaskScope.h30
1 files changed, 30 insertions, 0 deletions
diff --git a/Userland/Libraries/LibCore/UmaskScope.h b/Userland/Libraries/LibCore/UmaskScope.h
new file mode 100644
index 0000000000..f77c22956d
--- /dev/null
+++ b/Userland/Libraries/LibCore/UmaskScope.h
@@ -0,0 +1,30 @@
+/*
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
+ *
+ * SPDX-License-Identifier: BSD-2-Clause
+ */
+
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#pragma once
+
+namespace Core {
+
+class UmaskScope {
+public:
+ explicit UmaskScope(mode_t mask)
+ {
+ m_old_mask = umask(mask);
+ }
+
+ ~UmaskScope()
+ {
+ umask(m_old_mask);
+ }
+
+private:
+ mode_t m_old_mask {};
+};
+
+}