copy_rev.c 656 B

1234567891011121314151617181920212223
  1. #include "common.h"
  2. void copy_data(int fi, int fo, const char* input_path, const char* output_path, size_t size) {
  3. size_t max_step = 16;
  4. if (size > 65536)
  5. max_step = 256;
  6. void* data = alloc_buffer(max_step);
  7. ssize_t offset = size;
  8. ssize_t step;
  9. while (offset > 0) {
  10. if (offset > max_step)
  11. step = rand() % max_step + 1;
  12. else
  13. step = offset;
  14. offset -= step;
  15. seek_fd(input_path, fi, offset, SEEK_SET);
  16. seek_fd(output_path, fo, offset, SEEK_SET);
  17. read_fd(input_path, fi, data, step);
  18. write_fd(output_path, fo, data, step);
  19. }
  20. free(data);
  21. }