#include <core/wincompat.hpp>
#include <util/TimePoint.hpp>
#include <util/path.hpp>
+#include <util/process.hpp>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
// in the cache directory should be affected by the configured umask and that
// no other files and directories should.
if (config.umask()) {
- original_umask = Util::set_umask(*config.umask());
+ original_umask = util::set_umask(*config.umask());
}
}
-// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
+#include <util/process.hpp>
#include <cstdlib>
Util::set_cloexec_flag(*fd);
#ifndef _WIN32
- fchmod(*fd, 0666 & ~Util::get_umask());
+ fchmod(*fd, 0666 & ~util::get_umask());
#endif
}
#pragma once
-#include <Util.hpp>
+#include <util/process.hpp>
#include <sys/stat.h>
#include <sys/types.h>
{
#ifndef _WIN32
if (new_umask) {
- m_saved_umask = Util::set_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
- Util::set_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]
return result.empty() ? "." : result;
}
-mode_t
-get_umask()
-{
- return g_umask;
-}
-
std::optional<size_t>
is_absolute_path_with_prefix(std::string_view path)
{
#endif
}
-mode_t
-set_umask(mode_t mask)
-{
- g_umask = mask;
- return umask(mask);
-}
-
std::vector<std::string_view>
split_into_views(std::string_view string,
const char* separators,
// resolve to the same file as `path`.
std::string get_relative_path(std::string_view dir, std::string_view path);
-// Get process umask.
-mode_t get_umask();
-
// Determine if `path` is an absolute path with prefix, returning the split
// point.
std::optional<size_t> is_absolute_path_with_prefix(std::string_view path);
// 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);
-
// Return size change in KiB between `old_stat` and `new_stat`.
inline int64_t
size_change_kibibyte(const Stat& old_stat, const Stat& new_stat)
if (fall_back_to_original_compiler) {
if (original_umask) {
- Util::set_umask(*original_umask);
+ util::set_umask(*original_umask);
}
auto execv_argv = saved_orig_args.to_argv();
execute_noreturn(execv_argv.data(), saved_temp_dir);
#include <TemporaryFile.hpp>
#include <ThreadPool.hpp>
#include <UmaskScope.hpp>
+#include <Util.hpp>
#include <assertions.hpp>
#include <ccache.hpp>
#include <core/CacheEntry.hpp>
#include <util/TextTable.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
+#include <util/process.hpp>
#include <util/string.hpp>
#ifdef INODE_CACHE_SUPPORTED
fs::create_hard_link(source, dest, ec);
if (!ec) {
#ifndef _WIN32
- if (chmod(dest.c_str(), 0444 & ~Util::get_umask()) != 0) {
+ if (chmod(dest.c_str(), 0444 & ~util::get_umask()) != 0) {
LOG("Failed to chmod {}: {}", dest.c_str(), strerror(errno));
}
#endif
environment.cpp
file.cpp
path.cpp
+ process.cpp
string.cpp
zstd.cpp
)
--- /dev/null
+// Copyright (C) 2023 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#include "process.hpp"
+
+#include <core/wincompat.hpp>
+
+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;
+}();
+
+} // namespace
+
+namespace util {
+
+mode_t
+get_umask()
+{
+ return g_umask;
+}
+
+mode_t
+set_umask(mode_t mask)
+{
+ g_umask = mask;
+ return umask(mask);
+}
+
+} // namespace util
--- /dev/null
+// Copyright (C) 2023 Joel Rosdahl and other contributors
+//
+// See doc/AUTHORS.adoc for a complete list of contributors.
+//
+// This program is free software; you can redistribute it and/or modify it
+// under the terms of the GNU General Public License as published by the Free
+// Software Foundation; either version 3 of the License, or (at your option)
+// any later version.
+//
+// This program is distributed in the hope that it will be useful, but WITHOUT
+// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
+// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
+// more details.
+//
+// You should have received a copy of the GNU General Public License along with
+// this program; if not, write to the Free Software Foundation, Inc., 51
+// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+
+#pragma once
+
+#include <sys/stat.h>
+
+namespace util {
+
+// Get process umask.
+mode_t get_umask();
+
+// Set process umask. Returns the previous mask.
+mode_t set_umask(mode_t mask);
+
+} // namespace util