]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
Remove system.hpp, including what’s needed instead
authorJoel Rosdahl <joel@rosdahl.net>
Tue, 6 Jul 2021 19:19:57 +0000 (21:19 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Wed, 7 Jul 2021 07:13:05 +0000 (09:13 +0200)
This is the next step after a57f70eda32e99221de56f5499079b4f00dc2bc5.

88 files changed:
CMakeLists.txt
cmake/GenerateConfigurationFile.cmake
cmake/config.h.in
src/Args.hpp
src/ArgsInfo.hpp
src/AtomicFile.hpp
src/CMakeLists.txt
src/CacheEntryReader.hpp
src/CacheEntryWriter.hpp
src/CacheFile.hpp
src/Checksum.hpp
src/Compression.hpp
src/Compressor.hpp
src/Config.cpp
src/Config.hpp
src/Context.cpp
src/Context.hpp
src/Counters.hpp
src/Decompressor.hpp
src/Digest.hpp
src/Fd.cpp [new file with mode: 0644]
src/Fd.hpp
src/File.hpp
src/Finalizer.hpp
src/FormatNonstdStringView.hpp
src/Hash.cpp
src/Hash.hpp
src/InodeCache.cpp
src/InodeCache.hpp
src/Lockfile.cpp
src/Lockfile.hpp
src/Logging.cpp
src/Logging.hpp
src/Manifest.hpp
src/MiniTrace.cpp
src/MiniTrace.hpp
src/NullCompressor.hpp
src/NullDecompressor.hpp
src/ProgressBar.cpp
src/ProgressBar.hpp
src/Result.cpp
src/Result.hpp
src/ResultDumper.hpp
src/ResultExtractor.cpp
src/ResultExtractor.hpp
src/ResultRetriever.cpp
src/ResultRetriever.hpp
src/SignalHandler.cpp
src/SignalHandler.hpp
src/Stat.cpp
src/Stat.hpp
src/Statistics.hpp
src/ThreadPool.hpp
src/UmaskScope.hpp
src/Util.cpp
src/Util.hpp
src/Win32Util.hpp
src/ZstdCompressor.hpp
src/ZstdDecompressor.hpp
src/argprocessing.cpp
src/assertions.hpp
src/ccache.cpp
src/ccache.hpp
src/cleanup.hpp
src/compopt.cpp
src/compopt.hpp
src/compress.cpp
src/compress.hpp
src/core/wincompat.hpp [new file with mode: 0644]
src/exceptions.hpp
src/execute.cpp
src/execute.hpp
src/hashutil.cpp
src/hashutil.hpp
src/language.hpp
src/macroskip.hpp
src/storage/primary/PrimaryStorage.cpp
src/system.hpp [deleted file]
unittest/TestUtil.cpp
unittest/TestUtil.hpp
unittest/test_Lockfile.cpp
unittest/test_NullCompression.cpp
unittest/test_Stat.cpp
unittest/test_Util.cpp
unittest/test_ZstdCompression.cpp
unittest/test_argprocessing.cpp
unittest/test_bsdmkstemp.cpp
unittest/test_ccache.cpp

index dd1e76e6108a317ab7215507f724720acb2e75b8..d37342296174ca52e84f853c363ed09756c97cc2 100644 (file)
@@ -84,10 +84,6 @@ include(GNUInstallDirs)
 include(GenerateConfigurationFile)
 include(GenerateVersionFile)
 
-if(HAVE_SYS_MMAN_H AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
-  set(INODE_CACHE_SUPPORTED 1)
-endif()
-
 #
 # Third party
 #
index 244a5c585e3cce6e75d494536f6baf77e622dff8..30d50c10dadd26a28ee7a209244c9e030f1b7377 100644 (file)
@@ -98,5 +98,9 @@ endif()
 # alias
 set(MTR_ENABLED "${ENABLE_TRACING}")
 
+if(HAVE_SYS_MMAN_H AND HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
+  set(INODE_CACHE_SUPPORTED 1)
+endif()
+
 configure_file(${CMAKE_SOURCE_DIR}/cmake/config.h.in
                ${CMAKE_BINARY_DIR}/config.h @ONLY)
index ed2e19d49688cd5d002cceed594dc3344d641482..957118f328ad5ab8aa4ce70293568954f142a3a8 100644 (file)
@@ -64,8 +64,6 @@
 #cmakedefine _WIN32_WINNT @_WIN32_WINNT@
 // clang-format on
 
-#define SYSCONFDIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@"
-
 #ifdef __clang__
 #  pragma clang diagnostic pop
 #endif
 #endif
 
 #ifdef _WIN32
+#  define NOMINMAX 1
+#  define STDIN_FILENO 0
+#  define STDOUT_FILENO 1
+#  define STDERR_FILENO 2
+
 #  ifdef _MSC_VER
+#    define PATH_MAX MAX_PATH
 typedef unsigned __int32 mode_t;
 typedef int pid_t;
+
+#    ifndef __MINGW32__
+typedef __int64 ssize_t;
+#    endif
 #  endif
 #endif // _WIN32
 
+// GCC version of a couple of standard C++ attributes.
+#ifdef __GNUC__
+#  define nodiscard gnu::warn_unused_result
+#  define maybe_unused gnu::unused
+#endif
+
+// O_BINARY is needed when reading binary data on Windows, so use it everywhere
+// with a compatibility define for Unix platforms.
+#if !defined(_WIN32) && !defined(O_BINARY)
+#  define O_BINARY 0
+#endif
+
+#ifndef ESTALE
+#  define ESTALE -1
+#endif
+
+#define SYSCONFDIR "@CMAKE_INSTALL_FULL_SYSCONFDIR@"
+
+#cmakedefine INODE_CACHE_SUPPORTED
+
 // Buffer size for I/O operations. Should be a multiple of 4 KiB.
 #define CCACHE_READ_BUFFER_SIZE 65536
index 48fb77df5cdd3e2a2857d2a2c9b5164c9749bda6..a93d1881bb0cd12db9d63f83b3cf0b5d86d6b17c 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "NonCopyable.hpp"
 #include "Util.hpp"
 
index 4d9eaf3942fff7bbc65027d9d9f62de47311b9d3..6e9ea823b1f62bda816aa11747476feb2a5ffb85 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Args.hpp"
 
 #include <string>
index 118c310b4c20d910e22109a6f25c02a6a89e60ed..9dba4181f60d8048db2f8e28fe959cefd91429bf 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,8 @@
 
 #pragma once
 
-#include "system.hpp"
-
+#include <cstdint>
+#include <cstdio>
 #include <string>
 #include <vector>
 
index ed64aaa1a05d3d113e1b8d156bafac7110e45e1d..9b60b21096567b01c65d99e9dd25a9add74d34b7 100644 (file)
@@ -12,11 +12,11 @@ set(
   Counters.cpp
   Decompressor.cpp
   Depfile.cpp
+  Fd.cpp
   Hash.cpp
   Lockfile.cpp
   Logging.cpp
   Manifest.cpp
-  MiniTrace.cpp
   NullCompressor.cpp
   NullDecompressor.cpp
   ProgressBar.cpp
@@ -48,6 +48,10 @@ if(INODE_CACHE_SUPPORTED)
   list(APPEND source_files InodeCache.cpp)
 endif()
 
+if(MTR_ENABLED)
+  list(APPEND source_files MiniTrace.cpp)
+endif()
+
 if(WIN32)
   list(APPEND source_files Win32Util.cpp)
 endif()
index 37db80f5e62ba54f98917d57f0e27ab26900e524..ba98a66e56b774aae2f5a850c7562dd47b0b7a56 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Checksum.hpp"
 #include "Decompressor.hpp"
 #include "Util.hpp"
 
+#include <cstdint>
+#include <cstdio>
 #include <memory>
 
 // This class knows how to read a cache entry with a common header and a
index dc9226f61ac3452eaa33870c2782612d1abb8c0e..ccbbdff7d4548e912645073834ae823459e605f5 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Checksum.hpp"
 #include "Compressor.hpp"
 #include "Util.hpp"
 
+#include <cstdint>
+#include <cstdio>
 #include <memory>
 
 // This class knows how to write a cache entry with a common header and a
index 1cea40880bea2cee8fb12c61f2aa88adf420bc2c..8993f5becfb285387f2c98431337d19609ef8c4f 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Stat.hpp"
 
 #include "third_party/nonstd/optional.hpp"
index e2c6274f3a9ad70d04987c9701a8c39cb05019b7..ee8bcc23bc5e322bf13dc1739652afb2940d4f1c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #ifdef USE_XXH_DISPATCH
 #  include "third_party/xxh_x86dispatch.h"
 #else
 #  include "third_party/xxhash.h"
 #endif
 
+#include <cstdint>
+
 class Checksum
 {
 public:
index 24e1746bb395ae56b87b81ef68ba3b2d48f64200..42721e9790f43e90fa8641a270bd8aca39a42293 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,7 @@
 
 #pragma once
 
-#include "system.hpp"
-
+#include <cstdint>
 #include <string>
 
 class Config;
index 3295874c5084323cc43f55e2283383ab1d4db243..5588dada1843ca137b52e9e9bbef2be13c65716f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Compression.hpp"
 
+#include <cstdint>
+#include <cstdio>
 #include <memory>
 
 class Compressor
index 7eed171f1d1456069ac9eb4592c425022c556f73..937663e01d83b41ccc6ace5c0d676ca1ad9accde 100644 (file)
 #include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 #include <util/string_utils.hpp>
 
 #include "third_party/fmt/core.h"
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 #include <cassert>
 #include <fstream>
 using nonstd::nullopt;
 using nonstd::optional;
 
+#if defined(_MSC_VER)
+#  define DLLIMPORT __declspec(dllimport)
+#else
+#  define DLLIMPORT
+#endif
+
+DLLIMPORT extern char** environ;
+
 namespace {
 
 enum class ConfigItem {
index 06069bd18dab98710110648825833d4372e76387..e3b822944af3005d7cd149031a980c671cabd8a0 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "NonCopyable.hpp"
 #include "Util.hpp"
 
 #include "third_party/nonstd/optional.hpp"
 
+#include <cstdint>
 #include <functional>
 #include <limits>
 #include <string>
index d61a68b419d1b24709deea6ecc166227d51148b1..ff5ce124114024c90426d201fcd5f73cfc92ff4e 100644 (file)
 #include "Util.hpp"
 #include "hashutil.hpp"
 
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 #include <string>
 #include <vector>
index 856428b4e55699a39d88ed48a8ccd90c9eef9c6e..d0a7e8f45b3a23268afcfaf16f43d08534b8a0d8 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Args.hpp"
 #include "ArgsInfo.hpp"
 #include "Config.hpp"
@@ -39,6 +37,7 @@
 #include "third_party/nonstd/optional.hpp"
 #include "third_party/nonstd/string_view.hpp"
 
+#include <ctime>
 #include <string>
 #include <unordered_map>
 #include <vector>
index d19227b5bffefc63c775a52355dcd81de8a7b996..cb2837fbbf051bbae330ea2be346cb4d51eca452 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
+#include "Statistic.hpp"
 
+#include <cstddef>
+#include <cstdint>
 #include <vector>
 
-enum class Statistic;
-
 // A simple wrapper around a vector of integers used for the statistics
 // counters.
 class Counters
index 59558898b8dd8f394fc3e2b8ddb2ffb02aa28fca..44a2ae8e657ef969ad79859c0c7439a3dc4c5a18 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Compression.hpp"
 
+#include <cstdio>
 #include <memory>
 
 class Decompressor
index d219d51742735bddc06882a152e6d129865f88b5..189b537692603d66090f676a25f63c54c903d024 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Util.hpp"
 
 #include "third_party/fmt/core.h"
 
+#include <cstdint>
 #include <string>
 
 // Digest represents the binary form of the final digest (AKA hash or checksum)
diff --git a/src/Fd.cpp b/src/Fd.cpp
new file mode 100644 (file)
index 0000000..0828258
--- /dev/null
@@ -0,0 +1,31 @@
+// 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 <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+bool
+Fd::close()
+{
+  return m_fd != -1 && ::close(release()) == 0;
+}
index 6316e45cedebdac0d48313755b84b106556708be..3a47278c03714b299576e548010d384c64f43567 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "NonCopyable.hpp"
 #include "assertions.hpp"
 
@@ -87,12 +85,6 @@ Fd::operator=(Fd&& other_fd) noexcept
   return *this;
 }
 
-inline bool
-Fd::close()
-{
-  return m_fd != -1 && ::close(release()) == 0;
-}
-
 inline int
 Fd::release()
 {
index f8f6c0be48421ad6bfc83dbc70a77dabf5b2a8de..fe3206f487819e3b11c63633148bcba16d45cc7b 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "NonCopyable.hpp"
 
+#include <cstdio>
 #include <string>
 
 class File : public NonCopyable
index 74f6b781fd816782e6a51b0f99e62e5ee9bc075a..c5d2033c1d45ab2b6aea7713516543e4d2bec29d 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include <functional>
 
 class Finalizer
index 0770a901218194f5605ee0bdb44da493e89e7042..4834dc41e6f49088a714edaf269f8b0eea3c95e1 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/fmt/core.h"
 #include "third_party/nonstd/string_view.hpp"
 
index 61cc5a3e734b3fc59bcbb66b689d8e8144b211e5..2eb491dc966d7243951cd20eb700c9018f042b93 100644 (file)
 #include "Logging.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 using nonstd::string_view;
 
 const string_view HASH_DELIMITER("\000cCaChE\000", 8);
index d2686aff2cdbd81b0e5e2529438a5972fd696228..02c5a4d1227fd4d52cf90018f2cd3f3c998e0664 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Digest.hpp"
 
 #include "third_party/blake3/blake3.h"
 #include "third_party/nonstd/string_view.hpp"
 
+#include <cstdint>
+#include <cstdio>
+
 // This class represents a hash state.
 class Hash
 {
index 34f5577d4bfabf1678b045cc644846f17844c3c8..815e6aba6bab56df6e5400de17e7c159ff326a24 100644 (file)
@@ -19,6 +19,7 @@
 #include "InodeCache.hpp"
 
 #include "Config.hpp"
+#include "Digest.hpp"
 #include "Fd.hpp"
 #include "Finalizer.hpp"
 #include "Hash.hpp"
 #include "Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <fcntl.h>
 #include <libgen.h>
 #include <sys/mman.h>
+#include <unistd.h>
 
 #include <atomic>
 #include <type_traits>
@@ -63,7 +66,7 @@ const uint32_t k_num_entries = 4;
 
 static_assert(Digest::size() == 20,
               "Increment version number if size of digest is changed.");
-static_assert(IS_TRIVIALLY_COPYABLE(Digest),
+static_assert(std::is_trivially_copyable<Digest>::value,
               "Digest is expected to be trivially copyable.");
 
 static_assert(
index 9ef330afad33acd428b4fe2c10ab31055bac2a5c..a4a272972cb2086375965f266b71e4a6621734f3 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
-#include "config.h"
-
+#include <cstdint>
 #include <functional>
 #include <string>
 
index 209b0aac144b4ead1a0ded4a38a89addb29c957a..b0e2a82d25da67bc5f39e7fd21e8ee3697335abc 100644 (file)
 
 #include "Logging.hpp"
 #include "Util.hpp"
+#include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
-#ifdef _WIN32
-#  include "Win32Util.hpp"
-#endif
+#include <core/wincompat.hpp>
 
 #include "third_party/fmt/core.h"
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 #include <sstream>
 #include <thread>
 
+// AIX/PASE does not properly define usleep within its headers. However, the
+// function is available in libc.a.
+#ifdef _AIX
+extern "C" int usleep(useconds_t);
+#endif
+
 namespace {
 
 #ifndef _WIN32
@@ -221,3 +230,13 @@ Lockfile::~Lockfile()
 #endif
   }
 }
+
+bool
+Lockfile::acquired() const
+{
+#ifndef _WIN32
+  return m_acquired;
+#else
+  return m_handle != INVALID_HANDLE_VALUE;
+#endif
+}
index 78baed81e78e9afdba60b311fa6b6109cab43c1d..309c0c4aa39f521027196d552a5a1b83e54cfa82 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,7 @@
 
 #pragma once
 
-#include "system.hpp"
-
+#include <cstdint>
 #include <string>
 
 class Lockfile
@@ -40,16 +39,6 @@ private:
 #ifndef _WIN32
   bool m_acquired = false;
 #else
-  HANDLE m_handle = nullptr;
+  void* m_handle = nullptr;
 #endif
 };
-
-inline bool
-Lockfile::acquired() const
-{
-#ifndef _WIN32
-  return m_acquired;
-#else
-  return m_handle != INVALID_HANDLE_VALUE;
-#endif
-}
index c6590d88e7856ea64091362c77ae8586fb53ed4e..45a785a95f4cfde769954cfbb6c017c5fd46176c 100644 (file)
 #include "Config.hpp"
 #include "File.hpp"
 #include "Util.hpp"
+#include "Win32Util.hpp"
 #include "exceptions.hpp"
 #include "execute.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #ifdef HAVE_SYSLOG_H
 #  include <syslog.h>
 #endif
 #  endif
 #endif
 
-#ifdef _WIN32
-#  include <psapi.h>
-#  include <sys/locking.h>
-#  include <tchar.h>
-#endif
-
 using nonstd::string_view;
 
 namespace {
index 5c780ec15cd27121cd01327412d743e88185a87e..7ed70faefcc88bc5784fb384aaabfe7859afca49 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "FormatNonstdStringView.hpp"
 
 #include "third_party/fmt/core.h"
index addf17ec4f83a285c8823bb2e031bc0abd9066eb..0230c707a85b8fe9fb5e369dae95bdbaec71f8ec 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/nonstd/optional.hpp"
 
+#include <cstdint>
+#include <cstdio>
+#include <ctime>
 #include <string>
 #include <unordered_map>
 
index f593caa9998a82efd2cd56bff908bbfdcfd1f500..07f495ad7b31a527d213b805fe3c07a3e7419ad6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 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 "system.hpp"
+#include "MiniTrace.hpp"
 
-#ifdef MTR_ENABLED
+#include "ArgsInfo.hpp"
+#include "TemporaryFile.hpp"
+#include "Util.hpp"
+#include "fmtmacros.hpp"
 
-#  include "ArgsInfo.hpp"
-#  include "MiniTrace.hpp"
-#  include "TemporaryFile.hpp"
-#  include "Util.hpp"
-#  include "fmtmacros.hpp"
+#include <core/wincompat.hpp>
 
-#  ifdef HAVE_SYS_TIME_H
-#    include <sys/time.h>
-#  endif
+#ifdef HAVE_SYS_TIME_H
+#  include <sys/time.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
 
 namespace {
 
 std::string
 get_system_tmp_dir()
 {
-#  ifndef _WIN32
+#ifndef _WIN32
   const char* tmpdir = getenv("TMPDIR");
   if (tmpdir) {
     return tmpdir;
   }
-#  else
+#else
   static char dirbuf[PATH_MAX];
   DWORD retval = GetTempPath(PATH_MAX, dirbuf);
   if (retval > 0 && retval < PATH_MAX) {
     return dirbuf;
   }
-#  endif
+#endif
   return "/tmp";
 }
 
 double
 time_seconds()
 {
-#  ifdef HAVE_GETTIMEOFDAY
+#ifdef HAVE_GETTIMEOFDAY
   struct timeval tv;
   gettimeofday(&tv, nullptr);
   return (double)tv.tv_sec + (double)tv.tv_usec / 1000000.0;
-#  else
+#else
   return (double)time(nullptr);
-#  endif
+#endif
 }
 
 } // namespace
@@ -89,5 +92,3 @@ MiniTrace::~MiniTrace()
   }
   Util::unlink_tmp(m_tmp_trace_file);
 }
-
-#endif
index 25d88645813283c5f7d4cc192c14a3869e9d901a..76aae38105051b107f409ccc134f453b3eaba4b7 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/minitrace.h"
 
-#ifdef MTR_ENABLED
-
-#  include <string>
+#include <string>
 
 struct ArgsInfo;
 
@@ -40,5 +36,3 @@ private:
   std::string m_tmp_trace_file;
   std::string m_start_time;
 };
-
-#endif
index 9a4fcd16db9e9912991459344236ddc14897d6d6..e7abe29f8e969ea7fa6bc6a2e886c9ba2f85469c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Compressor.hpp"
 #include "NonCopyable.hpp"
 
+#include <cstdio>
+
 // A compressor of an uncompressed stream.
 class NullCompressor : public Compressor, NonCopyable
 {
index 514ed7d7cf573389432ff00ae86f21baa563ccc9..68ccf88229098055b2bf504b18bd8d63a1323263 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Decompressor.hpp"
 #include "NonCopyable.hpp"
 
+#include <cstdio>
+
 // A decompressor of an uncompressed stream.
 class NullDecompressor : public Decompressor, NonCopyable
 {
index c7b219e02de40781582658b473309a58c2f96a17..99a37a088cc1dc4ada238ce65290f36dbb7b72f9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/fmt/core.h"
 
-#ifndef _WIN32
+#ifdef _WIN32
+#else
 #  include <sys/ioctl.h>
 #endif
 
 #  include <termios.h>
 #endif
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 
 namespace {
index 8aefa897d4e6170d6419c8ca92dbdf16f918531d..1be38020aa645b28e6976576e66e59e8bc667a0f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,8 @@
 
 #pragma once
 
-#include "system.hpp"
-
+#include <cstddef>
+#include <cstdint>
 #include <string>
 
 class ProgressBar
index 4fd15483ed832419628c9d6ee6c43e8131f94296..a5c66fc5812985ff8d9f6ce682c793b562be5be6 100644 (file)
 #include "exceptions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 
 // Result data format
index 7fcfc95b6cd712a6374fcd222a9b2b40c039bae3..67032c58f1d62155a3d75433b6423e895105e0fa 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/nonstd/expected.hpp"
 #include "third_party/nonstd/optional.hpp"
 
+#include <cstdint>
 #include <map>
 #include <string>
 #include <vector>
index 85602d61fcc79e2fd216a20d6ba10035cb43e41d..c48d2ab59c048da404c981f85501f91e9aa8ed72 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Result.hpp"
 
+#include <cstdint>
+#include <cstdio>
+
 // This class dumps information about the result entry to `stream`.
 class ResultDumper : public Result::Reader::Consumer
 {
index e18ae516018132adba68b9a212596e8c0dac3cc3..b46f3000c6f8598f26d043fce31ccb6f0fa02016 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 #include "Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
 ResultExtractor::ResultExtractor(const std::string& directory)
   : m_directory(directory)
 {
index f4b8f3beda8ea44c23bc82f5b0205c547428e44f..0e801ff4a0e87aefcee4bc6c2f0a8a78e53976af 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Fd.hpp"
 #include "Result.hpp"
 
index 0218877c3ab801e65e0f102712a16cc3bea638bf..9eff7125abefea5b7a5b77b0505ae8d44af22749 100644 (file)
 #include "Depfile.hpp"
 #include "Logging.hpp"
 
+#include <core/wincompat.hpp>
+
+#include <fcntl.h>
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 using Result::FileType;
 
 ResultRetriever::ResultRetriever(Context& ctx, bool rewrite_dependency_target)
index 609f15f91a60f193937af31d703cb00d012c155f..a2ab439415a15f66694dd2c04cb255bc36a91279 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Fd.hpp"
 #include "Result.hpp"
 
index 8a07cc7e1a12a11f55564fbc854a00189992f590..9051eeb0dffb432beb48ab98d7efe00b19b9c274 100644 (file)
@@ -24,6 +24,9 @@
 #  include "assertions.hpp"
 
 #  include <signal.h> // NOLINT: sigaddset et al are defined in signal.h
+#  include <sys/types.h>
+#  include <sys/wait.h>
+#  include <unistd.h>
 
 namespace {
 
index 3ef88479dcc1cb24d71065fda28fd14be069521e..603dbe213b60e2ce3879a4f4827659a490b1fd78 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 class Context;
 
 class SignalHandler
index 244fd6f5a911f9c33308fecd63c357846b958fd7..ffd11843d4e3e55a427c0f89c40c4792f9f34eb3 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #include "Stat.hpp"
 
-#ifdef _WIN32
-#  include "Win32Util.hpp"
-
-#  include "third_party/win32/winerror_to_errno.h"
-#endif
-
 #include "Finalizer.hpp"
 #include "Logging.hpp"
+#include "Win32Util.hpp"
+
+#include <core/wincompat.hpp>
+
+#ifdef _WIN32
+#  include <third_party/win32/winerror_to_errno.h>
+#endif
 
 namespace {
 
index 5a046d2ab82503ebddfa502d7639025a750c7149..9cf9a210b5b91fe33e09d9640ff02c0216037ce9 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "exceptions.hpp"
 
+#include <sys/stat.h>
+#include <sys/types.h>
+
 #include <string>
 
+#ifdef _WIN32
+#  ifndef S_IFIFO
+#    define S_IFIFO 0x1000
+#  endif
+#  ifndef S_IFBLK
+#    define S_IFBLK 0x6000
+#  endif
+#  ifndef S_IFLNK
+#    define S_IFLNK 0xA000
+#  endif
+#  ifndef S_ISREG
+#    define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
+#  endif
+#  ifndef S_ISDIR
+#    define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
+#  endif
+#  ifndef S_ISFIFO
+#    define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
+#  endif
+#  ifndef S_ISCHR
+#    define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
+#  endif
+#  ifndef S_ISLNK
+#    define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
+#  endif
+#  ifndef S_ISBLK
+#    define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
+#  endif
+#endif
+
 class Stat
 {
 public:
index 6e5917b43e00c5ea8f0d9495734de1df1f05475b..ef7087900e45db0b802f38529a69fc5905da6fa3 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Counters.hpp"
-#include "Statistic.hpp" // Any reasonable use of Statistics requires the Statistic enum.
 
 #include "third_party/nonstd/optional.hpp"
 
+#include <ctime>
 #include <functional>
-#include <sstream>
 #include <string>
 
 class Config;
index 5eee3818210b89b3358941c5c9481ef2c79933fd..fa46538259cb4eb7066b80568afe3b020cde8b0f 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include <condition_variable>
 #include <functional>
 #include <limits>
index a641c1f35b377f5c0b6f9052662d17684b0c00ef..2a2f85a74425591a339d5c4412663dc4bd8b9a5b 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/nonstd/optional.hpp"
 
+#include <sys/stat.h>
+#include <sys/types.h>
+
 // This class sets a new (process-global) umask and restores the previous umask
 // when destructed.
 class UmaskScope
index fd701eadc36a3ee3d7a5fa5724e67a7ca42ead78..e407299602e849f2702f47f4fa3892099cdbd9b5 100644 (file)
 #include "FormatNonstdStringView.hpp"
 #include "Logging.hpp"
 #include "TemporaryFile.hpp"
+#include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 
 extern "C" {
 #include "third_party/base32hex.h"
 }
 
+#ifdef HAVE_DIRENT_H
+#  include <dirent.h>
+#endif
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+#include <fcntl.h>
+
 #include <algorithm>
 #include <fstream>
 
@@ -47,6 +59,12 @@ extern "C" {
 #  include <sys/time.h>
 #endif
 
+#ifdef HAVE_UTIME_H
+#  include <utime.h>
+#elif defined(HAVE_SYS_UTIME_H)
+#  include <sys/utime.h>
+#endif
+
 #ifdef HAVE_LINUX_FS_H
 #  include <linux/magic.h>
 #  include <sys/statfs.h>
@@ -55,10 +73,6 @@ extern "C" {
 #  include <sys/param.h>
 #endif
 
-#ifdef _WIN32
-#  include "Win32Util.hpp"
-#endif
-
 #ifdef __linux__
 #  ifdef HAVE_SYS_IOCTL_H
 #    include <sys/ioctl.h>
index d31657c796504d6177ad015801c0be6fe3642a1d..0c8328aa23bfb1039c05c76e2b3db3de4dc4202a 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "CacheFile.hpp"
 
 #include <util/Tokenizer.hpp>
@@ -28,6 +26,7 @@
 #include "third_party/nonstd/string_view.hpp"
 
 #include <algorithm>
+#include <cstdint>
 #include <functional>
 #include <ios>
 #include <memory>
index 0a2f1a133c30ed470d4e23abd7613d6858e7ab57..ceeab576ab07897fb34138efaf7523283574f47c 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
+#ifdef _WIN32
 
-#include <string>
+#  include <core/wincompat.hpp>
+
+#  include <string>
+
+void usleep(int64_t usec);
+struct tm* localtime_r(time_t* _clock, struct tm* _result);
+
+#  ifdef _MSC_VER
+int gettimeofday(struct timeval* tp, struct timezone* tzp);
+int asprintf(char** strp, const char* fmt, ...);
+#  endif
 
 namespace Win32Util {
 
@@ -44,3 +54,5 @@ std::string error_message(DWORD error_code);
 NTSTATUS get_last_ntstatus();
 
 } // namespace Win32Util
+
+#endif
index 58ca453423b53d1f734a4307cb4a61ccd5598476..2551d13261787ba36edf6f763edeb6e50d320998 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Compressor.hpp"
 #include "NonCopyable.hpp"
 
 #include <zstd.h>
 
+#include <cstdint>
+
 // A compressor of a Zstandard stream.
 class ZstdCompressor : public Compressor, NonCopyable
 {
index 4c79886b4573c592e8ff95053564fc99ea5a602e..2868982b0d83c2fbecbfd380dc44adeb46c90003 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Decompressor.hpp"
 
 #include <zstd.h>
 
-#include <fstream>
+#include <cstdint>
 
 // A decompressor of a Zstandard stream.
 class ZstdDecompressor : public Decompressor
index 839e4538a90402ea6f4fb29b3ffea2446264ec8a..62c4716dbf388b859f34400152e3b5917d45438a 100644 (file)
 #include "fmtmacros.hpp"
 #include "language.hpp"
 
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <cassert>
 
 using nonstd::nullopt;
@@ -94,7 +100,8 @@ bool
 color_output_possible()
 {
   const char* term_env = getenv("TERM");
-  return isatty(STDERR_FILENO) && term_env && strcasecmp(term_env, "DUMB") != 0;
+  return isatty(STDERR_FILENO) && term_env
+         && Util::to_lowercase(term_env) != "dumb";
 }
 
 bool
index 040c3a5f63c93f95507f801cf45e00e47e2e1a14..d88cb10f5675b6a3a15d6fafe7b4a584bc10f0d6 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "system.hpp"
+#include <cstddef>
 
 #ifdef _MSC_VER
 #  define CCACHE_FUNCTION __func__
index 65daa54a20cc3637d2260c8d045f10fa8753d39c..69534f1e377e8a14833f133a6cc4895fc51a1642 100644 (file)
@@ -44,6 +44,7 @@
 #include "TemporaryFile.hpp"
 #include "UmaskScope.hpp"
 #include "Util.hpp"
+#include "Win32Util.hpp"
 #include "argprocessing.hpp"
 #include "cleanup.hpp"
 #include "compopt.hpp"
@@ -55,6 +56,7 @@
 #include "language.hpp"
 
 #include <core/types.hpp>
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 
 #include "third_party/fmt/core.h"
@@ -71,8 +73,10 @@ extern "C" {
 }
 #endif
 
-#ifdef _WIN32
-#  include "Win32Util.hpp"
+#include <fcntl.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
 #endif
 
 #include <algorithm>
index da1f342e723f485a2e9b4fd4d4adf31b10741189..e4fb11607b0f6fb6a8df34cd83404e72a2445a82 100644 (file)
@@ -19,8 +19,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Config.hpp"
 
 #include "third_party/nonstd/string_view.hpp"
index 053eb53e086661d8edb640199dc812acb1fbffba..97d5cb75c3f3f0dbd07bf5de51341bc4e313f874 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Util.hpp"
 
+#include <cstdint>
 #include <string>
 
 class Config;
index 5e5f143f26600ea08be4aa3ef1656eee48318f79..8cc516e0b042fb5d4d728a3e0dfede854a64dc32 100644 (file)
@@ -45,6 +45,8 @@
 // The option only affects compilation; not passed to the preprocessor.
 #define AFFECTS_COMP (1 << 6)
 
+#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
+
 struct CompOpt
 {
   const char* name;
index a0169280a1749d335c2134ebadb9fbee1a3c96e6..29a3354b0061123c84f7004f4a0650c8244387aa 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include <string>
 
 bool compopt_short(bool (*fn)(const std::string& option),
index 70c711762c4d3752ad0f9b32c5c8eebf0fb27560..4a26de7843bbae836503bdaa8fde7edf60d7e67d 100644 (file)
 #include "assertions.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/fmt/core.h"
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <memory>
 #include <string>
 #include <thread>
index 91eb04d1b333a288cf57bb7a4996d8fea37bc6e1..dd1670b185c755fe3844607461d6a9c9d5e7ad64 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Util.hpp"
 
 #include "third_party/nonstd/optional.hpp"
diff --git a/src/core/wincompat.hpp b/src/core/wincompat.hpp
new file mode 100644 (file)
index 0000000..4bc2d16
--- /dev/null
@@ -0,0 +1,103 @@
+// 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
+
+#pragma once
+
+#ifdef _WIN32
+
+#  include <sys/stat.h>
+
+#  ifndef __MINGW32__
+typedef __int64 ssize_t;
+#  endif
+
+// From:
+// http://mesos.apache.org/api/latest/c++/3rdparty_2stout_2include_2stout_2windows_8hpp_source.html
+#  ifdef _MSC_VER
+const mode_t S_IRUSR = mode_t(_S_IREAD);
+const mode_t S_IWUSR = mode_t(_S_IWRITE);
+#  endif
+
+#  ifndef S_IFIFO
+#    define S_IFIFO 0x1000
+#  endif
+
+#  ifndef S_IFBLK
+#    define S_IFBLK 0x6000
+#  endif
+
+#  ifndef S_IFLNK
+#    define S_IFLNK 0xA000
+#  endif
+
+#  ifndef S_ISREG
+#    define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
+#  endif
+#  ifndef S_ISDIR
+#    define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
+#  endif
+#  ifndef S_ISFIFO
+#    define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
+#  endif
+#  ifndef S_ISCHR
+#    define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
+#  endif
+#  ifndef S_ISLNK
+#    define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
+#  endif
+#  ifndef S_ISBLK
+#    define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
+#  endif
+
+#  include <direct.h>
+#  include <fcntl.h>
+#  include <io.h>
+#  include <process.h>
+#  define NOMINMAX 1
+#  define WIN32_NO_STATUS
+// clang-format off
+#  include <windows.h>
+#  include <bcrypt.h> // NTSTATUS
+#  include <winsock2.h> // struct timeval
+// clang-format on
+#  undef WIN32_NO_STATUS
+#  include <ntstatus.h>
+#  define mkdir(a, b) _mkdir(a)
+
+// Protect against incidental use of MinGW execv.
+#  define execv(a, b) do_not_call_execv_on_windows
+
+#  ifdef _MSC_VER
+#    define PATH_MAX MAX_PATH
+#  endif
+
+#  ifdef _MSC_VER
+#    define DLLIMPORT __declspec(dllimport)
+#  else
+#    define DLLIMPORT
+#  endif
+
+#  define STDIN_FILENO 0
+#  define STDOUT_FILENO 1
+#  define STDERR_FILENO 2
+
+#  ifndef O_BINARY
+#    define O_BINARY 0
+#  endif
+
+#endif // _WIN32
index 6f7ccb32f33cfbbbe0b630026320b308bddff638..65c4e2e863d15b9d61bc7407dcaf84217c149739 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "FormatNonstdStringView.hpp"
 
 #include "third_party/fmt/core.h"
index 4f7a9a6bde4fcf0f42bd5bd26c3ba817c3ab4af2..6dac7644081f6f8e38712edab8c5144c4d22e3b0 100644 (file)
 #include "Stat.hpp"
 #include "TemporaryFile.hpp"
 #include "Util.hpp"
+#include "Win32Util.hpp"
 #include "fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
 #include <util/path_utils.hpp>
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+#  include <sys/wait.h>
+#endif
+
 #ifdef _WIN32
 #  include "Finalizer.hpp"
-#  include "Win32Util.hpp"
 #endif
 
 using nonstd::string_view;
index 628ceb32753e529a01665474a50a146ef654c84e..8e492263981d002c3b1e583112da8c8283f26fbe 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Fd.hpp"
 
 #include <string>
index 7378c02fa980ba4a3975e80f8b282f4b8fb4d67d..73350e33a0d6416bb3ab08cf9bb887d728c4ef8a 100644 (file)
 #include "Logging.hpp"
 #include "Sloppiness.hpp"
 #include "Stat.hpp"
+#include "Win32Util.hpp"
 #include "execute.hpp"
 #include "fmtmacros.hpp"
 #include "macroskip.hpp"
 
-#include "third_party/blake3/blake3_cpu_supports_avx2.h"
+#include <core/wincompat.hpp>
 
 #ifdef INODE_CACHE_SUPPORTED
 #  include "InodeCache.hpp"
 #endif
 
-#ifdef _WIN32
-#  include "Win32Util.hpp"
+#include "third_party/blake3/blake3_cpu_supports_avx2.h"
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
+#ifdef HAVE_SYS_WAIT_H
+#  include <sys/wait.h>
 #endif
 
 #ifdef HAVE_AVX2
index 51ac36af70a2e4904961afcec80498bff8089b14..b3f1756d7b7b0504d18a234b1f96c0c3d0bcf01a 100644 (file)
 
 #pragma once
 
-#include "system.hpp"
-
 #include "third_party/nonstd/string_view.hpp"
 
+#include <cstddef>
 #include <string>
 
 class Config;
index 99bf386e04665ee51816c6fe4043f202cc6beb2c..74be7aaf622c8d810fa5f85f0325092f5ecf04e4 100644 (file)
@@ -18,8 +18,6 @@
 
 #pragma once
 
-#include "system.hpp"
-
 #include "Config.hpp"
 
 #include <string>
index f15932346f604b5ed4946df0bc738de451ce560c..5cacba87f20e31532cfd3ecef2353d8c8d58cb49 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2010-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2010-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,7 +18,7 @@
 
 #pragma once
 
-#include "system.hpp"
+#include <cstdint>
 
 // A Boyer-Moore-Horspool skip table used for searching for the strings
 // "__TIME__", "__DATE__" and "__TIMESTAMP__".
index df8d7b6aae7c3290fe1e49d7e976825dab8098b1..027f2bff8e5cddfc32a70a4734fa0f45b3961eee 100644 (file)
 #include <Util.hpp>
 #include <assertions.hpp>
 #include <cleanup.hpp>
+#include <core/wincompat.hpp>
 #include <exceptions.hpp>
 #include <fmtmacros.hpp>
 #include <util/file_utils.hpp>
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 namespace storage {
 namespace primary {
 
diff --git a/src/system.hpp b/src/system.hpp
deleted file mode 100644 (file)
index df71a6d..0000000
+++ /dev/null
@@ -1,200 +0,0 @@
-// Copyright (C) 2010-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
-
-#pragma once
-
-#ifdef HAVE_SYS_FILE_H
-#  include <sys/file.h>
-#endif
-
-#ifdef HAVE_SYS_MMAN_H
-#  include <sys/mman.h>
-#endif
-#include <sys/stat.h>
-#include <sys/types.h>
-#ifdef HAVE_SYS_WAIT_H
-#  include <sys/wait.h>
-#endif
-
-#include <cassert>
-#include <cctype>
-#include <cerrno>
-#include <cinttypes>
-#include <climits>
-#include <csignal>
-#include <cstdarg>
-#include <cstddef>
-#include <cstdint>
-#include <cstdio>
-#include <cstdlib>
-#include <cstring>
-#include <ctime>
-
-#ifdef HAVE_DIRENT_H
-#  include <dirent.h>
-#endif
-
-#include <fcntl.h>
-
-#ifdef HAVE_STRINGS_H
-#  include <strings.h>
-#endif
-
-#ifdef HAVE_UNISTD_H
-#  include <unistd.h>
-#endif
-
-#ifdef HAVE_UTIME_H
-#  include <utime.h>
-#elif defined(HAVE_SYS_UTIME_H)
-#  include <sys/utime.h>
-#endif
-
-#ifdef HAVE_VARARGS_H
-#  include <varargs.h>
-#endif
-
-// AIX/PASE does not properly define usleep within its headers. However, the
-// function is available in libc.a. This extern define ensures that it is
-// usable within the ccache code base.
-#ifdef _AIX
-extern "C" int usleep(useconds_t);
-#endif
-
-#define ARRAY_SIZE(array) (sizeof(array) / sizeof((array)[0]))
-
-#ifndef ESTALE
-#  define ESTALE -1
-#endif
-
-#ifdef _WIN32
-#  ifndef _WIN32_WINNT
-// _WIN32_WINNT is set in the generated header config.h
-#    error _WIN32_WINNT is undefined
-#  endif
-
-#  ifndef __MINGW32__
-typedef int64_t ssize_t;
-#  endif
-
-// Defined in Win32Util.cpp
-void usleep(int64_t usec);
-struct tm* localtime_r(time_t* _clock, struct tm* _result);
-
-#  ifdef _MSC_VER
-int gettimeofday(struct timeval* tp, struct timezone* tzp);
-int asprintf(char** strp, const char* fmt, ...);
-#  endif
-
-// From:
-// http://mesos.apache.org/api/latest/c++/3rdparty_2stout_2include_2stout_2windows_8hpp_source.html
-#  ifdef _MSC_VER
-const mode_t S_IRUSR = mode_t(_S_IREAD);
-const mode_t S_IWUSR = mode_t(_S_IWRITE);
-#  endif
-
-#  ifndef S_IFIFO
-#    define S_IFIFO 0x1000
-#  endif
-
-#  ifndef S_IFBLK
-#    define S_IFBLK 0x6000
-#  endif
-
-#  ifndef S_IFLNK
-#    define S_IFLNK 0xA000
-#  endif
-
-#  ifndef S_ISREG
-#    define S_ISREG(m) (((m)&S_IFMT) == S_IFREG)
-#  endif
-#  ifndef S_ISDIR
-#    define S_ISDIR(m) (((m)&S_IFMT) == S_IFDIR)
-#  endif
-#  ifndef S_ISFIFO
-#    define S_ISFIFO(m) (((m)&S_IFMT) == S_IFIFO)
-#  endif
-#  ifndef S_ISCHR
-#    define S_ISCHR(m) (((m)&S_IFMT) == S_IFCHR)
-#  endif
-#  ifndef S_ISLNK
-#    define S_ISLNK(m) (((m)&S_IFMT) == S_IFLNK)
-#  endif
-#  ifndef S_ISBLK
-#    define S_ISBLK(m) (((m)&S_IFMT) == S_IFBLK)
-#  endif
-
-#  include <direct.h>
-#  include <io.h>
-#  include <process.h>
-#  define NOMINMAX 1
-#  define WIN32_NO_STATUS
-// clang-format off
-#  include <windows.h>
-#  include <bcrypt.h> // NTSTATUS
-#  include <winsock2.h> // struct timeval
-// clang-format on
-#  undef WIN32_NO_STATUS
-#  include <ntstatus.h>
-#  define mkdir(a, b) _mkdir(a)
-#  define execv(a, b)                                                          \
-    do_not_call_execv_on_windows // to protect against incidental use of MinGW
-                                 // execv
-#  define strncasecmp _strnicmp
-#  define strcasecmp _stricmp
-
-#  ifdef _MSC_VER
-#    define PATH_MAX MAX_PATH
-#  endif
-
-#  ifdef _MSC_VER
-#    define DLLIMPORT __declspec(dllimport)
-#  else
-#    define DLLIMPORT
-#  endif
-
-#  define STDIN_FILENO 0
-#  define STDOUT_FILENO 1
-#  define STDERR_FILENO 2
-#else
-#  define DLLIMPORT
-#endif
-
-DLLIMPORT extern char** environ;
-
-// Work with silly DOS binary open.
-#ifndef O_BINARY
-#  define O_BINARY 0
-#endif
-
-#if defined(HAVE_SYS_MMAN_H) && defined(HAVE_PTHREAD_MUTEXATTR_SETPSHARED)
-#  define INODE_CACHE_SUPPORTED
-#endif
-
-// Workaround for missing std::is_trivially_copyable in GCC < 5.
-#if __GNUG__ && __GNUC__ < 5
-#  define IS_TRIVIALLY_COPYABLE(T) __has_trivial_copy(T)
-#else
-#  define IS_TRIVIALLY_COPYABLE(T) std::is_trivially_copyable<T>::value
-#endif
-
-// GCC version of a couple of standard C++ attributes
-#ifdef __GNUC__
-#  define nodiscard gnu::warn_unused_result
-#  define maybe_unused gnu::unused
-#endif
index fa8f7f01b32cb368d371679aaafba6637ea3bebe..615f8bcb90cb4a214afcce7ba9ef99dae0400eeb 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 #include "../src/exceptions.hpp"
 #include "../src/fmtmacros.hpp"
 
+#include <core/wincompat.hpp>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 namespace TestUtil {
 
 size_t TestContext::m_subdir_counter = 0;
index 0f06d3ee31d516e7d8dff25a4e29e6a5cb5d1762..6be4969b239f991090010e708ccc759d5be0a580 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -18,8 +18,7 @@
 
 #pragma once
 
-#include "system.hpp"
-
+#include <cstddef>
 #include <string>
 
 #ifdef _MSC_VER
index 7a01512ea619c0ac572ac489d494276e838630e0..d95cb3d1b12d966c573e7d10c0c4e913be364016 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2020 Joel Rosdahl and other contributors
+// Copyright (C) 2020-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 #include "../src/Stat.hpp"
 #include "TestUtil.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 TEST_SUITE_BEGIN("LockFile");
 
 using TestUtil::TestContext;
index 22da2f55f7280cf417b5e6d9845a36d23045686e..9ea78afef471b1bd727a9b2dd2a459bfa45d6746 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -24,6 +24,8 @@
 
 #include "third_party/doctest.h"
 
+#include <cstring>
+
 using TestUtil::TestContext;
 
 TEST_SUITE_BEGIN("NullCompression");
index e5b6eeb8385fd7fb2e7fa0f7510afb627dd2c66a..c67673299236a855d2dcd131ced700116e4562fc 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -21,6 +21,8 @@
 #include "../src/Util.hpp"
 #include "TestUtil.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 
 #ifdef HAVE_UNISTD_H
index 4720c8ba54146cd201b08ce6490f6ebd8df262da..cd40e8d8fb946caf97351c7157f79eb4935cb9f4 100644 (file)
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 #include "third_party/nonstd/optional.hpp"
 
+#include <fcntl.h>
+
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #include <algorithm>
 
 using doctest::Approx;
index a72f59e56d5120fd611b2bb50a84a9c248530ca4..834350346ef591ab9af91ba2eb0b647e2fbc045c 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2019-2020 Joel Rosdahl and other contributors
+// Copyright (C) 2019-2021 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
@@ -24,6 +24,8 @@
 
 #include "third_party/doctest.h"
 
+#include <cstring>
+
 using TestUtil::TestContext;
 
 TEST_SUITE_BEGIN("ZstdCompression");
index aa4c0550a049d53395be57430af06ce69de0cfc6..8ac228b5ec692c6b6d0f9e4f82c3c9dfc079039c 100644 (file)
@@ -25,6 +25,8 @@
 #include "TestUtil.hpp"
 #include "argprocessing.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 
 #include <algorithm>
index 6ded67403c86550d84cc1b42ee5663889924ece4..5a8dd6d18d082adade1cf1fcfc4e5cae663ab2a6 100644 (file)
@@ -20,6 +20,8 @@
 #include "../src/Finalizer.hpp"
 #include "TestUtil.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 #include "third_party/win32/mktemp.h"
 
index 3236a4883822697e203ce96e4c10d3e2b5ab9726..a09a316e7bd623dd0d27d5a7393a867c53d7979f 100644 (file)
 #include "../src/fmtmacros.hpp"
 #include "TestUtil.hpp"
 
+#include <core/wincompat.hpp>
+
 #include "third_party/doctest.h"
 #include "third_party/nonstd/optional.hpp"
 
+#ifdef HAVE_UNISTD_H
+#  include <unistd.h>
+#endif
+
 #ifdef MYNAME
 #  define CCACHE_NAME MYNAME
 #else