Skip to content

Commit

Permalink
Use std::filesystem to get current working dir
Browse files Browse the repository at this point in the history
This doesn't work on GCC 7... TODO: Figure out whether we can safely
bump the requirements to GCC 8.

Signed-off-by: aszlig <[email protected]>
  • Loading branch information
aszlig committed Jul 8, 2021
1 parent 92cd86f commit 3ef2ee3
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
14 changes: 5 additions & 9 deletions src/blackhole.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <cstring>
#include <climits>
#include <filesystem>
#include <unistd.h>

#include <sys/stat.h>
Expand Down Expand Up @@ -60,15 +61,10 @@ static std::string get_tmpdir(void)
if (is_writable_dir("/var/tmp"))
return "/var/tmp";

int old_errno = errno;
char *workdir = get_current_dir_name();
errno = old_errno;
if (workdir != nullptr) {
std::string wdir_str(workdir);
free(workdir);
if (is_writable_dir(workdir))
return workdir;
}
std::string workdir = std::filesystem::current_path();

if (is_writable_dir(workdir))
return workdir;

LOG(FATAL) << "Unable to get temporary directory.";
std::abort();
Expand Down
3 changes: 2 additions & 1 deletion src/rules/parse.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// SPDX-License-Identifier: LGPL-3.0-only
#include <algorithm>
#include <iostream>
#include <filesystem>
#include <fstream>
#include <memory>
#include <sstream>
Expand Down Expand Up @@ -322,7 +323,7 @@ std::string make_absolute(const std::string &path)
if (path.empty() || path[0] == '/')
return path;

return std::string(get_current_dir_name()) + '/' + path;
return std::filesystem::current_path() / path;
}

std::optional<Rule> parse_rule_arg(size_t rulepos, const std::string &arg)
Expand Down

0 comments on commit 3ef2ee3

Please sign in to comment.