• 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 
28 #include "posixtest.h"
29 #include "tempfile.h"
30 
main(void)31 int main(void)
32 {
33 	char tmpfname[PATH_MAX];
34 
35 	void *pa;
36 	size_t size = 1024;
37 	int flag = ~0;
38 	int fd;
39 
40 	PTS_GET_TMP_FILENAME(tmpfname, "pts_mmap_21_1");
41 	unlink(tmpfname);
42 	fd = open(tmpfname, O_CREAT | O_RDWR | O_EXCL, S_IRUSR | S_IWUSR);
43 	if (fd == -1) {
44 		printf("Error at open(): %s\n", strerror(errno));
45 		return PTS_UNRESOLVED;
46 	}
47 	unlink(tmpfname);
48 
49 	if (ftruncate(fd, size) == -1) {
50 		printf("Error at ftruncate(): %s\n", strerror(errno));
51 		return PTS_UNRESOLVED;
52 	}
53 
54 	pa = mmap(NULL, size, PROT_READ | PROT_WRITE, flag, fd, 0);
55 	if (pa == MAP_FAILED && errno == EINVAL) {
56 		printf("Test PASSED\n");
57 		return PTS_PASS;
58 	}
59 
60 	close(fd);
61 	munmap(pa, size);
62 	printf("Test FAILED\n");
63 	return PTS_FAIL;
64 }
65