From ee8f54ee5f123f8227700d44ac121bd4ba18c0be Mon Sep 17 00:00:00 2001 From: Simon Rozman Date: Wed, 8 Nov 2023 13:48:41 +0100 Subject: [PATCH] Fix to compile for Linux Signed-off-by: Simon Rozman --- include/stdex/compat.hpp | 12 ++++++++++++ include/stdex/interval.hpp | 2 +- include/stdex/parser.hpp | 9 +++------ include/stdex/progress.hpp | 2 +- include/stdex/sgml.hpp | 1 + include/stdex/stream.hpp | 7 ++++--- include/stdex/sys_info.hpp | 18 +++++++++++------- include/stdex/system.hpp | 2 ++ include/stdex/unicode.hpp | 12 +++++++++++- include/stdex/vector_queue.hpp | 2 ++ 10 files changed, 48 insertions(+), 19 deletions(-) diff --git a/include/stdex/compat.hpp b/include/stdex/compat.hpp index 27f81a0ef..919f94150 100644 --- a/include/stdex/compat.hpp +++ b/include/stdex/compat.hpp @@ -61,6 +61,9 @@ #ifndef _In_reads_bytes_opt_ #define _In_reads_bytes_opt_(p) #endif +#ifndef _Printf_format_string_ +#define _Printf_format_string_ +#endif #ifndef _Printf_format_string_params_ #define _Printf_format_string_params_(n) #endif @@ -74,6 +77,9 @@ #ifndef _Inout_z_ #define _Inout_z_ #endif +#ifndef _Inout_z_count_ +#define _Inout_z_count_(p) +#endif #ifndef _Inout_cap_ #define _Inout_cap_(p) #endif @@ -208,3 +214,9 @@ size_t _countof(T (&arr)[N]) #define ftruncate64 ftruncate #endif +#ifndef _WIN32 +typedef int SOCKET; +#define INVALID_SOCKET ((SOCKET)-1) +#define SOCKET_ERROR -1 +#define closesocket close +#endif diff --git a/include/stdex/interval.hpp b/include/stdex/interval.hpp index 5b327886e..1100b6b62 100644 --- a/include/stdex/interval.hpp +++ b/include/stdex/interval.hpp @@ -87,7 +87,7 @@ namespace stdex /// inline interval operator+(_In_ const interval& other) const { - return interval(start + other.start, end + other.end);i. + return interval(start + other.start, end + other.end); } /// diff --git a/include/stdex/parser.hpp b/include/stdex/parser.hpp index 9c2cb6ffe..94fd3fb57 100644 --- a/include/stdex/parser.hpp +++ b/include/stdex/parser.hpp @@ -19,11 +19,8 @@ #include #endif #include -#elif defined(__APPLE__) -#include #else -#include -#include +#include #endif #include #include @@ -55,7 +52,7 @@ enum class T : type #elif defined(__APPLE__) #define s6_words __u6_addr.__u6_addr16 #else -#error Unsupported platform +#define s6_words s6_addr16 #endif namespace stdex @@ -173,7 +170,7 @@ namespace stdex /// \endcond public: - interval interval; ///< Region of the last match + stdex::interval interval; ///< Region of the last match protected: std::locale m_locale; diff --git a/include/stdex/progress.hpp b/include/stdex/progress.hpp index 436cff7c9..24b9bea97 100644 --- a/include/stdex/progress.hpp +++ b/include/stdex/progress.hpp @@ -130,7 +130,7 @@ namespace stdex protected: std::chrono::nanoseconds m_timeout; - std::chrono::steady_clock::time_point m_last; + std::chrono::system_clock::time_point m_last; T m_start, m_end, m_value; }; diff --git a/include/stdex/sgml.hpp b/include/stdex/sgml.hpp index 65313e0bf..2ca8fcbf5 100644 --- a/include/stdex/sgml.hpp +++ b/include/stdex/sgml.hpp @@ -9,6 +9,7 @@ #include "mapping.hpp" #include "sgml_unicode.hpp" #include "string.hpp" +#include #include #include diff --git a/include/stdex/stream.hpp b/include/stdex/stream.hpp index 7ba8b1d04..a55eaf8b7 100644 --- a/include/stdex/stream.hpp +++ b/include/stdex/stream.hpp @@ -22,6 +22,7 @@ #else #include #include +#include #include #endif #include @@ -2364,7 +2365,7 @@ namespace stdex { if (this != std::addressof(other)) { if (m_h != INVALID_SOCKET) - closesocket(m_h); + ::closesocket(m_h); m_h = other.m_h; other.m_h = INVALID_SOCKET; } @@ -2388,7 +2389,7 @@ namespace stdex virtual ~socket() { if (m_h != INVALID_SOCKET) - closesocket(m_h); + ::closesocket(m_h); } /// @@ -2448,7 +2449,7 @@ namespace stdex virtual void close() { if (m_h != INVALID_SOCKET) { - closesocket(m_h); + ::closesocket(m_h); m_h = INVALID_SOCKET; } m_state = state_t::ok; diff --git a/include/stdex/sys_info.hpp b/include/stdex/sys_info.hpp index 705fb9e39..3ae9736b2 100644 --- a/include/stdex/sys_info.hpp +++ b/include/stdex/sys_info.hpp @@ -11,6 +11,8 @@ #include "windows.h" #include #include +#else +#include #endif #include @@ -23,13 +25,6 @@ namespace stdex typedef uint16_t platform_id; #else typedef const char* platform_id; - - inline bool operator ==(_In_ const platform_id a, _In_ const platform_id b) { return a == b; } - inline bool operator !=(_In_ const platform_id a, _In_ const platform_id b) { return a != b; } - inline bool operator <(_In_ const platform_id a, _In_ const platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) < 0; } - inline bool operator <=(_In_ const platform_id a, _In_ const platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) <= 0; } - inline bool operator >(_In_ const platform_id a, _In_ const platform_id b) { return a != IMAGE_FILE_MACHINE_UNKNOWN && b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) > 0; } - inline bool operator >=(_In_ const platform_id a, _In_ const platform_id b) { return b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) >= 0; } #endif } @@ -39,6 +34,13 @@ constexpr stdex::platform_id IMAGE_FILE_MACHINE_I386 = "i386"; constexpr stdex::platform_id IMAGE_FILE_MACHINE_AMD64 = "x86_64"; constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARMNT = "arm"; constexpr stdex::platform_id IMAGE_FILE_MACHINE_ARM64 = "aarch64"; + +inline bool operator ==(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == b; } +inline bool operator !=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a != b; } +inline bool operator <(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) < 0; } +inline bool operator <=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) <= 0; } +inline bool operator >(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return a != IMAGE_FILE_MACHINE_UNKNOWN && b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) > 0; } +inline bool operator >=(_In_ const stdex::platform_id a, _In_ const stdex::platform_id b) { return b == IMAGE_FILE_MACHINE_UNKNOWN || a != IMAGE_FILE_MACHINE_UNKNOWN && b != IMAGE_FILE_MACHINE_UNKNOWN && strcmp(a, b) >= 0; } #endif namespace stdex @@ -98,7 +100,9 @@ namespace stdex sys_info_t() : os_platform(IMAGE_FILE_MACHINE_UNKNOWN), +#ifdef _WIN32 wow64(false), +#endif interactive_process(true), admin(false), elevated(false) diff --git a/include/stdex/system.hpp b/include/stdex/system.hpp index 301e57350..368c3350f 100644 --- a/include/stdex/system.hpp +++ b/include/stdex/system.hpp @@ -11,7 +11,9 @@ #include #include #else +#ifndef _LARGEFILE64_SOURCE #define _LARGEFILE64_SOURCE // TODO: Make this -D compile-time project setting +#endif #include #include #include diff --git a/include/stdex/unicode.hpp b/include/stdex/unicode.hpp index 89f25371d..dd2494c74 100644 --- a/include/stdex/unicode.hpp +++ b/include/stdex/unicode.hpp @@ -8,6 +8,7 @@ #include "compat.hpp" #include "endian.hpp" #include "math.hpp" +#include "string.hpp" #include #ifndef _WIN32 #include @@ -17,6 +18,11 @@ #include #include +#ifndef _WIN32 +#pragma GCC diagnostic push +#pragma GCC diagnostic ignored "-Wdeprecated-declarations" +#endif + namespace stdex { enum class charset_id : uint16_t { @@ -103,7 +109,7 @@ namespace stdex _In_reads_or_z_opt_(count_src) const T_from* src, _In_ size_t count_src) { _Assume_(src || !count_src); - count_src = stdex::strnlen(src, count_src); + count_src = stdex::strnlen(src, count_src); if (!count_src) _Unlikely_ return; @@ -767,3 +773,7 @@ namespace stdex return wstr2str(src.c_str(), src.size(), charset); } } + +#ifndef _WIN32 +#pragma GCC diagnostic pop +#endif diff --git a/include/stdex/vector_queue.hpp b/include/stdex/vector_queue.hpp index 0926cb286..6b8a62a07 100644 --- a/include/stdex/vector_queue.hpp +++ b/include/stdex/vector_queue.hpp @@ -6,6 +6,8 @@ #pragma once #include "compat.hpp" +#include +#include namespace stdex {