file_descriptor.hpp 434 B

12345678910111213141516171819202122
  1. #pragma once
  2. #include <unistd.h>
  3. namespace nkg::resource_traits::unix_os {
  4. struct file_descriptor {
  5. using handle_t = int;
  6. static constexpr handle_t invalid_value = -1;
  7. [[nodiscard]]
  8. static bool is_valid(const handle_t& handle) noexcept {
  9. return handle != invalid_value;
  10. }
  11. static void release(const handle_t& handle) {
  12. close(handle);
  13. }
  14. };
  15. }