13 #ifndef __STOUT_INTERNAL_WINDOWS_INHERIT_HPP__ 14 #define __STOUT_INTERNAL_WINDOWS_INHERIT_HPP__ 23 #include <processthreadsapi.h> 34 if (handles.empty()) {
39 BOOL result = ::InitializeProcThreadAttributeList(
48 if (result == FALSE) {
49 if (::GetLastError() != ERROR_INSUFFICIENT_BUFFER) {
54 std::shared_ptr<AttributeList> attribute_list(
55 reinterpret_cast<AttributeList*>(std::malloc(size)),
56 [](AttributeList* p) {
60 ::DeleteProcThreadAttributeList(p);
64 if (attribute_list ==
nullptr) {
70 ::InitializeProcThreadAttributeList(attribute_list.get(), 1, 0, &
size);
72 if (result == FALSE) {
76 result = ::UpdateProcThreadAttribute(
79 PROC_THREAD_ATTRIBUTE_HANDLE_LIST,
81 const_cast<PVOID*
>(handles.data()),
82 handles.size() *
sizeof(
HANDLE),
86 if (result == FALSE) {
90 return attribute_list;
100 const BOOL result = ::SetHandleInformation(
101 fd, HANDLE_FLAG_INHERIT, inherit ? HANDLE_FLAG_INHERIT : 0);
103 if (result == FALSE) {
113 #endif // __STOUT_INTERNAL_WINDOWS_INHERIT_HPP__ Result< std::shared_ptr< AttributeList > > create_attributes_list_for_handles(const std::vector< HANDLE > &handles)
Definition: inherit.hpp:32
Definition: nothing.hpp:16
Try< Bytes > size(const std::string &path, const FollowSymlink follow=FollowSymlink::FOLLOW_SYMLINK)
Definition: stat.hpp:130
Definition: error.hpp:108
Try< Nothing > set_inherit(const int_fd &fd, const bool inherit)
Definition: inherit.hpp:98
constexpr Handle HANDLE
Definition: ingress.hpp:37
Definition: attributes.hpp:24
_PROC_THREAD_ATTRIBUTE_LIST AttributeList
Definition: inherit.hpp:30
int int_fd
Definition: int_fd.hpp:35