Config.cpp
Context.cpp
Depfile.cpp
- Fd.cpp
Hash.cpp
Logging.cpp
ProgressBar.cpp
+++ /dev/null
-// Copyright (C) 2021 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 "Fd.hpp"
-
-#include <util/wincompat.hpp>
-
-#ifdef HAVE_UNISTD_H
-# include <unistd.h>
-#endif
-
-bool
-Fd::close()
-{
- return m_fd != -1 && ::close(release()) == 0;
-}
#include "Hash.hpp"
-#include "Fd.hpp"
#include "Logging.hpp"
#include "fmtmacros.hpp"
+#include <util/Fd.hpp>
#include <util/file.hpp>
#include <util/string.hpp>
#include <util/wincompat.hpp>
tl::expected<void, std::string>
Hash::hash_file(const std::string& path)
{
- Fd fd(open(path.c_str(), O_RDONLY | O_BINARY));
+ util::Fd fd(open(path.c_str(), O_RDONLY | O_BINARY));
if (!fd) {
LOG("Failed to open {}: {}", path, strerror(errno));
return tl::unexpected(strerror(errno));
#include "fmtmacros.hpp"
#include <util/DirEntry.hpp>
+#include <util/Fd.hpp>
#include <util/TemporaryFile.hpp>
#include <util/conversion.hpp>
#include <util/file.hpp>
munmap(m_sr, sizeof(SharedRegion));
m_sr = nullptr;
}
- m_fd = Fd(open(inode_cache_file.c_str(), O_RDWR));
+ m_fd = util::Fd(open(inode_cache_file.c_str(), O_RDWR));
if (!m_fd) {
LOG("Failed to open inode cache {}: {}", inode_cache_file, strerror(errno));
return false;
#pragma once
-#include <Fd.hpp>
#include <Hash.hpp>
#include <hashutil.hpp>
#include <util/Duration.hpp>
+#include <util/Fd.hpp>
#include <util/TimePoint.hpp>
#include <cstdint>
const Config& m_config;
util::Duration m_min_age;
- Fd m_fd;
+ util::Fd m_fd;
struct SharedRegion* m_sr = nullptr;
bool m_failed = false;
const pid_t m_self_pid;
#include "Config.hpp"
#include "Context.hpp"
-#include "Fd.hpp"
#include "Logging.hpp"
#include "Win32Util.hpp"
#include "ArgsInfo.hpp"
#include "Context.hpp"
#include "Depfile.hpp"
-#include "Fd.hpp"
#include "File.hpp"
#include "Finalizer.hpp"
#include "Hash.hpp"
#include <core/mainoptions.hpp>
#include <core/types.hpp>
#include <storage/Storage.hpp>
+#include <util/Fd.hpp>
#include <util/TemporaryFile.hpp>
#include <util/UmaskScope.hpp>
#include <util/environment.hpp>
struct GetTmpFdResult
{
- Fd fd;
+ util::Fd fd;
fs::path path;
};
return {std::move(tmp_stdout.fd), std::move(tmp_stdout.path)};
} else {
const auto dev_null_path = util::get_dev_null_path();
- return {Fd(open(dev_null_path, O_WRONLY | O_BINARY)), dev_null_path};
+ return {util::Fd(open(dev_null_path, O_WRONLY | O_BINARY)), dev_null_path};
}
}
#include "Config.hpp"
#include "Context.hpp"
-#include "Fd.hpp"
#include "File.hpp"
#include "Logging.hpp"
#include "Util.hpp"
-// 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.
//
#pragma once
-#include "Fd.hpp"
-
#include <core/Result.hpp>
#include <functional>
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/DirEntry.hpp>
+#include <util/Fd.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
{
ASSERT(m_ctx.args_info.dependency_target);
- Fd fd(open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
+ util::Fd fd(
+ open(path.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!fd) {
throw WriteError(FMT("Failed to open {} for writing", path));
}
#pragma once
-#include "Fd.hpp"
-
#include <Hash.hpp>
#include <core/Result.hpp>
#include <core/exceptions.hpp>
#include "mainoptions.hpp"
#include <Config.hpp>
-#include <Fd.hpp>
#include <File.hpp>
#include <Hash.hpp>
#include <InodeCache.hpp>
#include <fmtmacros.hpp>
#include <storage/Storage.hpp>
#include <storage/local/LocalStorage.hpp>
+#include <util/Fd.hpp>
#include <util/TemporaryFile.hpp>
#include <util/TextTable.hpp>
#include <util/UmaskScope.hpp>
case CHECKSUM_FILE: {
util::XXH3_128 checksum;
- Fd fd(arg == "-" ? STDIN_FILENO : open(arg.c_str(), O_RDONLY));
+ util::Fd fd(arg == "-" ? STDIN_FILENO : open(arg.c_str(), O_RDONLY));
if (fd) {
util::read_fd(*fd, [&checksum](auto data) { checksum.update(data); });
const auto digest = checksum.digest();
#include "Config.hpp"
#include "Context.hpp"
-#include "Fd.hpp"
#include "Logging.hpp"
#include "SignalHandler.hpp"
#include "Util.hpp"
#include <core/exceptions.hpp>
#include <fmtmacros.hpp>
#include <util/DirEntry.hpp>
+#include <util/Fd.hpp>
#include <util/TemporaryFile.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
const std::string& temp_dir);
int
-execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
+execute(Context& ctx,
+ const char* const* argv,
+ util::Fd&& fd_out,
+ util::Fd&& fd_err)
{
LOG("Executing {}", util::format_argv_for_logging(argv));
// Execute a compiler backend, capturing all output to the given paths the full
// path to the compiler to run is in argv[0].
int
-execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err)
+execute(Context& ctx,
+ const char* const* argv,
+ util::Fd&& fd_out,
+ util::Fd&& fd_err)
{
LOG("Executing {}", util::format_argv_for_logging(argv));
#pragma once
-#include "Fd.hpp"
+#include <util/Fd.hpp>
#include <filesystem>
#include <optional>
class Context;
-int execute(Context& ctx, const char* const* argv, Fd&& fd_out, Fd&& fd_err);
+int execute(Context& ctx,
+ const char* const* argv,
+ util::Fd&& fd_out,
+ util::Fd&& fd_err);
void execute_noreturn(const char* const* argv, const std::string& temp_dir);
clone_file(const std::string& src, const std::string& dest, bool via_tmp_file)
{
# if defined(__linux__)
- Fd src_fd(open(src.c_str(), O_RDONLY));
+ util::Fd src_fd(open(src.c_str(), O_RDONLY));
if (!src_fd) {
throw core::Error(FMT("{}: {}", src, strerror(errno)));
}
- Fd dest_fd;
+ util::Fd dest_fd;
std::string tmp_file;
if (via_tmp_file) {
auto temp_file =
dest_fd = std::move(temp_file.fd);
tmp_file = std::move(temp_file.path);
} else {
- dest_fd =
- Fd(open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
+ dest_fd = util::Fd(
+ open(dest.c_str(), O_WRONLY | O_CREAT | O_TRUNC | O_BINARY, 0666));
if (!dest_fd) {
throw core::Error(FMT("{}: {}", src, strerror(errno)));
}
-// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2023 Joel Rosdahl and other contributors
//
// See doc/AUTHORS.adoc for a complete list of contributors.
//
#pragma once
-#include "NonCopyable.hpp"
-#include "assertions.hpp"
+#include <NonCopyable.hpp>
+#include <assertions.hpp>
+#include <util/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+# include <unistd.h>
+#endif
+
+namespace util {
class Fd : NonCopyable
{
return *this;
}
+inline bool
+Fd::close()
+{
+ return m_fd != -1 && ::close(release()) == 0;
+}
+
inline int
Fd::release()
{
m_fd = -1;
return fd;
}
+
+} // namespace util
#pragma once
-#include <Fd.hpp>
+#include <util/Fd.hpp>
#include <third_party/tl/expected.hpp>
#include "file.hpp"
-#include <Fd.hpp>
#include <Finalizer.hpp>
#include <Logging.hpp>
#include <Win32Util.hpp>
#include <fmtmacros.hpp>
#include <util/Bytes.hpp>
#include <util/DirEntry.hpp>
+#include <util/Fd.hpp>
#include <util/TemporaryFile.hpp>
#include <util/expected.hpp>
#include <util/file.hpp>
#include "../src/InodeCache.hpp"
#include "TestUtil.hpp"
-#include <Fd.hpp>
+#include <util/Fd.hpp>
#include <util/file.hpp>
#include <util/path.hpp>
bool
inode_cache_available()
{
- Fd fd(open(util::actual_cwd().c_str(), O_RDONLY));
+ util::Fd fd(open(util::actual_cwd().c_str(), O_RDONLY));
return fd && InodeCache::available(*fd);
}
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
#include "../src/Config.hpp"
-#include "../src/Fd.hpp"
#include "../src/Util.hpp"
#include "../src/fmtmacros.hpp"
#include "TestUtil.hpp"
-// 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.
//
// this program; if not, write to the Free Software Foundation, Inc., 51
// Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
-#include "../src/Fd.hpp"
#include "../src/Finalizer.hpp"
#include "TestUtil.hpp"
+#include <util/Fd.hpp>
#include <util/wincompat.hpp>
#include "third_party/doctest.h"
#include <utility>
using TestUtil::TestContext;
+using util::Fd;
namespace {
#include "TestUtil.hpp"
-#include <Fd.hpp>
#include <fmtmacros.hpp>
#include <util/Bytes.hpp>
#include <util/DirEntry.hpp>
+#include <util/Fd.hpp>
#include <util/file.hpp>
#include <util/filesystem.hpp>
#include <util/string.hpp>
const char filename[] = "test-file";
- CHECK(util::fallocate(Fd(creat(filename, S_IRUSR | S_IWUSR)).get(), 10000));
+ CHECK(
+ util::fallocate(util::Fd(creat(filename, S_IRUSR | S_IWUSR)).get(), 10000));
CHECK(DirEntry(filename).size() == 10000);
- CHECK(
- util::fallocate(Fd(open(filename, O_RDWR, S_IRUSR | S_IWUSR)).get(), 5000));
+ CHECK(util::fallocate(
+ util::Fd(open(filename, O_RDWR, S_IRUSR | S_IWUSR)).get(), 5000));
CHECK(DirEntry(filename).size() == 10000);
- CHECK(util::fallocate(Fd(open(filename, O_RDWR, S_IRUSR | S_IWUSR)).get(),
- 20000));
+ CHECK(util::fallocate(
+ util::Fd(open(filename, O_RDWR, S_IRUSR | S_IWUSR)).get(), 20000));
CHECK(DirEntry(filename).size() == 20000);
}