Advertisement
Guest User

Untitled

a guest
Nov 17th, 2018
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.96 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <sys/stat.h>
  4. #include <math.h>
  5. #include <fcntl.h>
  6. #include <sys/time.h>
  7. #include <sys/types.h>
  8. #include <sys/mman.h>
  9. #include <unistd.h>
  10. #include <string.h>
  11.  
  12. int main(int argc, char *argv[])
  13. {
  14.     struct timeval tv;
  15.     gettimeofday(&tv, NULL);
  16.     int start = tv.tv_usec;
  17.     struct stat st;
  18.     stat(argv[1], &st);
  19.     int size = st.st_size;
  20.     printf("File size: %d\n", size);
  21.     int half = round(size/2);
  22.     int half2 = size - half;
  23.  
  24.     int f = open(argv[1], O_RDONLY);
  25.     int f2 = open(argv[2], O_RDWR | O_CREAT, 0664);
  26.     void *src, *dst;
  27.     lseek(f2, size-1, SEEK_SET);
  28.     write(f2, "", 1);
  29.  
  30.     src = mmap(NULL, size, PROT_READ, MAP_SHARED, f, 0);
  31.     dst = mmap(NULL, size, PROT_WRITE, MAP_SHARED, f2, 0);
  32.     memcpy(dst, (void*)(src + half), half);
  33.     memcpy((void*)(dst + half), src, half2);
  34.  
  35.     gettimeofday(&tv, NULL);
  36.     int end = tv.tv_usec;
  37.     double time = end - start;
  38.     printf("Done in %f seconds\n", time/1000000);
  39.     return 0;
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement