2021-02-07 22:31:04 +03:00
|
|
|
### Mmap
|
2020-12-27 20:58:52 +03:00
|
|
|
|
|
|
|
### Mmap wrapper
|
|
|
|
|
2021-02-06 10:19:31 +03:00
|
|
|
- Basic mmap wrapper for Posix and Windows.
|
2020-12-28 02:52:22 +03:00
|
|
|
|
|
|
|
```c
|
|
|
|
|
|
|
|
#include "sc_mmap.h"
|
|
|
|
|
|
|
|
#include <assert.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
|
|
|
|
int main(int argc, char *argv[])
|
|
|
|
{
|
|
|
|
int rc;
|
|
|
|
struct sc_mmap mmap;
|
|
|
|
|
|
|
|
rc = sc_mmap_init(&mmap, "x.txt", O_RDWR | O_CREAT | O_TRUNC,
|
|
|
|
PROT_READ | PROT_WRITE, MAP_SHARED, 0, 15000);
|
|
|
|
assert(rc == 0);
|
|
|
|
|
|
|
|
void* ptr = mmap.ptr;
|
|
|
|
size_t mapped_len = mmap.len;
|
|
|
|
|
|
|
|
printf("mapped len : %zu \n", mapped_len);
|
|
|
|
|
|
|
|
*(char*)ptr = 't';
|
|
|
|
|
|
|
|
sc_mmap_msync(&mmap, 0, 4096);
|
|
|
|
sc_mmap_term(&mmap);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
```
|
2020-12-27 20:58:52 +03:00
|
|
|
|