Cleanup scaffolds
[mirrors/Programs.git] / c / mmap / mmap.c
CommitLineData
b4d0545c
TM
1//#define _GNU_SOURCE
2
21c4e167 3#include <stdio.h>
21c4e167 4#include <sys/types.h>
b4d0545c
TM
5#include <sys/stat.h>
6#include <sys/mman.h>
7#include <fcntl.h>
8#include <unistd.h>
9#include <string.h>
21c4e167 10
b4d0545c
TM
11#define MEM_PATH "hello.bin"
12#define MEM_SIZE 1048576
21c4e167
H
13
14int main() {
b4d0545c
TM
15 int fd;
16 fd = open(MEM_PATH, O_RDWR | O_SYNC | O_CREAT | O_CLOEXEC, S_IRUSR | S_IWUSR);
17 ftruncate(fd, MEM_SIZE);
21c4e167 18
b4d0545c
TM
19 void *mem;
20 mem = mmap(NULL, MEM_SIZE, PROT_READ | PROT_WRITE, MAP_SHARED , fd, 0);
21 close(fd);
21c4e167 22
b4d0545c
TM
23 char hello[] = "Hello!";
24 memcpy(mem, hello, sizeof(hello));
25 msync(mem, sizeof(hello), MS_SYNC);
21c4e167 26}
This page took 0.876498 seconds and 4 git commands to generate.