add: [system] sys::conf page_size for win

This commit is contained in:
mutouyun 2022-08-14 22:01:49 +08:00
parent c604fadbea
commit db2b2b38ec
3 changed files with 25 additions and 4 deletions

View File

@ -7,6 +7,7 @@
#pragma once
#include <string>
#include <cstdint>
#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;

View File

@ -62,8 +62,8 @@ std::int64_t conf(info r) noexcept {
case info::page_size: {
auto val = ::sysconf(_SC_PAGESIZE);
if (val >= 0) return (std::int64_t)val;
}
break;
}
default:
log.error("invalid info = {}", enum_cast(r));
return -1;

View File

@ -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_