@@ -32,6 +32,12 @@ SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
3232#include " minizip/unzip.h"
3333#endif
3434
35+ #if defined(__GLIBC__)
36+ #if !defined(_FILE_OFFSET_BITS) || (_FILE_OFFSET_BITS != 64)
37+ #error _FILE_OFFSET_BITS should be set to 64 on glibc
38+ #endif
39+ #endif
40+
3541#ifdef BUILD_VM
3642#include " shared/VMMain.h"
3743#else
@@ -175,6 +181,7 @@ enum class openMode_t {
175181 MODE_APPEND,
176182 MODE_EDIT
177183};
184+
178185inline int my_open (Str::StringRef path, openMode_t mode)
179186{
180187 int mode_ = Util::ordinal (mode);
@@ -192,14 +199,10 @@ inline int my_open(Str::StringRef path, openMode_t mode)
192199 int fd = _open_osfhandle (reinterpret_cast <intptr_t >(h), modes[mode_] | O_BINARY | O_NOINHERIT);
193200 if (fd == -1 )
194201 CloseHandle (h);
195- #elif defined(__FreeBSD__) || defined(__APPLE__)
196- // O_CLOEXEC is supported in macOS from 10.7 onwards
202+ #else
203+ // This doesn't actually work in Native Client, but it's not used anyways.
204+ // O_CLOEXEC is supported in macOS from 10.7 onwards.
197205 int fd = open (path.c_str (), modes[mode_] | O_CLOEXEC, 0666 );
198- #elif defined(__linux__)
199- int fd = open64 (path.c_str (), modes[mode_] | O_CLOEXEC | O_LARGEFILE, 0666 );
200- #elif defined(__native_client__)
201- // This doesn't actually work, but it's not used anyways
202- int fd = open (path.c_str (), modes[mode_], 0666 );
203206#endif
204207
205208#ifndef _WIN32
@@ -238,47 +241,37 @@ inline offset_t my_ftell(FILE* fd)
238241{
239242#ifdef _WIN32
240243 return _ftelli64 (fd);
241- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
244+ #else
242245 return ftello (fd);
243- #elif defined(__linux__)
244- return ftello64 (fd);
245246#endif
246247}
247248inline int my_fseek (FILE* fd, offset_t off, int whence)
248249{
249250#ifdef _WIN32
250251 return _fseeki64 (fd, off, whence);
251- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
252+ #else
252253 return fseeko (fd, off, whence);
253- #elif defined(__linux__)
254- return fseeko64 (fd, off, whence);
255254#endif
256255}
257256#ifdef _WIN32
258257typedef struct _stati64 my_stat_t ;
259- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
258+ #else
260259using my_stat_t = struct stat ;
261- #elif defined(__linux__)
262- using my_stat_t = struct stat64 ;
263260#endif
264261inline int my_fstat (int fd, my_stat_t * st)
265262{
266263#ifdef _WIN32
267264 return _fstati64 (fd, st);
268- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
265+ #else
269266 return fstat (fd, st);
270- #elif defined(__linux__)
271- return fstat64 (fd, st);
272267#endif
273268}
274269inline int my_stat (Str::StringRef path, my_stat_t * st)
275270{
276271#ifdef _WIN32
277272 return _wstati64 (Str::UTF8To16 (path).c_str (), st);
278- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
273+ #else
279274 return stat (path.c_str (), st);
280- #elif defined(__linux__)
281- return stat64 (path.c_str (), st);
282275#endif
283276}
284277inline intptr_t my_pread (int fd, void * buf, size_t count, offset_t offset)
@@ -294,10 +287,8 @@ inline intptr_t my_pread(int fd, void* buf, size_t count, offset_t offset)
294287 return -1 ;
295288 }
296289 return bytesRead;
297- #elif defined(__FreeBSD__) || defined(__APPLE__) || defined(__native_client__)
290+ #else
298291 return pread (fd, buf, count, offset);
299- #elif defined(__linux__)
300- return pread64 (fd, buf, count, offset);
301292#endif
302293}
303294
0 commit comments