From a0626f802a567b98af3994d85cc65d196d0f7209 Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Mon, 27 May 2024 12:17:38 +0200 Subject: [PATCH] system: fix to compile with Xcode Signed-off-by: Simon Rozman --- include/stdex/system.hpp | 86 ++++++++++++++++++++-------------------- 1 file changed, 43 insertions(+), 43 deletions(-) diff --git a/include/stdex/system.hpp b/include/stdex/system.hpp index 59a463377..4f4af6ae8 100644 --- a/include/stdex/system.hpp +++ b/include/stdex/system.hpp @@ -92,6 +92,49 @@ namespace stdex /// using sregex = std::basic_regex; + /// + /// System object operations + /// + struct sys_object_traits + { + static inline const sys_handle invalid_handle = stdex::invalid_handle; + + /// + /// Closes object + /// + static void close(_In_ sys_handle h) + { +#if defined(_WIN32) + if (CloseHandle(h) || GetLastError() == ERROR_INVALID_HANDLE) + return; + throw std::system_error(GetLastError(), std::system_category(), "CloseHandle failed"); +#else + if (::close(h) >= 0 || errno == EBADF) + return; + throw std::system_error(errno, std::system_category(), "close failed"); +#endif + } + + /// + /// Duplicates given object + /// + static sys_handle duplicate(_In_ sys_handle h, _In_ bool inherit = false) + { + sys_handle h_new; +#if defined(_WIN32) + HANDLE process = GetCurrentProcess(); + if (DuplicateHandle(process, h, process, &h_new, 0, inherit, DUPLICATE_SAME_ACCESS)) + return h_new; + throw std::system_error(GetLastError(), std::system_category(), "DuplicateHandle failed"); +#else + _Unreferenced_(inherit); + if ((h_new = dup(h)) >= 0) + return h_new; + throw std::system_error(errno, std::system_category(), "dup failed"); +#endif + } + }; + /// /// Operating system object base class /// @@ -160,49 +203,6 @@ namespace stdex T m_h; }; - /// - /// System object operations - /// - struct sys_object_traits - { - static inline const sys_handle invalid_handle = stdex::invalid_handle; - - /// - /// Closes object - /// - static void close(_In_ sys_handle h) - { -#if defined(_WIN32) - if (CloseHandle(h) || GetLastError() == ERROR_INVALID_HANDLE) - return; - throw std::system_error(GetLastError(), std::system_category(), "CloseHandle failed"); -#else - if (::close(h) >= 0 || errno == EBADF) - return; - throw std::system_error(errno, std::system_category(), "close failed"); -#endif - } - - /// - /// Duplicates given object - /// - static sys_handle duplicate(_In_ sys_handle h, _In_ bool inherit = false) - { - sys_handle h_new; -#if defined(_WIN32) - HANDLE process = GetCurrentProcess(); - if (DuplicateHandle(process, h, process, &h_new, 0, inherit, DUPLICATE_SAME_ACCESS)) - return h_new; - throw std::system_error(GetLastError(), std::system_category(), "DuplicateHandle failed"); -#else - _Unreferenced_(inherit); - if ((h_new = dup(h)) >= 0) - return h_new; - throw std::system_error(errno, std::system_category(), "dup failed"); -#endif - } - }; - /// /// Operating system object (file, pipe, anything with an OS handle etc.) ///