[Scummvm-git-logs] scummvm master -> f44e87dfb7318240323faa7436d0b6c1aae3808a
bluegr
bluegr at gmail.com
Fri Aug 13 18:58:04 UTC 2021
This automated email contains information about 1 new commit which have been
pushed to the 'scummvm' repo located at https://github.com/scummvm/scummvm .
Summary:
f44e87dfb7 WIN32: Remove F_OK/R_OK/W_OK hack (#3265)
Commit: f44e87dfb7318240323faa7436d0b6c1aae3808a
https://github.com/scummvm/scummvm/commit/f44e87dfb7318240323faa7436d0b6c1aae3808a
Author: Carlo Bramini (30959007+carlo-bramini at users.noreply.github.com)
Date: 2021-08-13T21:58:01+03:00
Commit Message:
WIN32: Remove F_OK/R_OK/W_OK hack (#3265)
In backends/fs/windows/windows-fs.cpp, the macros F_OK/R_OK/W_OK are not defined by system includes of MSVC, so they have been added manually into the code.
While this solution works, in my opinion it would be much cleaner to use GetFileAttributes() for getting this information.
Actually, this is what the _access()/_waccess() functions do and, afterall, this is a piece of code expected to work on Windows only.
Changed paths:
backends/fs/windows/windows-fs.cpp
diff --git a/backends/fs/windows/windows-fs.cpp b/backends/fs/windows/windows-fs.cpp
index 4c59f8cf86..f682625d27 100644
--- a/backends/fs/windows/windows-fs.cpp
+++ b/backends/fs/windows/windows-fs.cpp
@@ -28,31 +28,21 @@
#include "backends/fs/windows/windows-fs.h"
#include "backends/fs/stdiostream.h"
-// F_OK, R_OK and W_OK are not defined under MSVC, so we define them here
-// For more information on the modes used by MSVC, check:
-// http://msdn2.microsoft.com/en-us/library/1w06ktdy(VS.80).aspx
-#ifndef F_OK
-#define F_OK 0
-#endif
-
-#ifndef R_OK
-#define R_OK 4
-#endif
-
-#ifndef W_OK
-#define W_OK 2
-#endif
-
bool WindowsFilesystemNode::exists() const {
- return _taccess(charToTchar(_path.c_str()), F_OK) == 0;
+ // Check whether the file actually exists
+ return (GetFileAttributes(charToTchar(_path.c_str())) != INVALID_FILE_ATTRIBUTES);
}
bool WindowsFilesystemNode::isReadable() const {
- return _taccess(charToTchar(_path.c_str()), R_OK) == 0;
+ // Since all files are always readable and it is not possible to give
+ // write-only permission, this is equivalent to ::exists().
+ return (GetFileAttributes(charToTchar(_path.c_str())) != INVALID_FILE_ATTRIBUTES);
}
bool WindowsFilesystemNode::isWritable() const {
- return _taccess(charToTchar(_path.c_str()), W_OK) == 0;
+ // Check whether the file exists and it can be written.
+ DWORD fileAttribs = GetFileAttributes(charToTchar(_path.c_str()));
+ return ((fileAttribs != INVALID_FILE_ATTRIBUTES) && (!(fileAttribs & FILE_ATTRIBUTE_READONLY)));
}
void WindowsFilesystemNode::addFile(AbstractFSList &list, ListMode mode, const char *base, bool hidden, WIN32_FIND_DATA* find_data) {
More information about the Scummvm-git-logs
mailing list