From 00c936aaf66d89d9dbc3c0f4f90b2a6d38edf4cb Mon Sep 17 00:00:00 2001 From: Kelvin Sherlock Date: Fri, 5 Aug 2016 09:38:35 -0400 Subject: [PATCH] mapped_file w/ length of 0. --- mapped_file.cpp | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/mapped_file.cpp b/mapped_file.cpp index a67aaa4..61683b4 100644 --- a/mapped_file.cpp +++ b/mapped_file.cpp @@ -48,7 +48,6 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si HANDLE fh; HANDLE mh; - LARGE_INTEGER file_size; // length of 0 in CreateFileMapping / MapViewOfFile // means map the entire file. @@ -71,10 +70,12 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si auto fh_close = make_unique_resource(fh, CloseHandle); - GetFileSizeEx(fh, &file_size); - if (length == -1) + if (length == -1){ + LARGE_INTEGER file_size; + GetFileSizeEx(fh, &file_size); length = file_size.QuadPart; + } DWORD protect = 0; DWORD access = 0; @@ -246,7 +247,7 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si length = st.st_size; } - + if (length == 0) return; // mmap w/ length of 0 is EINVAL. _data = ::mmap(0, length, flags == readonly ? PROT_READ : PROT_READ | PROT_WRITE,