move_file.cpp 680 B

12345678910111213141516171819202122232425262728
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/fs.h>
  5. #include<__vic/throw_errno.h>
  6. #include<unistd.h>
  7. #include<cerrno>
  8. namespace __vic {
  9. //----------------------------------------------------------------------------
  10. void move_file(const char *src_path, const char *dest_path)
  11. {
  12. // std::rename overwrites existing entry so we don't use it
  13. if(::link(src_path, dest_path))
  14. {
  15. int err = errno;
  16. if(err != EXDEV) throw_errno("link", err);
  17. // src and dest are not on the same filesystem
  18. copy_file(src_path, dest_path);
  19. }
  20. remove_file_if_exists(src_path);
  21. }
  22. //----------------------------------------------------------------------------
  23. } // namespace