---
name: "buffer_mmapread"
section: "3"
platform: "linux"
package: "libowfat-dev"
version: "0.32-5"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/buffer_mmapread"
---

# buffer\_mmapread(3)

create read-only memory-mapped file buffer

## NAME

buffer\_mmapread - create read-only memory-mapped file buffer

## SYNTAX

**#include \<libowfat/buffer.h\>**

int **buffer\_mmapread**(buffer &*b*,const char\* *filename*);

## DESCRIPTION

buffer\_mmapread opens *filename* for reading and fills *b* so that the contents of the file can be read from it.  Using mmap is more efficient than reading through a real buffer, but you have to call buffer\_close to unmap the memory in the end.

## EXAMPLE

  \#include \<libowfat/buffer.h\>\
   \#include \<libowfat/open.h\>

  buffer input;\
   char x;

  buffer\_mmapread(&input,"/etc/passwd");\
   while (buffer\_get(&input,&x,1)==1) {\
     buffer\_put(buffer\_1,&x,1);\
     if (x=='\\n') break;\
   }\
   buffer\_flush(buffer\_1);\
   buffer\_close(&input);

## RETURN VALUE

**buffer\_mmapread** returns 0 if everything was fine, -1 on error (setting *errno*).

## SEE ALSO

[buffer\_flush(3)](/buffer_flush/3.md), [buffer(3)](/buffer/3.md)
