remove_file.cpp 839 B

12345678910111213141516171819202122232425262728293031323334
  1. //
  2. // $Id$
  3. //
  4. #include<__vic/fs.h>
  5. #include<__vic/throw_errno.h>
  6. #include<__vic/posix/error.h>
  7. #include<unistd.h>
  8. #include<cerrno>
  9. namespace __vic {
  10. //----------------------------------------------------------------------------
  11. void remove_file(const char *path)
  12. {
  13. if(::unlink(path)) throw_errno("unlink");
  14. }
  15. //----------------------------------------------------------------------------
  16. bool remove_file_if_exists(const char *path)
  17. {
  18. if(::unlink(path) == 0) return true;
  19. int err = errno;
  20. if(posix::is_ENOENT(err)) return false;
  21. throw_errno("unlink", err);
  22. }
  23. //----------------------------------------------------------------------------
  24. bool remove_file_nt(const char *path) noexcept
  25. {
  26. return ::unlink(path) == 0;
  27. }
  28. //----------------------------------------------------------------------------
  29. } // namespace