1 /* 2 * Copyright (c) 2012, Cyril Hrubis <chrubis (at) suse.cz> 3 * 4 * This file is licensed under the GPL license. For the full content 5 * of this license, see the COPYING file at the top level of this 6 * source tree. 7 * 8 * If len is zero, mmap() shall fail and no mapping shall be established. 9 */ 10 11 #define _XOPEN_SOURCE 600 12 13 #include <stdio.h> 14 #include <stdlib.h> 15 #include <unistd.h> 16 #include <limits.h> 17 #include <sys/mman.h> 18 #include <sys/types.h> 19 #include <sys/stat.h> 20 #include <sys/wait.h> 21 #include <fcntl.h> 22 #include <string.h> 23 #include <errno.h> 24 #include "posixtest.h" 25 26 int main(void) 27 { 28 char tmpfname[256]; 29 30 void *pa; 31 int fd; 32 33 snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_31_1_%d", getpid()); 34 unlink(tmpfname); 35 fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR); 36 if (fd == -1) { 37 printf("Error at open(): %s\n", strerror(errno)); 38 return PTS_UNRESOLVED; 39 } 40 unlink(tmpfname); 41 42 pa = mmap(NULL, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 43 if (pa == MAP_FAILED && errno == EINVAL) { 44 printf("Got EINVAL\n"); 45 printf("Test PASSED\n"); 46 close(fd); 47 return PTS_PASS; 48 } 49 50 if (pa == MAP_FAILED) 51 printf("Test FAILED: Expected EINVAL got %s\n", strerror(errno)); 52 else 53 printf("Test FAILED: mmap() succedded unexpectedly\n"); 54 55 close(fd); 56 munmap(pa, 0); 57 return PTS_FAIL; 58 } 59