21
common/resource_traits/unix_os/file_descriptor.hpp
Normal file
21
common/resource_traits/unix_os/file_descriptor.hpp
Normal file
@@ -0,0 +1,21 @@
|
||||
#pragma once
|
||||
#include <unistd.h>
|
||||
|
||||
namespace nkg::resource_traits::unix_os {
|
||||
|
||||
struct file_descriptor {
|
||||
using handle_t = int;
|
||||
|
||||
static constexpr handle_t invalid_value = -1;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
|
||||
static void release(const handle_t& handle) {
|
||||
close(handle);
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
19
common/resource_traits/unix_os/map_view.hpp
Normal file
19
common/resource_traits/unix_os/map_view.hpp
Normal file
@@ -0,0 +1,19 @@
|
||||
#pragma once
|
||||
#include <errno.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/mman.h>
|
||||
|
||||
namespace nkg::resource_traits::unix_os {
|
||||
|
||||
struct map_view {
|
||||
using handle_t = void*;
|
||||
|
||||
static inline const handle_t invalid_value = MAP_FAILED;
|
||||
|
||||
[[nodiscard]]
|
||||
static bool is_valid(const handle_t& handle) noexcept {
|
||||
return handle != invalid_value;
|
||||
}
|
||||
};
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user