Skip to content

Commit 38eb583

Browse files
Moving towards use of c++17 filesystem instead of the C functions
1 parent f90cbad commit 38eb583

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

smithlab_os.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <cmath>
2525
#include <unordered_map>
2626
#include <exception>
27+
#include <filesystem>
2728

2829
#include "smithlab_os.hpp"
2930
#include "smithlab_utils.hpp"
@@ -535,9 +536,10 @@ read_dir(const string& dirname, vector<string> &filenames) {
535536

536537
bool
537538
is_valid_output_file(const string &filename) {
538-
const bool file_exists = (access(filename.c_str(), F_OK) == 0);
539-
if (file_exists)
540-
return (!isdir(filename.c_str()) &&
539+
// ADS: seems like there is no way around "access" and apparently
540+
// access is not a great solution anyway.
541+
if (std::filesystem::exists(filename))
542+
return (!std::filesystem::is_directory(filename) &&
541543
access(filename.c_str(), W_OK) == 0);
542544
else {
543545
// ADS: check if dir exists and is writeable

0 commit comments

Comments
 (0)