-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2022 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
using nonstd::string_view;
-namespace {
-
-#ifndef _WIN32
-mode_t
-get_umask()
-{
- static bool mask_retrieved = false;
- static mode_t mask;
- if (!mask_retrieved) {
- mask = umask(0);
- umask(mask);
- mask_retrieved = true;
- }
- return mask;
-}
-#endif
-
-} // namespace
-
TemporaryFile::TemporaryFile(string_view path_prefix)
: path(std::string(path_prefix) + ".XXXXXX")
{
Util::set_cloexec_flag(*fd);
#ifndef _WIN32
- fchmod(*fd, 0666 & ~get_umask());
+ fchmod(*fd, 0666 & ~Util::get_umask());
#endif
}
return result.empty() ? "." : result;
}
+#ifndef _WIN32
+mode_t
+get_umask()
+{
+ static bool mask_retrieved = false;
+ static mode_t mask;
+ if (!mask_retrieved) {
+ mask = umask(0);
+ umask(mask);
+ mask_retrieved = true;
+ }
+ return mask;
+}
+#endif
+
void
hard_link(const std::string& oldpath, const std::string& newpath)
{
std::string get_relative_path(nonstd::string_view dir,
nonstd::string_view path);
+#ifndef _WIN32
+// Get process umask.
+mode_t get_umask();
+#endif
+
// Hard-link `oldpath` to `newpath`. Throws `core::Error` on error.
void hard_link(const std::string& oldpath, const std::string& newpath);