KaisarCode

mmap.c

mmap.c - Memory map

mmap.c is a minimal portable C library and CLI for creating a binary file from stdin and later exposing that file as readonly memory through mmap.


CLI

Command line interface for the mmap tool.

Examples

Read standard input and write to file:

echo -n "example input" | ./bin/x86_64/linux/mmap set file.bin

Map file and print to standard output:

./bin/x86_64/linux/mmap get file.bin

Parameters

Command/FlagDescription
setRead stdin, replace file with exact bytes
getMap file, write exact bytes to stdout
-h, --helpShow help and usage
-v, --versionShow version

Public API

#include "mmap.h"

kc_mmap_t map = {0};

if (kc_mmap_open(&map, "file.bin") == KC_MMAP_OK) {
    const void *data = kc_mmap_data(&map);
    size_t size = kc_mmap_size(&map);

    // ...
}

kc_mmap_close(&map);

Lifecycle

  • kc_mmap_open() - initialize a new mmap context and map a file.
  • kc_mmap_data() - get pointer to mapped data.
  • kc_mmap_size() - get mapped data size.
  • kc_mmap_close() - release a mmap context. Safe on a zero-initialized object.

Build

Compiled artifacts are generated under bin/{arch}/{platform}/ for the host architecture running the build.

make clean && make

Multiarch Builds

The project is prepared to build artifacts for multiple architectures under bin/{arch}/{platform}/. A plain make builds only the current host architecture, while the targets below build the full matrix or a specific target.

make all
make x86_64/linux
make x86_64/windows
make i686/linux
make i686/windows
make aarch64/linux
make aarch64/android
make armv7/linux
make armv7/android
make armv7hf/linux
make riscv64/linux
make powerpc64le/linux
make mips/linux
make mipsel/linux
make mips64el/linux
make s390x/linux
make loongarch64/linux

License

GPLv3

This project is distributed under the GNU General Public License version 3 (GPLv3).


Repo

GitHub: kaisarcode/mmap.c