Skip to content

Commit 6df1517

Browse files
committed
FileSystem: mutualize the open64() selection
1 parent 81d12ce commit 6df1517

File tree

1 file changed

+13
-7
lines changed

1 file changed

+13
-7
lines changed

src/common/FileSystem.cpp

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,11 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2828
===========================================================================
2929
*/
3030

31+
#if defined(_WIN32)
32+
#elif defined(__linux__) && defined(__GLIBC__)
33+
#define DAEMON_OPEN64
34+
#endif
35+
3136
#if defined(BUILD_ENGINE)
3237
#include "minizip/unzip.h"
3338
#endif
@@ -175,6 +180,7 @@ enum class openMode_t {
175180
MODE_APPEND,
176181
MODE_EDIT
177182
};
183+
178184
inline int my_open(Str::StringRef path, openMode_t mode)
179185
{
180186
int mode_ = Util::ordinal(mode);
@@ -192,7 +198,7 @@ inline int my_open(Str::StringRef path, openMode_t mode)
192198
int fd = _open_osfhandle(reinterpret_cast<intptr_t>(h), modes[mode_] | O_BINARY | O_NOINHERIT);
193199
if (fd == -1)
194200
CloseHandle(h);
195-
#elif defined(__linux__) && defined(__GLIBC__)
201+
#elif defined(DAEMON_OPEN64)
196202
int fd = open64(path.c_str(), modes[mode_] | O_CLOEXEC | O_LARGEFILE, 0666);
197203
#else
198204
// This doesn't actually work in Native Client, but it's not used anyways.
@@ -236,7 +242,7 @@ inline offset_t my_ftell(FILE* fd)
236242
{
237243
#ifdef _WIN32
238244
return _ftelli64(fd);
239-
#elif defined(__linux__) && defined(__GLIBC__)
245+
#elif defined(DAEMON_OPEN64)
240246
return ftello64(fd);
241247
#else
242248
return ftello(fd);
@@ -246,15 +252,15 @@ inline int my_fseek(FILE* fd, offset_t off, int whence)
246252
{
247253
#ifdef _WIN32
248254
return _fseeki64(fd, off, whence);
249-
#elif defined(__linux__) && defined(__GLIBC__)
255+
#elif defined(DAEMON_OPEN64)
250256
return fseeko64(fd, off, whence);
251257
#else
252258
return fseeko(fd, off, whence);
253259
#endif
254260
}
255261
#ifdef _WIN32
256262
typedef struct _stati64 my_stat_t;
257-
#elif defined(__linux__) && defined(__GLIBC__)
263+
#elif defined(DAEMON_OPEN64)
258264
using my_stat_t = struct stat64;
259265
#else
260266
using my_stat_t = struct stat;
@@ -263,7 +269,7 @@ inline int my_fstat(int fd, my_stat_t* st)
263269
{
264270
#ifdef _WIN32
265271
return _fstati64(fd, st);
266-
#elif defined(__linux__) && defined(__GLIBC__)
272+
#elif defined(DAEMON_OPEN64)
267273
return fstat64(fd, st);
268274
#else
269275
return fstat(fd, st);
@@ -273,7 +279,7 @@ inline int my_stat(Str::StringRef path, my_stat_t* st)
273279
{
274280
#ifdef _WIN32
275281
return _wstati64(Str::UTF8To16(path).c_str(), st);
276-
#elif defined(__linux__) && defined(__GLIBC__)
282+
#elif defined(DAEMON_OPEN64)
277283
return stat64(path.c_str(), st);
278284
#else
279285
return stat(path.c_str(), st);
@@ -292,7 +298,7 @@ inline intptr_t my_pread(int fd, void* buf, size_t count, offset_t offset)
292298
return -1;
293299
}
294300
return bytesRead;
295-
#elif defined(__linux__) && defined(__GLIBC__)
301+
#elif defined(DAEMON_OPEN64)
296302
return pread64(fd, buf, count, offset);
297303
#else
298304
return pread(fd, buf, count, offset);

0 commit comments

Comments
 (0)