/
Mr.Stalin
/
FOnline-Engine
Обзор
Документация
Войти
/
Mr.Stalin
/
FOnline-Engine
Код
Пакеты
0
Релизы
0
Аналитика
Безопасность
master
Source/Essentials/BasicCore.cpp
184 строки
5 KB
cvet
Non const locals (#190)
24 июл 2026, 10:46
Не верифицирован
24 июл 2026, 10:46
4883d25
Код
Авторство
О чём код?
// __________ ___ ______ _ // / ____/ __ \____ / (_)___ ___ / ____/___ ____ _(_)___ ___ // / /_ / / / / __ \/ / / __ \/ _ \ / __/ / __ \/ __ `/ / __ \/ _ ` // / __/ / /_/ / / / / / / / / / __/ / /___/ / / / /_/ / / / / / __/ // /_/ \____/_/ /_/_/_/_/ /_/\___/ /_____/_/ /_/\__, /_/_/ /_/\___/ // /____/ // FOnline Engine // https://fonline.ru // https://github.com/cvet/fonline // // MIT License // // Copyright (c) 2006 - 2026, Anton Tsvetinskiy aka cvet <cvet@tut.by> // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in all // copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE // SOFTWARE. // #include "BasicCore.h" #if FO_WINDOWS #define WIN32_LEAN_AND_MEAN #include <Windows.h> #endif #include "WinApiUndef.inc" #if FO_MAC #include <sys/sysctl.h> #include <unistd.h> #endif FO_BEGIN_NAMESPACE static bool RunInDebugger = false; static std::once_flag RunInDebuggerOnce; void ExitApp(bool success) noexcept { int32_t code = success ? EXIT_SUCCESS : EXIT_FAILURE; #if !FO_WEB && !FO_MAC && !FO_IOS && !FO_ANDROID std::quick_exit(code); #else std::exit(code); #endif while (true) { std::this_thread::sleep_for(std::chrono::seconds(1)); } } extern auto IsRunInDebugger() noexcept -> bool { #if FO_WINDOWS std::call_once(RunInDebuggerOnce, [] { RunInDebugger = ::IsDebuggerPresent() != FALSE; }); #elif FO_LINUX std::call_once(RunInDebuggerOnce, [] { std::ifstream status("/proc/self/status"); if (status.is_open()) { std::string line; while (std::getline(status, line)) { if (line.starts_with("TracerPid:")) { std::istringstream iss(line.substr("TracerPid:"_len)); std::string value; iss >> value; if (!value.empty() && std::all_of(value.begin(), value.end(), ::isdigit)) { RunInDebugger = value != "0"; } break; } } } }); #elif FO_MAC std::call_once(RunInDebuggerOnce, [] { int32_t mib[4] = {CTL_KERN, KERN_PROC, KERN_PROC_PID, getpid()}; struct kinfo_proc info = {}; size_t size = sizeof(info); if (::sysctl(mib, sizeof(mib) / sizeof(*mib), &info, &size, nullptr, 0) == 0) { RunInDebugger = (info.kp_proc.p_flag & P_TRACED) != 0; } }); #else ignore_unused(RunInDebuggerOnce); #endif return RunInDebugger; } extern auto BreakIntoDebugger() noexcept -> bool { if (IsRunInDebugger()) { #if FO_WINDOWS ::DebugBreak(); return true; #elif FO_LINUX #ifdef __has_builtin #if __has_builtin(__builtin_debugtrap) __builtin_debugtrap(); #else std::raise(SIGTRAP); #endif #else std::raise(SIGTRAP); #endif return true; #elif FO_MAC __builtin_debugtrap(); return true; #endif } return false; } extern auto ItoA(int64_t num, char buf[64], int32_t base) noexcept -> const char* { int32_t i = 0; bool is_negative = false; uint64_t unsigned_num = 0; if (num == 0) { buf[i++] = '0'; buf[i] = '\0'; return buf; } if (num < 0 && base == 10) { is_negative = true; unsigned_num = static_cast<uint64_t>(-(num + 1)) + 1; while (unsigned_num != 0) { uint64_t rem = unsigned_num % static_cast<uint64_t>(base); buf[i++] = static_cast<char>(rem > 9 ? rem - 10 + 'a' : rem + '0'); unsigned_num /= static_cast<uint64_t>(base); } } else { while (num != 0) { int64_t rem = num % base; buf[i++] = static_cast<char>(rem > 9 ? rem - 10 + 'a' : rem + '0'); num = num / base; } } if (is_negative) { buf[i++] = '-'; } buf[i] = '\0'; int32_t start = 0; int32_t end = i - 1; while (start < end) { char ch = buf[start]; buf[start] = buf[end]; buf[end] = ch; end--; start++; } return buf; } FO_END_NAMESPACE