Page MenuHomeFreeBSD

mmap_trunc_core.c

Authored By
avg
Jan 20 2017, 12:58 PM
Size
868 B
Referenced Files
None
Subscribers
None

mmap_trunc_core.c

#include <sys/types.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
static const int SIZE = 4096;
int main (int argc, char *argv[])
{
char *p;
int fd;
if (argc < 2) {
fprintf (stderr, "usage: %s <file>\n", argv[0]);
return (1);
}
fd = open(argv[1], O_CREAT | O_EXCL | O_RDWR, 0660);
if (fd == -1) {
perror ("open");
return (1);
}
unlink(argv[1]);
if (ftruncate(fd, SIZE) == -1) {
perror ("ftruncate");
return (1);
}
p = mmap(NULL, 4 * SIZE, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
if (p == MAP_FAILED) {
perror ("mmap");
return (1);
}
abort();
}

File Metadata

Mime Type
text/x-c
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
723846
Default Alt Text
mmap_trunc_core.c (868 B)

Event Timeline