Home | History | Annotate | Download | only in mmap
      1 /*
      2  * Copyright (c) 2002, Intel Corporation. All rights reserved.
      3  * Copyright (c) 2012, Cyril Hrubis <chrubis (at) 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 #define _XOPEN_SOURCE 600
     15 
     16 #include <stdio.h>
     17 #include <stdlib.h>
     18 #include <unistd.h>
     19 #include <sys/mman.h>
     20 #include <sys/types.h>
     21 #include <sys/stat.h>
     22 #include <sys/wait.h>
     23 #include <fcntl.h>
     24 #include <string.h>
     25 #include <errno.h>
     26 #include "posixtest.h"
     27 
     28 int main(void)
     29 {
     30 	void *pa;
     31 	int fd = -1;
     32 
     33 	pa = mmap(NULL, 1024, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
     34 
     35 	if (pa == MAP_FAILED && errno == EBADF) {
     36 		printf("Test PASSED\n");
     37 		return PTS_PASS;
     38 	}
     39 
     40 	if (pa == MAP_FAILED)
     41 		perror("mmap()");
     42 
     43 	printf("Test FAILED: Did not get EBADF when fd is invalid\n");
     44 	return PTS_FAIL;
     45 }
     46