diff options
| author | Tom Smeding <tom@tomsmeding.com> | 2026-03-29 23:25:10 +0200 |
|---|---|---|
| committer | Tom Smeding <tom@tomsmeding.com> | 2026-03-29 23:25:10 +0200 |
| commit | f21dcde54b09913550036e6501cca935278597d9 (patch) | |
| tree | 505f373b1bce690f0bafc2038636721126d9bcad /cbits | |
Initial
Diffstat (limited to 'cbits')
| -rw-r--r-- | cbits/mmap.c | 26 |
1 files changed, 26 insertions, 0 deletions
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 <stdio.h> +#include <sys/mman.h> +#include <sys/stat.h> + + +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"); + } +} |
