• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2012, Cyril Hrubis <chrubis@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 
12 #include <stdio.h>
13 #include <stdlib.h>
14 #include <unistd.h>
15 #include <limits.h>
16 #include <sys/mman.h>
17 #include <sys/types.h>
18 #include <sys/stat.h>
19 #include <sys/wait.h>
20 #include <fcntl.h>
21 #include <string.h>
22 #include <errno.h>
23 
24 #include "posixtest.h"
25 #include "tempfile.h"
26 
main(void)27 int main(void)
28 {
29 	char tmpfname[PATH_MAX];
30 
31 	void *pa;
32 	int fd;
33 
34 	PTS_GET_TMP_FILENAME(tmpfname, "pts_mmap_32_1");
35 	unlink(tmpfname);
36 	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
37 	if (fd == -1) {
38 		printf("Error at open(): %s\n", strerror(errno));
39 		return PTS_UNRESOLVED;
40 	}
41 	unlink(tmpfname);
42 
43 	pa = mmap(NULL, 0, PROT_READ | PROT_WRITE, MAP_SHARED, fd, 0);
44 	if (pa == MAP_FAILED && errno == EINVAL) {
45 		printf("Got EINVAL\n");
46 		printf("Test PASSED\n");
47 		close(fd);
48 		return PTS_PASS;
49 	}
50 
51 	if (pa == MAP_FAILED)
52 		printf("Test FAILED: Expected EINVAL got %s\n", strerror(errno));
53 	else
54 		printf("Test FAILED: mmap() succedded unexpectedly\n");
55 
56 	close(fd);
57 	munmap(pa, 0);
58 	return PTS_FAIL;
59 }
60