---
name: "lc_mmapfile"
section: "3"
platform: "linux"
package: "liblibrecast-dev"
version: "0.9.1-1"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/lc_mmapfile"
---

# lc\_mmapfile(3)

map or unmap files or devices into memory

## 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)](/mmap/2.md) which [**open**(2)](/open/2.md)s and maps a file in a single call. See [**mmap**(2)](/mmap/2.md) for a full description.

If *prot* has the **PROT\_WRITE** flag set, *pathname* is [**open**(2)](/open/2.md)'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)](/ftruncate/2.md) 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)](/open/2.md), [**mmap**(2)](/mmap/2.md), [**fstat**(2)](/fstat/2.md), and [**ftruncate**(2)](/ftruncate/2.md).

## SEE ALSO

[**mmap**(2)](/mmap/2.md), [**msync**(2)](/msync/2.md), [**munmap**(2)](/munmap/2.md), [**open**(2)](/open/2.md), [**fstat**(2)](/fstat/2.md), [**ftruncate**(2)](/ftruncate/2.md)
