All pastes #1224219 Raw Edit

testcase for open/mmap/close

public c v1 · immutable
#1224219 ·published 2008-10-10 01:06 UTC
rendered paste body
#define _GNU_SOURCE#include <fcntl.h>#include <signal.h>#include <stdio.h>#include <unistd.h>#include <fnmatch.h>#include <stdlib.h>#include <string.h>#include <sys/mman.h>int main(int argc, char** argv) {    int fd;    void* mem;    for(;;) {        fd = open("/dev/zero", O_RDONLY);        if(fd == -1) {            perror("open");            return 1;        }        mem = mmap(NULL, 1, PROT_READ, MAP_PRIVATE, fd, 0);        if(mem == MAP_FAILED) {            perror("mmap");            return 2;        }        printf("mapped fd %d at %p\n", fd, mem);        if(close(fd)) {            perror("close");            return 3;        }    }}