Skip to content
This repository has been archived by the owner on Nov 29, 2024. It is now read-only.

Commit

Permalink
system: fix to compile with Xcode
Browse files Browse the repository at this point in the history
Signed-off-by: Simon Rozman <[email protected]>
  • Loading branch information
rozmansi committed May 27, 2024
1 parent c1616b0 commit a0626f8
Showing 1 changed file with 43 additions and 43 deletions.
86 changes: 43 additions & 43 deletions include/stdex/system.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,49 @@ namespace stdex
///
using sregex = std::basic_regex<stdex::schar_t>;

///
/// 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
///
Expand Down Expand Up @@ -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.)
///
Expand Down

0 comments on commit a0626f8

Please sign in to comment.