10#include "ll/api/base/CompilerPredefine.h"
11#include "ll/api/base/Macro.h"
12#include "ll/api/base/StdInt.h"
13#include "ll/api/data/TmWithMs.h"
14#include "ll/api/data/Version.h"
16namespace ll::inline utils::sys_utils {
20[[nodiscard]]
inline HandleT getCurrentModuleHandle() {
return internal::getCurrentModuleHandle(); }
22LLNDAPI HandleT getModuleHandle(
void* addr);
24LLNDAPI std::optional<std::filesystem::path> getModulePath(HandleT handle, HandleT process =
nullptr);
26LLNDAPI std::string getModuleFileName(HandleT handle, HandleT process =
nullptr);
28[[nodiscard]]
inline std::string getCallerModuleFileName(
void* addr = LL_RETURN_ADDRESS) {
29 return getModuleFileName(getModuleHandle(addr));
31LLNDAPI std::span<std::byte> getImageRange(std::string_view name =
"");
33LLNDAPI std::string getSystemLocaleCode();
35LLNDAPI std::string
const& getSystemName();
37LLNDAPI data::TmWithMs getLocalTime();
39LLNDAPI std::string getEnvironmentVariable(std::string_view name);
41LLAPI
bool setEnvironmentVariable(std::string_view name, std::string_view value);
43LLAPI
bool addOrSetEnvironmentVariable(std::string_view name, std::string_view value);
45LLNDAPI
bool isStdoutSupportAnsi();
49LLNDAPI data::Version getSystemVersion();
52 HandleT lib =
nullptr;
56 [[nodiscard]]
DynamicLibrary(std::filesystem::path
const& path) { load(path); }
66 LLAPI std::optional<std::system_error> load(std::filesystem::path
const& path)
noexcept;
67 LLAPI std::optional<std::system_error> free()
noexcept;
69 LLNDAPI
void* getAddress(
char const* name)
noexcept;
72 T getAddress(
char const* name)
noexcept {
73 return reinterpret_cast<T
>(getAddress(name));
76 [[nodiscard]]
constexpr HandleT handle()
const noexcept {
return lib; }
79template <std::invocable<
wchar_t*,
size_t,
size_t&> Fn>
80[[nodiscard]]
inline std::optional<std::wstring> adaptFixedSizeToAllocatedResult(Fn&& callback)
noexcept {
81 constexpr size_t arraySize = 256;
83 wchar_t value[arraySize]{};
84 size_t valueLengthNeededWithNull{};
86 std::optional<std::wstring> result{std::in_place};
88 if (!std::invoke(std::forward<Fn>(callback), value, arraySize, valueLengthNeededWithNull)) {
92 if (valueLengthNeededWithNull <= arraySize) {
93 return std::optional<std::wstring>{std::in_place, value, valueLengthNeededWithNull - 1};
96 result->resize(valueLengthNeededWithNull - 1);
97 if (!std::invoke(std::forward<Fn>(callback), result->data(), result->size() + 1, valueLengthNeededWithNull)) {
101 }
while (valueLengthNeededWithNull > result->size() + 1);
102 if (valueLengthNeededWithNull <= result->size()) {
103 result->resize(valueLengthNeededWithNull - 1);
Definition SystemUtils.h:51