]> git.ipfire.org Git - thirdparty/ccache.git/commitdiff
refactor: Use std::filesystem::current_path
authorJoel Rosdahl <joel@rosdahl.net>
Wed, 12 Jul 2023 19:20:04 +0000 (21:20 +0200)
committerJoel Rosdahl <joel@rosdahl.net>
Fri, 14 Jul 2023 18:33:17 +0000 (20:33 +0200)
src/Util.cpp
src/core/wincompat.hpp

index 61b65b697f67ad6c9cd5c0b7e2376b46bfa51739..5ad6b7f00f3b16d3a2bd99fb5a14d092c6d18871 100644 (file)
@@ -35,8 +35,6 @@
 #include <util/path.hpp>
 #include <util/string.hpp>
 
-#include <limits.h> // NOLINT: PATH_MAX is defined in limits.h
-
 #ifdef HAVE_DIRENT_H
 #  include <dirent.h>
 #endif
@@ -330,18 +328,12 @@ ensure_dir_exists(std::string_view dir)
 std::string
 get_actual_cwd()
 {
-  char buffer[PATH_MAX];
-  if (getcwd(buffer, sizeof(buffer))) {
-#ifndef _WIN32
-    return buffer;
-#else
-    std::string cwd = buffer;
-    std::replace(cwd.begin(), cwd.end(), '\\', '/');
-    return cwd;
+  std::error_code ec;
+  auto cwd = fs::current_path(ec).string();
+#ifdef _WIN32
+  std::replace(cwd.begin(), cwd.end(), '\\', '/');
 #endif
-  } else {
-    return {};
-  }
+  return cwd;
 }
 
 std::string
index 20827109f4b75dce67d59c51194a2ad21e9ab2fc..e8c875d79f1751a6efad03da6ab1fa47a4c79094 100644 (file)
@@ -1,4 +1,4 @@
-// Copyright (C) 2021 Joel Rosdahl and other contributors
+// Copyright (C) 2021-2022 Joel Rosdahl and other contributors
 //
 // See doc/AUTHORS.adoc for a complete list of contributors.
 //
 #  define STDOUT_FILENO 1
 #  define STDERR_FILENO 2
 
-#  ifdef _MSC_VER
-#    define PATH_MAX MAX_PATH
-#  endif // _MSC_VER
-
 // From:
 // http://mesos.apache.org/api/latest/c++/3rdparty_2stout_2include_2stout_2windows_8hpp_source.html
 #  ifdef _MSC_VER
@@ -90,10 +86,6 @@ const mode_t S_IWUSR = mode_t(_S_IWRITE);
 // 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