Browse Source

Extended File class

- added "canRead" implementation for unix like systems
patrick 3 years ago
parent
commit
031cd6c0b1
1 changed files with 18 additions and 1 deletions
  1. 18 1
      source/io/File.cpp

+ 18 - 1
source/io/File.cpp

@@ -283,12 +283,29 @@ bool ls_std::File::_isFile(const std::string& _path)
   struct stat _stat {};
 
   if(stat(_path.c_str(), &_stat) == 0) {
-    match = _stat.st_mode & (unsigned short) S_IFREG;
+    match = _stat.st_mode & (unsigned) S_IFREG;
   }
 
   return match;
 }
 
+#if defined(unix) || defined(__APPLE__)
+bool ls_std::File::_isReadableUnix(const std::string &_path)
+{
+  bool readable {};
+
+  if(ls_std::File::_exists(_path)) {
+    struct stat _stat {};
+
+    if(stat(_path.c_str(), &_stat) == 0) {
+      readable = (_stat.st_mode & (unsigned) S_IREAD) != 0;
+    }
+  }
+
+  return readable;
+}
+#endif
+
 #ifdef _WIN32
 bool ls_std::File::_isReadableWindows(const std::string &_path)
 {