sc/memory-map/mmap_example.c

28 lines
437 B
C
Raw Permalink Normal View History

2020-11-25 09:25:38 +03:00
2020-12-28 02:52:22 +03:00
#include "sc_mmap.h"
#include <assert.h>
#include <stdio.h>
2020-11-25 09:25:38 +03:00
int main(void)
2020-11-25 09:25:38 +03:00
{
int rc;
struct sc_mmap mmap;
2020-12-28 02:52:22 +03:00
rc = sc_mmap_init(&mmap, "x.txt", O_RDWR | O_CREAT | O_TRUNC,
PROT_READ | PROT_WRITE, MAP_SHARED, 0, 15000);
assert(rc == 0);
2020-12-28 02:52:22 +03:00
void *ptr = mmap.ptr;
size_t mapped_len = mmap.len;
2020-12-28 02:52:22 +03:00
printf("mapped len : %zu \n", mapped_len);
2020-12-28 02:52:22 +03:00
*(char *) ptr = 't';
2020-11-25 09:25:38 +03:00
sc_mmap_msync(&mmap, 0, 4096);
sc_mmap_term(&mmap);
2020-11-25 09:25:38 +03:00
return 0;
2020-11-25 09:25:38 +03:00
}