3
0
Fork 0
mirror of https://github.com/YosysHQ/yosys synced 2025-05-14 19:24:45 +00:00

io: don't accept a directory when file expected

This commit is contained in:
Emil J. Tywoniak 2025-05-09 22:30:43 +02:00
parent 55bd950af4
commit b05c0c70af
4 changed files with 34 additions and 25 deletions

View file

@ -247,7 +247,7 @@ std::string make_temp_dir(std::string template_str)
#endif
}
bool check_directory_exists(const std::string& dirname)
bool check_is_directory(const std::string& dirname)
{
#if defined(_WIN32)
struct _stat info;
@ -267,17 +267,26 @@ bool check_directory_exists(const std::string& dirname)
}
#ifdef _WIN32
bool check_file_exists(std::string filename, bool)
bool check_accessible(const std::string& filename, bool)
{
return _access(filename.c_str(), 0) == 0;
}
#else
bool check_file_exists(std::string filename, bool is_exec)
bool check_accessible(const std::string& filename, bool is_exec)
{
return access(filename.c_str(), is_exec ? X_OK : F_OK) == 0;
}
#endif
bool check_file_exists(const std::string& filename, bool is_exec)
{
return check_accessible(filename, is_exec) && !check_is_directory(filename);
}
bool check_directory_exists(const std::string& filename, bool is_exec)
{
return check_accessible(filename, is_exec) && check_is_directory(filename);
}
bool is_absolute_path(std::string filename)
{
#ifdef _WIN32