exhaust
Link to this paste: http://bugs.dragonflybsd.org/pastes/33
Added by tuxillo over 1 year ago.
Syntax: Plain Text
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <err.h>
#define NFILES 300
int
main(int argc, char *argv[])
{
int i;
int fd[NFILES];
struct stat st[NFILES];
char name[128];
char *p[NFILES];
for (i = 0; i < NFILES; i++) {
snprintf(name, 128, "tmpfiles/file%d", i);
if ((fd[i] = open(name, O_RDWR)) < 1)
err(1, "open");
if ((fstat(fd[i], &st[i])) == -1)
err(1, "fstat");
p[i] = mmap(0, st[i].st_size, PROT_READ | PROT_WRITE, MAP_SHARED, fd[i], 0);
if (p[i] == MAP_FAILED)
err(1, "mmap");
p[i][i+8] = i * 1024;
}
return 0;
}
|