Skip to content

Commit 54f333c

Browse files
committed
FileSystem: properly detect Linux with glibc to detect what's not
1 parent 22d56d9 commit 54f333c

File tree

1 file changed

+22
-22
lines changed

1 file changed

+22
-22
lines changed

src/common/FileSystem.cpp

Lines changed: 22 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -192,14 +192,14 @@ inline int my_open(Str::StringRef path, openMode_t mode)
192192
int fd = _open_osfhandle(reinterpret_cast<intptr_t>(h), modes[mode_] | O_BINARY | O_NOINHERIT);
193193
if (fd == -1)
194194
CloseHandle(h);
195-
#elif defined(__FreeBSD__) || defined(__APPLE__)
196-
// O_CLOEXEC is supported in macOS from 10.7 onwards
197-
int fd = open(path.c_str(), modes[mode_] | O_CLOEXEC, 0666);
198-
#elif defined(__linux__)
195+
#elif defined(__linux__) && defined(__GLIBC__)
199196
int fd = open64(path.c_str(), modes[mode_] | O_CLOEXEC | O_LARGEFILE, 0666);
200197
#elif defined(__native_client__)
201198
// This doesn't actually work, but it's not used anyways
202199
int fd = open(path.c_str(), modes[mode_], 0666);
200+
#else
201+
// O_CLOEXEC is supported in macOS from 10.7 onwards
202+
int fd = open(path.c_str(), modes[mode_] | O_CLOEXEC, 0666);
203203
#endif
204204

205205
#ifndef _WIN32
@@ -238,47 +238,47 @@ inline offset_t my_ftell(FILE* fd)
238238
{
239239
#ifdef _WIN32
240240
return _ftelli64(fd);
241-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
242-
return ftello(fd);
243-
#elif defined(__linux__)
241+
#elif defined(__linux__) && defined(__GLIBC__)
244242
return ftello64(fd);
243+
#else
244+
return ftello(fd);
245245
#endif
246246
}
247247
inline int my_fseek(FILE* fd, offset_t off, int whence)
248248
{
249249
#ifdef _WIN32
250250
return _fseeki64(fd, off, whence);
251-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
252-
return fseeko(fd, off, whence);
253-
#elif defined(__linux__)
251+
#elif defined(__linux__) && defined(__GLIBC__)
254252
return fseeko64(fd, off, whence);
253+
#else
254+
return fseeko(fd, off, whence);
255255
#endif
256256
}
257257
#ifdef _WIN32
258258
typedef struct _stati64 my_stat_t;
259-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
260-
using my_stat_t = struct stat;
261-
#elif defined(__linux__)
259+
#elif defined(__linux__) && defined(__GLIBC__)
262260
using my_stat_t = struct stat64;
261+
#else
262+
using my_stat_t = struct stat;
263263
#endif
264264
inline int my_fstat(int fd, my_stat_t* st)
265265
{
266266
#ifdef _WIN32
267267
return _fstati64(fd, st);
268-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
269-
return fstat(fd, st);
270-
#elif defined(__linux__)
268+
#elif defined(__linux__) && defined(__GLIBC__)
271269
return fstat64(fd, st);
270+
#else
271+
return fstat(fd, st);
272272
#endif
273273
}
274274
inline int my_stat(Str::StringRef path, my_stat_t* st)
275275
{
276276
#ifdef _WIN32
277277
return _wstati64(Str::UTF8To16(path).c_str(), st);
278-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
279-
return stat(path.c_str(), st);
280-
#elif defined(__linux__)
278+
#elif defined(__linux__) && defined(__GLIBC__)
281279
return stat64(path.c_str(), st);
280+
#else
281+
return stat(path.c_str(), st);
282282
#endif
283283
}
284284
inline intptr_t my_pread(int fd, void* buf, size_t count, offset_t offset)
@@ -294,10 +294,10 @@ inline intptr_t my_pread(int fd, void* buf, size_t count, offset_t offset)
294294
return -1;
295295
}
296296
return bytesRead;
297-
#elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
298-
return pread(fd, buf, count, offset);
299-
#elif defined(__linux__)
297+
#elif defined(__linux__) && defined(__GLIBC__)
300298
return pread64(fd, buf, count, offset);
299+
#else
300+
return pread(fd, buf, count, offset);
301301
#endif
302302
}
303303

0 commit comments

Comments
 (0)