• 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 #define _XOPEN_SOURCE 600
17 
18 #include <stdio.h>
19 #include <stdlib.h>
20 #include <unistd.h>
21 #include <sys/mman.h>
22 #include <sys/types.h>
23 #include <sys/stat.h>
24 #include <sys/wait.h>
25 #include <fcntl.h>
26 #include <string.h>
27 #include <errno.h>
28 #include "posixtest.h"
29 
main(void)30 int main(void)
31 {
32 	char tmpfname[256];
33 
34 	void *pa;
35 	size_t size = 1024;
36 	int flag;
37 	int fd;
38 
39 	snprintf(tmpfname, sizeof(tmpfname), "/tmp/pts_mmap_21_1_%d", getpid());
40 	unlink(tmpfname);
41 	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
42 	if (fd == -1) {
43 		printf("Error at open(): %s\n", strerror(errno));
44 		return PTS_UNRESOLVED;
45 	}
46 	unlink(tmpfname);
47 
48 	if (ftruncate(fd, size) == -1) {
49 		printf("Error at ftruncate(): %s\n", strerror(errno));
50 		return PTS_UNRESOLVED;
51 	}
52 
53 	flag = MAP_SHARED;
54 	while (flag == MAP_SHARED || flag == MAP_PRIVATE || flag == MAP_FIXED)
55 		flag++;
56 
57 	pa = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, fd, 0);
58 	if (pa == MAP_FAILED && errno == EINVAL) {
59 		printf("Test PASSED\n");
60 		return PTS_PASS;
61 	}
62 
63 	close(fd);
64 	munmap(pa, size);
65 	printf("Test FAILED\n");
66 	return PTS_FAIL;
67 }
68