mirror of
https://github.com/ksherlock/mpw-shell.git
synced 2025-03-10 19:34:00 +00:00
mapped file -- if length is 0, return an unopened mapped file. Posix would EINVAL on a length of 0.
This commit is contained in:
parent
50ac7355bd
commit
fbcbfffcb5
@ -66,7 +66,6 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
|||||||
|
|
||||||
HANDLE fh;
|
HANDLE fh;
|
||||||
HANDLE mh;
|
HANDLE mh;
|
||||||
LARGE_INTEGER file_size;
|
|
||||||
|
|
||||||
// length of 0 in CreateFileMapping / MapViewOfFile
|
// length of 0 in CreateFileMapping / MapViewOfFile
|
||||||
// means map the entire file.
|
// means map the entire file.
|
||||||
@ -89,10 +88,14 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
|||||||
|
|
||||||
auto fh_close = make_unique_resource(fh, CloseHandle);
|
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;
|
length = file_size.QuadPart;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (length == 0) return;
|
||||||
|
|
||||||
DWORD protect = 0;
|
DWORD protect = 0;
|
||||||
DWORD access = 0;
|
DWORD access = 0;
|
||||||
@ -232,7 +235,6 @@ void mapped_file_base::close() {
|
|||||||
void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, size_t offset) {
|
void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, size_t offset) {
|
||||||
|
|
||||||
int fd;
|
int fd;
|
||||||
struct stat st;
|
|
||||||
|
|
||||||
int oflags = 0;
|
int oflags = 0;
|
||||||
|
|
||||||
@ -257,12 +259,18 @@ void mapped_file_base::open(const path_type& p, mapmode flags, size_t length, si
|
|||||||
//defer([fd](){::close(fd); });
|
//defer([fd](){::close(fd); });
|
||||||
auto close_fd = make_unique_resource(fd, ::close);
|
auto close_fd = make_unique_resource(fd, ::close);
|
||||||
|
|
||||||
if (::fstat(fd, &st) < 0) {
|
|
||||||
throw_error(errno);
|
|
||||||
|
if (length == -1) {
|
||||||
|
struct stat st;
|
||||||
|
|
||||||
|
if (::fstat(fd, &st) < 0) {
|
||||||
|
throw_error(errno);
|
||||||
|
}
|
||||||
|
length = st.st_size;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (length == 0) return;
|
||||||
if (length == -1) length = st.st_size;
|
|
||||||
|
|
||||||
_data = ::mmap(0, length,
|
_data = ::mmap(0, length,
|
||||||
flags == readonly ? PROT_READ : PROT_READ | PROT_WRITE,
|
flags == readonly ? PROT_READ : PROT_READ | PROT_WRITE,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user