Map a region of the file with descriptor into memory.

Synopsis

Declared in <bdls_filesystemutil.h>

static
int
map(
    FileDescriptor descriptor,
    void** address,
    Offset offset,
    std::size_t size,
    int mode);

Description

Map the region of the specified size bytes, starting at the specified offset bytes into the file with the specified descriptor to memory, and load into the specified address of the mapped area. Return 0 on success, and a non‐zero value otherwise. The access permissions for mapping memory are defined by the specified mode, which may be a combination of MemoryUtil::k_ACCESS_READ, MemoryUtil::k_ACCESS_WRITE and MemoryUtil::k_ACCESS_EXECUTE. Note that on failure, the value of address is undefined. Also note that mapping will succeed even if there are fewer than offset + size bytes in the specified file, and an attempt to access the mapped memory beyond the end of the file will result in undefined behavior (i.e., this function does not grow the file to guarantee it can accommodate the mapped region). Also note that mapping past the end of file may return 0, but any access of the resulting mapped memory may segfault.

Return Value

0 on success, and a non‐zero value otherwise

Parameters

Name

Description

descriptor

file descriptor of the file to map

address

receives the base address of the mapped region

offset

byte offset in the file at which mapping begins

size

length in bytes of the region to map

mode

memory access permissions for the mapping

Created with MrDocs