fix for is-file? function

This commit is contained in:
vaclavt
2022-02-28 19:48:05 +01:00
parent aad8724cbb
commit 2b3d8ab026

View File

@@ -50,8 +50,13 @@ MlValue list_dir(const std::string &path) {
} }
bool is_path_file(const std::string &path) { bool is_path_file(const std::string &path) {
std::ifstream ifile(path.c_str()); struct stat buf{};
return (bool) ifile; stat(path.c_str(), &buf);
return (bool) S_ISREG(buf.st_mode) ||
(bool) S_ISBLK(buf.st_mode) ||
(bool) S_ISCHR(buf.st_mode) ||
(bool) S_ISFIFO(buf.st_mode) ||
(bool) S_ISSOCK(buf.st_mode);
} }
bool is_path_dir(const std::string &path) { bool is_path_dir(const std::string &path) {