// in the cache directory should be affected by the configured umask and that
// no other files and directories should.
if (config.umask()) {
- original_umask = umask(*config.umask());
+ original_umask = Util::set_umask(*config.umask());
}
}
{
#ifndef _WIN32
if (new_umask) {
- m_saved_umask = umask(*new_umask);
+ m_saved_umask = Util::set_umask(*new_umask);
}
#else
(void)new_umask;
# pragma GCC diagnostic push
# pragma GCC diagnostic ignored "-Wmaybe-uninitialized"
# endif
- umask(*m_saved_umask);
+ Util::set_umask(*m_saved_umask);
# if defined(__GNUC__) && !defined(__clang__)
# pragma GCC diagnostic pop
# endif
namespace {
+// Process umask, read and written by get_umask and set_umask.
+mode_t g_umask = [] {
+ const mode_t mask = umask(0);
+ umask(mask);
+ return mask;
+}();
+
// Search for the first match of the following regular expression:
//
// \x1b\[[\x30-\x3f]*[\x20-\x2f]*[Km]
mode_t
get_umask()
{
- const mode_t mask = umask(0);
- umask(mask);
- return mask;
+ return g_umask;
}
void
#endif
}
+mode_t
+set_umask(mode_t mask)
+{
+ g_umask = mask;
+ return umask(mask);
+}
+
void
setenv(const std::string& name, const std::string& value)
{
// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
void set_cloexec_flag(int fd);
+// Set process umask. Returns the previous mask.
+mode_t set_umask(mode_t mask);
+
// Set environment variable `name` to `value`.
void setenv(const std::string& name, const std::string& value);
if (fall_back_to_original_compiler) {
if (original_umask) {
- umask(*original_umask);
+ Util::set_umask(*original_umask);
}
auto execv_argv = saved_orig_args.to_argv();
execute_noreturn(execv_argv.data(), saved_temp_dir);