LC_MMAPFILE(3)

NAME
lc_mmapfile - map or unmap files or devices into memory

LIBRARY
Librecast library (liblibrecast, -llibrecast)

SYNOPSIS
#include <librecast/sync.h>

void *lc_mmapfile(const char *pathname, size_t *len, int prot, int flags,
                  off_t offset, struct stat *sb);

Compile and link with -llibrecast.

DESCRIPTION
The lc_mmapfile() function is a convenience wrapper for mmap(2) which open(2)s and maps a file in a single call. See mmap(2) for a full description.

If prot has the PROT_WRITE flag set, pathname is open(2)'ed with the O_RDWR and O_CREAT flags set (the file is created and opened read-write), otherwise it is opened O_RDONLY. The mode for the created file can be set by setting st_mode in sb when calling lc_mmapfile().

If len points to a value greater than zero, ftruncate(2) is called to truncate the file to the specified length. Otherwise, the variable len points to is set to the size of the file.

When done, the file can be unmapped and the memory freed by calling munmap(3).

RETURN VALUE
On success, lc_mmapfile() returns a pointer to the mapped area. On error, the value MAP_FAILED (that is, (void*)-1 ) is returned, and errno is set to indicate the error.

ERRORS

ENODATA
    File is zero length.

See also open(2), mmap(2), fstat(2), and ftruncate(2).

SEE ALSO
mmap(2), msync(2), munmap(2), open(2), fstat(2), ftruncate(2)