From db2b2b38ecb4912e031d6585df47243fda7e81ab Mon Sep 17 00:00:00 2001 From: mutouyun Date: Sun, 14 Aug 2022 22:01:49 +0800 Subject: [PATCH] add: [system] sys::conf page_size for win --- include/libimp/system.h | 3 ++- src/libimp/platform/posix/system.h | 6 +++--- src/libimp/platform/win/system.h | 20 ++++++++++++++++++++ 3 files changed, 25 insertions(+), 4 deletions(-) diff --git a/include/libimp/system.h b/include/libimp/system.h index ba542d5..ceba407 100644 --- a/include/libimp/system.h +++ b/include/libimp/system.h @@ -7,6 +7,7 @@ #pragma once #include +#include #include "libimp/def.h" #include "libimp/export.h" @@ -27,7 +28,7 @@ LIBIMP_EXPORT void error_code(result_code) noexcept; LIBIMP_EXPORT std::string error_str(result_code) noexcept; /** - * @brief @brief A text description string with an error number attached + * @brief A text description string with an error number attached */ LIBIMP_EXPORT std::string error_msg(result_code) noexcept; diff --git a/src/libimp/platform/posix/system.h b/src/libimp/platform/posix/system.h index 44d917a..a786ab4 100644 --- a/src/libimp/platform/posix/system.h +++ b/src/libimp/platform/posix/system.h @@ -60,10 +60,10 @@ std::int64_t conf(info r) noexcept { LIBIMP_LOG_(); switch (r) { case info::page_size: { - auto val = ::sysconf(_SC_PAGESIZE); - if (val >= 0) return (std::int64_t)val; - } + auto val = ::sysconf(_SC_PAGESIZE); + if (val >= 0) return (std::int64_t)val; break; + } default: log.error("invalid info = {}", enum_cast(r)); return -1; diff --git a/src/libimp/platform/win/system.h b/src/libimp/platform/win/system.h index b50f2bc..d412a65 100644 --- a/src/libimp/platform/win/system.h +++ b/src/libimp/platform/win/system.h @@ -14,6 +14,7 @@ #include "libimp/system.h" #include "libimp/log.h" #include "libimp/codecvt.h" +#include "libimp/enum_cast.h" LIBIMP_NAMESPACE_BEG_ namespace sys { @@ -76,5 +77,24 @@ std::string error_str(result_code code) noexcept { return {}; } +/** + * @brief Retrieves information about the current system + * https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getsysteminfo + * https://docs.microsoft.com/en-us/windows/win32/api/sysinfoapi/nf-sysinfoapi-getnativesysteminfo + */ +std::int64_t conf(info r) noexcept { + LIBIMP_LOG_(); + switch (r) { + case info::page_size: { + ::SYSTEM_INFO info {}; + ::GetNativeSystemInfo(&info); + return (std::int64_t)info.dwPageSize; + } + default: + log.error("invalid info = {}", enum_cast(r)); + return -1; + } +} + } // namespace sys LIBIMP_NAMESPACE_END_