From 990206f3c6a546a9932baeb806077d2ef2f6a2f1 Mon Sep 17 00:00:00 2001 From: Joel Rosdahl Date: Wed, 12 Jul 2023 21:20:04 +0200 Subject: [PATCH] refactor: Use std::filesystem::current_path --- src/Util.cpp | 18 +++++------------- src/core/wincompat.hpp | 10 +--------- 2 files changed, 6 insertions(+), 22 deletions(-) diff --git a/src/Util.cpp b/src/Util.cpp index 61b65b697..5ad6b7f00 100644 --- a/src/Util.cpp +++ b/src/Util.cpp @@ -35,8 +35,6 @@ #include #include -#include // NOLINT: PATH_MAX is defined in limits.h - #ifdef HAVE_DIRENT_H # include #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 diff --git a/src/core/wincompat.hpp b/src/core/wincompat.hpp index 20827109f..e8c875d79 100644 --- a/src/core/wincompat.hpp +++ b/src/core/wincompat.hpp @@ -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. // @@ -26,10 +26,6 @@ # 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 -- 2.47.2