copy_seq.c 568 B

123456789101112131415161718192021
  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 = 0;
  8. ssize_t step;
  9. while (offset < size) {
  10. if (offset + max_step <= size)
  11. step = rand() % max_step + 1;
  12. else
  13. step = size - offset;
  14. read_fd(input_path, fi, data, step);
  15. write_fd(output_path, fo, data, step);
  16. offset += step;
  17. }
  18. free(data);
  19. }