1/*
2 * Copyright (c) 2015 The Chromium OS Authors. All rights reserved.
3 * Use of this source code is governed by a BSD-style license that can be
4 * found in the LICENSE file.
5 */
6
7#include <fcntl.h>
8#include <stdlib.h>
9#include <unistd.h>
10
11#include <sys/mman.h>
12#include <sys/stat.h>
13#include <sys/types.h>
14
15int main(void)
16{
17	char *buf;
18	int fd, ret;
19	unsigned int i;
20
21	fd = open("/dev/zero", O_RDONLY);
22	if (fd < 0)
23		return 1;
24
25	buf = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, fd, 0);
26	if (buf == (char *)-1)
27		return 2;
28
29	for (i = 0; i < 4096; i++) {
30		if (buf[i] != 0)
31			return 3;
32	}
33
34	ret = munmap(buf, 4096);
35	if (ret < 0)
36		return 4;
37
38	ret = close(fd);
39	if (ret < 0)
40		return 5;
41
42	return 0;
43}
44