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 main(void)15int main(void) { 16 char *buf; 17 int fd, ret; 18 unsigned int i; 19 20 fd = open("/dev/zero", O_RDONLY); 21 if (fd < 0) 22 return 1; 23 24 buf = mmap(NULL, 4096, PROT_READ, MAP_PRIVATE, fd, 0); 25 if (buf == (char *)-1) 26 return 2; 27 28 for (i = 0; i < 4096; i++) { 29 if (buf[i] != 0) 30 return 3; 31 } 32 33 ret = munmap(buf, 4096); 34 if (ret < 0) 35 return 4; 36 37 ret = close(fd); 38 if (ret < 0) 39 return 5; 40 41 return 0; 42 } 43