You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

72 lines
1.8 KiB

  1. /*
  2. Copyright (c) 2019, Antonio SJ Musumeci <trapexit@spawn.link>
  3. Permission to use, copy, modify, and/or distribute this software for any
  4. purpose with or without fee is hereby granted, provided that the above
  5. copyright notice and this permission notice appear in all copies.
  6. THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
  7. WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
  8. MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
  9. ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
  10. WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
  11. ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
  12. OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  13. */
  14. #include "errno.hpp"
  15. #include "fs_copy_file_range.hpp"
  16. #include "fs_fstat.hpp"
  17. #include <cstdint>
  18. namespace l
  19. {
  20. int64_t
  21. copydata_copy_file_range(const int src_fd_,
  22. const int dst_fd_,
  23. uint64_t size_)
  24. {
  25. int64_t rv;
  26. uint64_t nleft;
  27. int64_t src_off;
  28. int64_t dst_off;
  29. src_off = 0;
  30. dst_off = 0;
  31. nleft = size_;
  32. do
  33. {
  34. rv = fs::copy_file_range(src_fd_,&src_off,dst_fd_,&dst_off,nleft,0);
  35. if((rv == -1) && (errno == EINTR))
  36. continue;
  37. if(rv == -1)
  38. return -1;
  39. nleft -= rv;
  40. }
  41. while(nleft > 0);
  42. return size_;
  43. }
  44. }
  45. namespace fs
  46. {
  47. int64_t
  48. copydata_copy_file_range(const int src_fd_,
  49. const int dst_fd_)
  50. {
  51. int rv;
  52. struct stat st;
  53. rv = fs::fstat(src_fd_,&st);
  54. if(rv == -1)
  55. return -1;
  56. return l::copydata_copy_file_range(src_fd_,
  57. dst_fd_,
  58. st.st_size);
  59. }
  60. }