// Copyright (C) 2002 Andrew Tridgell
-// Copyright (C) 2009-2022 Joel Rosdahl and other contributors
+// Copyright (C) 2009-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#include "fmtmacros.hpp"
#include <core/wincompat.hpp>
+#include <util/file.hpp>
#ifdef HAVE_UNISTD_H
# include <unistd.h>
logfile_path = config.log_file();
logfile.open(logfile_path, "a");
if (logfile) {
- Util::set_cloexec_flag(fileno(*logfile));
+ util::set_cloexec_flag(fileno(*logfile));
} else {
print_fatal_error_and_exit();
}
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
+#include <util/file.hpp>
#include <util/process.hpp>
#include <cstdlib>
FMT("Failed to create temporary file for {}: {}", path, strerror(errno)));
}
- Util::set_cloexec_flag(*fd);
+ util::set_cloexec_flag(*fd);
#ifndef _WIN32
fchmod(*fd, 0666 & ~util::get_umask());
#endif
}
}
-void
-set_cloexec_flag(int fd)
-{
-#ifndef _WIN32
- int flags = fcntl(fd, F_GETFD, 0);
- if (flags >= 0) {
- fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
- }
-#else
- (void)fd;
-#endif
-}
-
std::vector<std::string_view>
split_into_views(std::string_view string,
const char* separators,
// `core::Error` on error.
void send_to_fd(const Context& ctx, std::string_view text, int fd);
-// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
-void set_cloexec_flag(int fd);
-
// 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)
return {};
}
+void
+set_cloexec_flag(int fd)
+{
+#ifndef _WIN32
+ int flags = fcntl(fd, F_GETFD, 0);
+ if (flags >= 0) {
+ fcntl(fd, F_SETFD, flags | FD_CLOEXEC);
+ }
+#else
+ (void)fd;
+#endif
+}
+
nonstd::expected<void, std::string>
read_fd(int fd, DataReceiver data_receiver)
{
nonstd::expected<void, std::string> rename(const std::string& oldpath,
const std::string& newpath);
+// Set the FD_CLOEXEC on file descriptor `fd`. This is a NOP on Windows.
+void set_cloexec_flag(int fd);
+
// Set atime/mtime of `path`. If `mtime` is std::nullopt, set to the current
// time. If `atime` is std::nullopt, set to what `mtime` specifies.
void set_timestamps(const std::string& path,