// Using native file handles instead of file descriptors for reducing the resource consumption.
+ const HANDLE InvalidFile = INVALID_HANDLE_VALUE;
+
HANDLE openFile(const FileName &path, bool readOnly)
{
DWORD access = readOnly ? GENERIC_READ : (GENERIC_READ | GENERIC_WRITE);
// For non-Windows
+ const FILE *InvalidFile = 0;
+
struct FileNameHandle : public std::string
{
FileNameHandle(FileName name) : std::string(name) {}
};
FileStream::FileStreamPrivate::FileStreamPrivate(FileName fileName, bool openReadOnly) :
- file(0),
+ file(InvalidFile),
name(fileName),
readOnly(true),
size(0)
if(!openReadOnly)
file = openFile(name, false);
- if(file)
+ if(file != InvalidFile)
readOnly = false;
else
file = openFile(name, true);
- if(!file) {
+ if(file == InvalidFile) {
debug("Could not open file " + String((const char *) name));
}
}