diff options
Diffstat (limited to 'lib/Handle.cc')
-rw-r--r-- | lib/Handle.cc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/lib/Handle.cc b/lib/Handle.cc index 83eb15d..2006b19 100644 --- a/lib/Handle.cc +++ b/lib/Handle.cc @@ -37,7 +37,7 @@ enum { INFLATE }; -Handle::Handle(const Handle & nh) : itell(0), h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0) +Handle::Handle(const Handle & nh) : itell(0), hFile(0), h(nh.h >= 0 ? dup(nh.h) : nh.h), closed(nh.closed), nonblock(nh.closed), zfile(0), z(0) { #ifdef DEBUG printm(M_INFO, String(_("Duplication of handle ")) + nh.h + _(" to ") + h + "\n"); @@ -513,3 +513,33 @@ void Handle::Flush() { #endif } } + +void * Handle::mmap(off_t offset, size_t length) { + if (length == -1) { + length = GetSize(); + } +#ifndef _WIN32 + return ::mmap(0, length, (CanRead() ? PROT_READ : 0) | (CanWrite() ? PROT_WRITE : 0), MAP_SHARED, h, offset); +#else + void * lpvMem = 0; + hMapObject = CreateFileMapping(
+ hFile,
+ 0,
+ CanWrite() ? PAGE_READWRITE : PAGE_READONLY,
+ 0,
+ length,
+ GetName().to_charp());
+ if (hMapObject != NULL) {
+ lpvMem = MapViewOfFile(
+ hMapObject,
+ CanWrite() ? FILE_MAP_WRITE : FILE_MAP_READ,
+ 0,
+ offset,
+ length);
+ if (lpvMem == NULL) {
+ CloseHandle(hMapObject);
+ }
+ }
+ return lpvMem; +#endif +} |