mirror of
https://github.com/kiwix/libkiwix.git
synced 2026-10-24 01:49:15 -04:00
Introduce kiwix::fileReadable
kiwix::fileExists only checks for file existence now kiwix::fileReadable will check if the file is readable (implicitly checking for file existence also)
This commit is contained in:
1 parent
c9eb3196f7
commit
854058f842
4 files changed
+23
-12
No files matched your search
+11
-9
@@ -305,16 +305,18 @@ std::string kiwix::getFileContent(const std::string& path)
|
||||
bool kiwix::fileExists(const std::string& path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return PathFileExistsW(Utf8ToWide(path).c_str());
|
||||
return (_waccess_s(Utf8ToWide(path).c_str(), 0) == 0);
|
||||
#else
|
||||
return (access(path.c_str(), F_OK) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
bool kiwix::fileReadable(const std::string& path)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
return (_waccess_s(Utf8ToWide(path).c_str(), 4) == 0);
|
||||
#else
|
||||
bool flag = false;
|
||||
std::fstream fin;
|
||||
fin.open(path.c_str(), std::ios::in);
|
||||
if (fin.is_open()) {
|
||||
flag = true;
|
||||
}
|
||||
fin.close();
|
||||
return flag;
|
||||
return (access(path.c_str(), R_OK) == 0);
|
||||
#endif
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user