From 2b3d8ab026cdaef26025976cdfbeafd6ad77ca54 Mon Sep 17 00:00:00 2001 From: vaclavt Date: Mon, 28 Feb 2022 19:48:05 +0100 Subject: [PATCH] fix for is-file? function --- ml_io.cpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/ml_io.cpp b/ml_io.cpp index a5ac3b2..ab0cfed 100644 --- a/ml_io.cpp +++ b/ml_io.cpp @@ -50,8 +50,13 @@ MlValue list_dir(const std::string &path) { } bool is_path_file(const std::string &path) { - std::ifstream ifile(path.c_str()); - return (bool) ifile; + struct stat buf{}; + 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) {