Merge pull request #179 from richinseattle/windows-ftell64-fix
use ssize_t/int64 and 64bit version of ftell on windows
This commit is contained in:
@@ -483,7 +483,7 @@ int main(int argc, char *argv[]) {
|
||||
TransformerWeights weights;
|
||||
int fd = 0; // file descriptor for memory mapping
|
||||
float* data = NULL; // memory mapped data pointer
|
||||
long file_size; // size of the checkpoint file in bytes
|
||||
ssize_t file_size; // size of the checkpoint file in bytes
|
||||
{
|
||||
FILE *file = fopen(checkpoint, "rb");
|
||||
if (!file) { printf("Couldn't open file %s\n", checkpoint); return 1; }
|
||||
|
||||
@@ -2,7 +2,6 @@
|
||||
#include <errno.h>
|
||||
#include <io.h>
|
||||
|
||||
|
||||
#ifndef FILE_MAP_EXECUTE
|
||||
#define FILE_MAP_EXECUTE 0x0020
|
||||
#endif /* FILE_MAP_EXECUTE */
|
||||
@@ -53,10 +52,9 @@ static DWORD __map_mmap_prot_file(const int prot)
|
||||
return desiredAccess;
|
||||
}
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, ssize_t off)
|
||||
{
|
||||
HANDLE fm, h;
|
||||
|
||||
void * map = MAP_FAILED;
|
||||
|
||||
#ifdef _MSC_VER
|
||||
@@ -64,19 +62,15 @@ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
|
||||
#pragma warning(disable: 4293)
|
||||
#endif
|
||||
|
||||
const DWORD dwFileOffsetLow = (sizeof(off_t) <= sizeof(DWORD)) ?
|
||||
(DWORD)off : (DWORD)(off & 0xFFFFFFFFL);
|
||||
const DWORD dwFileOffsetHigh = (sizeof(off_t) <= sizeof(DWORD)) ?
|
||||
(DWORD)0 : (DWORD)((off >> 32) & 0xFFFFFFFFL);
|
||||
const DWORD dwFileOffsetLow = (DWORD)(off & 0xFFFFFFFFL);
|
||||
const DWORD dwFileOffsetHigh = (DWORD)((off >> 32) & 0xFFFFFFFFL);
|
||||
const DWORD protect = __map_mmap_prot_page(prot);
|
||||
const DWORD desiredAccess = __map_mmap_prot_file(prot);
|
||||
|
||||
const off_t maxSize = off + (off_t)len;
|
||||
const ssize_t maxSize = off + (ssize_t)len;
|
||||
|
||||
const DWORD dwMaxSizeLow = (sizeof(off_t) <= sizeof(DWORD)) ?
|
||||
(DWORD)maxSize : (DWORD)(maxSize & 0xFFFFFFFFL);
|
||||
const DWORD dwMaxSizeHigh = (sizeof(off_t) <= sizeof(DWORD)) ?
|
||||
(DWORD)0 : (DWORD)((maxSize >> 32) & 0xFFFFFFFFL);
|
||||
const DWORD dwMaxSizeLow = (DWORD)(maxSize & 0xFFFFFFFFL);
|
||||
const DWORD dwMaxSizeHigh = (DWORD)((maxSize >> 32) & 0xFFFFFFFFL);
|
||||
|
||||
#ifdef _MSC_VER
|
||||
#pragma warning(pop)
|
||||
@@ -110,11 +104,11 @@ void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off)
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
return MAP_FAILED;
|
||||
}
|
||||
|
||||
|
||||
map = MapViewOfFile(fm, desiredAccess, dwFileOffsetHigh, dwFileOffsetLow, len);
|
||||
|
||||
CloseHandle(fm);
|
||||
|
||||
|
||||
if (map == NULL)
|
||||
{
|
||||
errno = __map_mman_error(GetLastError(), EPERM);
|
||||
|
||||
@@ -5,6 +5,8 @@
|
||||
#include <windows.h>
|
||||
#include <time.h>
|
||||
|
||||
#define ssize_t __int64
|
||||
#define ftell _ftelli64
|
||||
|
||||
// Below code is originally from mman-win32
|
||||
//
|
||||
@@ -51,7 +53,7 @@ extern "C" {
|
||||
/* Flags for portable clock_gettime call. */
|
||||
#define CLOCK_REALTIME 0
|
||||
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, off_t off);
|
||||
void* mmap(void *addr, size_t len, int prot, int flags, int fildes, ssize_t off);
|
||||
int munmap(void *addr, size_t len);
|
||||
int mprotect(void *addr, size_t len, int prot);
|
||||
int msync(void *addr, size_t len, int flags);
|
||||
|
||||
Reference in New Issue
Block a user