2020#ifdef _MSC_VER
2121// Windows
2222#include < windows.h>
23+
24+ #define MM_INVALID_FILE NULL
2325#else
2426// Linux
2527// enable large file support on 32 bit systems
3739#include < errno.h>
3840#include < unistd.h>
3941
42+ #define MM_INVALID_FILE -1
4043#endif
4144
4245
@@ -46,7 +49,7 @@ MemoryMapped::MemoryMapped()
4649 _filesize (0 ),
4750 _hint (Normal),
4851 _mappedBytes(0 ),
49- _file (0 ),
52+ _file (MM_INVALID_FILE ),
5053#ifdef _MSC_VER
5154 _mappedFile (NULL ),
5255#endif
@@ -60,7 +63,7 @@ MemoryMapped::MemoryMapped(const std::string& filename, size_t mappedBytes, Cach
6063 _filesize (0 ),
6164 _hint (hint),
6265 _mappedBytes(mappedBytes),
63- _file (0 ),
66+ _file (MM_INVALID_FILE ),
6467#ifdef _MSC_VER
6568 _mappedFile (NULL ),
6669#endif
@@ -84,7 +87,7 @@ bool MemoryMapped::open(const std::string& filename, size_t mappedBytes, CacheHi
8487 if (isValid ())
8588 return false ;
8689
87- _file = 0 ;
90+ _file = MM_INVALID_FILE ;
8891 _filesize = 0 ;
8992 _hint = hint;
9093#ifdef _MSC_VER
@@ -106,7 +109,7 @@ bool MemoryMapped::open(const std::string& filename, size_t mappedBytes, CacheHi
106109
107110 // open file
108111 _file = ::CreateFileA (filename.c_str (), GENERIC_READ, FILE_SHARE_READ, NULL , OPEN_EXISTING, winHint, NULL );
109- if (! _file)
112+ if (_file == MM_INVALID_FILE )
110113 return false ;
111114
112115 // file size
@@ -127,9 +130,8 @@ bool MemoryMapped::open(const std::string& filename, size_t mappedBytes, CacheHi
127130 // open file
128131
129132 _file = ::open (filename.c_str (), O_RDONLY);
130- if (_file == - 1 )
133+ if (_file == MM_INVALID_FILE )
131134 {
132- _file = 0 ;
133135 return false ;
134136 }
135137
@@ -176,14 +178,14 @@ void MemoryMapped::close()
176178#endif
177179
178180 // close underlying file
179- if (_file)
181+ if (_file != MM_INVALID_FILE )
180182 {
181183#ifdef _MSC_VER
182184 ::CloseHandle (_file);
183185#else
184186 ::close (_file);
185187#endif
186- _file = 0 ;
188+ _file = MM_INVALID_FILE ;
187189 }
188190
189191 _filesize = 0 ;
@@ -240,7 +242,7 @@ size_t MemoryMapped::mappedSize() const
240242// / replace mapping by a new one of the same file, offset MUST be a multiple of the page size
241243bool MemoryMapped::remap (uint64_t offset, size_t mappedBytes)
242244{
243- if (! _file)
245+ if (_file == MM_INVALID_FILE )
244246 return false ;
245247
246248 if (mappedBytes == WholeFile)
0 commit comments