Advertisement
Guest User

Untitled

a guest
Mar 19th, 2018
74
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.51 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <sys/stat.h>
  3. #include <unistd.h>
  4. #include <sys/mman.h>
  5. #include <fcntl.h>
  6.  
  7. int main(int argc, char* argv[]) {
  8. double sum = 0;
  9. int fd = open(argv[1], O_RDONLY);
  10. struct stat buf;
  11. fstat(fd, &buf);
  12. double *map = mmap(0, buf.st_size, PROT_READ, MAP_SHARED, fd, 0);
  13. size_t size = buf.st_size / sizeof(double);
  14. for (size_t i = 0; i < size; i++) {
  15. sum += map[i];
  16. }
  17. printf("%a\n", sum / size);
  18. munmap(0, buf.st_size);
  19. close(fd);
  20. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement