• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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  * When the implementation selects a
10  * The mmap() function shall fail if:
11  * [EINVAL] The value of flags is invalid (neither MAP_PRIVATE nor MAP_SHARED is
12  * set).
13  *
14  */
15 
16 
17 #include <stdio.h>
18 #include <stdlib.h>
19 #include <unistd.h>
20 #include <sys/mman.h>
21 #include <sys/types.h>
22 #include <sys/stat.h>
23 #include <sys/wait.h>
24 #include <fcntl.h>
25 #include <string.h>
26 #include <errno.h>
27 #include "posixtest.h"
28 
main(void)29 int main(void)
30 {
31 	char tmpfname[256];
32 
33 	void *pa;
34 	size_t size = 1024;
35 	int flag = ~0;
36 	int fd;
37 
38 	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_21_1_%d", getpid());
39 	unlink(tmpfname);
40 	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
41 	if (fd == -1) {
42 		printf("Error at open(): %s\n", strerror(errno));
43 		return PTS_UNRESOLVED;
44 	}
45 	unlink(tmpfname);
46 
47 	if (ftruncate(fd, size) == -1) {
48 		printf("Error at ftruncate(): %s\n", strerror(errno));
49 		return PTS_UNRESOLVED;
50 	}
51 
52 	pa = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, fd, 0);
53 	if (pa == MAP_FAILED && errno == EINVAL) {
54 		printf("Test PASSED\n");
55 		return PTS_PASS;
56 	}
57 
58 	close(fd);
59 	munmap(pa, size);
60 	printf("Test FAILED\n");
61 	return PTS_FAIL;
62 }
63