diff options
| author | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-04 15:13:22 +0100 |
|---|---|---|
| committer | Amlal El Mahrouss <amlal@nekernel.org> | 2025-12-04 15:17:53 +0100 |
| commit | cd3092186eb698a9ed175dacb6884f0404e7c062 (patch) | |
| tree | cdc3e0e013f5efb0dfc8c450b706951d3a8e3597 /src/CompilerKit/Detail/Config.h | |
| parent | 14ed88e58517890f5cce1bb9ab5cfb9e94bcfbf6 (diff) | |
chore! Breaking API changes for CompilerKit and DebuggerKit.
Signed-off-by: Amlal El Mahrouss <amlal@nekernel.org>
Diffstat (limited to 'src/CompilerKit/Detail/Config.h')
| -rw-r--r-- | src/CompilerKit/Detail/Config.h | 64 |
1 files changed, 64 insertions, 0 deletions
diff --git a/src/CompilerKit/Detail/Config.h b/src/CompilerKit/Detail/Config.h new file mode 100644 index 0000000..6137e2a --- /dev/null +++ b/src/CompilerKit/Detail/Config.h @@ -0,0 +1,64 @@ +/* ======================================== + + Copyright (C) 2024-2025 Amlal El Mahrouss, Licensed under the Apache 2.0 license + +======================================== */ + +#pragma once + +/// =========================================================== /// +/// @file detail/Config.h +/// @author Amlal El Mahrouss +/// @brief Basic defines and types for CompilerKit. +/// =========================================================== /// + +#include <CompilerKit/Detail/PreConfig.h> + +namespace CompilerKit { +inline constexpr int kBaseYear = 1900; +using STLString = std::string; + +inline STLString current_date() noexcept { + auto time_data = time(nullptr); + auto time_struct = gmtime(&time_data); + + STLString fmt = std::to_string(kBaseYear + time_struct->tm_year); + + fmt += "-"; + fmt += std::to_string(time_struct->tm_mon + 1); + fmt += "-"; + fmt += std::to_string(time_struct->tm_mday); + + return fmt; +} + +inline bool to_str(Char* str, Int32 limit, Int32 base) noexcept { + if (limit == 0) return false; + + Int32 copy_limit = limit; + Int32 cnt = 0; + Int32 ret = base; + + while (limit != 1) { + ret = ret % 10; + str[cnt] = ret; + + ++cnt; + --limit; + --ret; + } + + str[copy_limit] = '\0'; + return true; +} + +inline bool install_signal(Int32 signal, void (*handler)(int)) noexcept { + if (handler == nullptr) return false; + + if (::signal(signal, handler) == SIG_ERR) { + return false; + } + + return true; +} +} // namespace CompilerKit |
