Skip to content

Instantly share code, notes, and snippets.

@andyrudoff
Last active July 30, 2019 13:41
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save andyrudoff/c22dd375d01925702775277650a1ba0e to your computer and use it in GitHub Desktop.
Save andyrudoff/c22dd375d01925702775277650a1ba0e to your computer and use it in GitHub Desktop.
#include <sys/mman.h>
#include <err.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
int
main(int argc, char *argv[])
{
int fd;
char *pmaddr;
if (argc != 2) {
fprintf(stderr, "Usage: %s filename\n", argv[0]);
exit(1);
}
if ((fd = open(argv[1], O_RDWR|O_CREAT, 0644)) < 0)
err(1, "open: %s", argv[2]);
if (ftruncate(fd, (off_t)40960) < 0)
err(1, "ftruncate: %s", argv[2]);
if ((pmaddr = (char *)mmap(NULL, 40960, PROT_READ|PROT_WRITE,
MAP_SHARED_VALIDATE|MAP_SYNC,
fd, 0)) == MAP_FAILED)
err(1, "mmap(MAP_SYNC): %s", argv[2]);
close(fd);
printf("MAP_SYNC successful.\n");
exit(0);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment