io/load: Enabled pread implementation for mingw32 (#1706)

This commit is contained in:
Jesper Stemann Andersen 2024-12-16 16:20:45 +01:00 committed by GitHub
parent af5a614aad
commit a82996e9fb
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -6,9 +6,11 @@
#include <sstream> #include <sstream>
// Used by pread implementation. // Used by pread implementation.
#ifdef _WIN32
#include <windows.h>
#endif
#ifdef _MSC_VER #ifdef _MSC_VER
#define NOMINMAX #define NOMINMAX
#include <windows.h>
#endif #endif
#include "mlx/io/load.h" #include "mlx/io/load.h"
@ -106,7 +108,7 @@ Dtype dtype_from_array_protocol(std::string_view t) {
"[from_str] Invalid array protocol type-string: " + std::string(t)); "[from_str] Invalid array protocol type-string: " + std::string(t));
} }
#ifdef _MSC_VER #ifdef _WIN32
// There is no pread on Windows, emulate it with ReadFile. // There is no pread on Windows, emulate it with ReadFile.
int64_t pread(int fd, void* buf, uint64_t size, uint64_t offset) { int64_t pread(int fd, void* buf, uint64_t size, uint64_t offset) {
HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd)); HANDLE file = reinterpret_cast<HANDLE>(_get_osfhandle(fd));