From edd8f19a1b8bd8a6dc98388ef443d2628e44a831 Mon Sep 17 00:00:00 2001 From: Andreas Kling Date: Sat, 1 Jan 2022 19:49:35 +0100 Subject: LibCore: Add Core::UmaskScope to set and unset a temporary umask --- Userland/Libraries/LibCore/UmaskScope.h | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) create mode 100644 Userland/Libraries/LibCore/UmaskScope.h (limited to 'Userland/Libraries/LibCore') 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 + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include +#include + +#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 {}; +}; + +} -- cgit v1.2.3