From f21dcde54b09913550036e6501cca935278597d9 Mon Sep 17 00:00:00 2001 From: Tom Smeding Date: Sun, 29 Mar 2026 23:25:10 +0200 Subject: Initial --- cbits/mmap.c | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 cbits/mmap.c (limited to 'cbits') diff --git a/cbits/mmap.c b/cbits/mmap.c new file mode 100644 index 0000000..079959f --- /dev/null +++ b/cbits/mmap.c @@ -0,0 +1,26 @@ +#include +#include +#include + + +void* ircbrowse_mmap(int fd, size_t *lengthp) { + struct stat statbuf; + int ret = fstat(fd, &statbuf); + if (ret < 0) { + perror("stat"); + return NULL; + } + void *addr = mmap(NULL, statbuf.st_size, PROT_READ, MAP_SHARED, fd, 0); + if (addr == NULL) { + perror("mmap"); + } + if (lengthp != NULL) *lengthp = statbuf.st_size; + return addr; +} + +void ircbrowse_munmap(void *addr, size_t length) { + int ret = munmap(addr, length); + if (ret < 0) { + perror("munmap"); + } +} -- cgit v1.3