large-mmap.c 763 B

123456789101112131415161718192021222324
  1. /* -*- mode:c; c-file-style:"k&r"; c-basic-offset: 4; tab-width:4; indent-tabs-mode:nil; mode:auto-fill; fill-column:78; -*- */
  2. /* vim: set ts=4 sw=4 et tw=78 fo=cqt wm=0: */
  3. #include <stdio.h>
  4. #include <unistd.h>
  5. #include <sys/mman.h>
  6. #include <sys/types.h>
  7. #define TEST_LENGTH 0x10000f000
  8. int main() {
  9. FILE*fp=fopen("testfil","a+");
  10. if (!fp) { perror("fopen"); return 1; }
  11. int rv = ftruncate(fileno(fp), TEST_LENGTH);
  12. if (rv) {perror ("ftruncate"); return 1;}
  13. else
  14. printf("large-mmap: ftruncate OK\n");
  15. void* a=mmap(NULL, TEST_LENGTH, PROT_READ|PROT_WRITE, MAP_SHARED, fileno(fp), 0);
  16. if (!a) { perror("mmap"); return 1; }
  17. ((char*)a)[0x100000000]=0xff;
  18. printf("large-mmap: test completed OK\n");
  19. return 0;
  20. }