1 /* 2 * Copyright (c) 2002, Intel Corporation. All rights reserved. 3 * Copyright (c) 2012, Cyril Hrubis <chrubis@suse.cz> 4 * 5 * This file is licensed under the GPL license. For the full content 6 * of this license, see the COPYING file at the top level of this 7 * source tree. 8 * 9 * The mmap() function shall fail if: 10 * [EBADF] The fildes argument is not a valid open file descriptor. 11 * 12 */ 13 14 15 #include <stdio.h> 16 #include <stdlib.h> 17 #include <unistd.h> 18 #include <sys/mman.h> 19 #include <sys/types.h> 20 #include <sys/stat.h> 21 #include <sys/wait.h> 22 #include <fcntl.h> 23 #include <string.h> 24 #include <errno.h> 25 #include "posixtest.h" 26 main(void)27int main(void) 28 { 29 void *pa; 30 int fd = -1; 31 32 pa = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0); 33 34 if (pa == MAP_FAILED && errno == EBADF) { 35 printf("Test PASSED\n"); 36 return PTS_PASS; 37 } 38 39 if (pa == MAP_FAILED) 40 perror("mmap()"); 41 42 printf("Test FAILED: Did not get EBADF when fd is invalid\n"); 43 return PTS_FAIL; 44 } 45