ResourceTraitsUnix.hpp 884 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. #pragma once
  2. #include <errno.h>
  3. #include <unistd.h>
  4. #include <sys/mman.h>
  5. #include "ExceptionSystem.hpp"
  6. namespace ARL::ResourceTraits {
  7. struct FileDescriptor {
  8. using HandleType = int;
  9. static inline const HandleType InvalidValue = -1;
  10. [[nodiscard]]
  11. static bool IsValid(const HandleType& Handle) noexcept {
  12. return Handle != InvalidValue;
  13. }
  14. static void Release(const HandleType& Handle) {
  15. if (close(Handle) != 0) {
  16. throw ARL::SystemError(__FILE__, __LINE__, errno, "close failed.");
  17. }
  18. }
  19. };
  20. struct MapView {
  21. using HandleType = void*;
  22. static inline const HandleType InvalidValue = MAP_FAILED;
  23. [[nodiscard]]
  24. static bool IsValid(const HandleType& Handle) noexcept {
  25. return Handle != InvalidValue;
  26. }
  27. };
  28. }