Steppable 0.0.1
A CAS project written from scratch in C++
Loading...
Searching...
No Matches
platform.hpp
1/**************************************************************************************************
2 * Copyright (c) 2023-2025 NWSOFT *
3 * *
4 * Permission is hereby granted, free of charge, to any person obtaining a copy *
5 * of this software and associated documentation files (the "Software"), to deal *
6 * in the Software without restriction, including without limitation the rights *
7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell *
8 * copies of the Software, and to permit persons to whom the Software is *
9 * furnished to do so, subject to the following conditions: *
10 * *
11 * The above copyright notice and this permission notice shall be included in all *
12 * copies or substantial portions of the Software. *
13 * *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE *
17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER *
18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, *
19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE *
20 * SOFTWARE. *
21 **************************************************************************************************/
22
33
34#pragma once
35
36#include <cstdlib>
37#include <ctime>
38#include <filesystem>
39#include <mutex>
40
41using namespace std::literals;
42
49{
59 inline void programSafeExit(const int status)
60 {
61#ifdef MACOSX
62 exit(status); // NOLINT(concurrency-mt-unsafe)
63#else
64 std::quick_exit(status);
65#endif
66 }
67
68 inline std::tm localtime_xp(std::time_t* timer)
69 {
70 std::tm bt{};
71#if defined(__unix__)
72 localtime_r(timer, &bt);
73#elif defined(WINDOWS)
74 localtime_s(&bt, timer);
75#else
76 static std::mutex mtx;
77 std::lock_guard<std::mutex> lock(mtx);
78 bt = *std::localtime(timer); // NOLINT(concurrency-mt-unsafe)
79#endif
80 return bt;
81 }
82
83 std::filesystem::path getHomeDirectory();
84
85 std::filesystem::path getConfDirectory();
86} // namespace steppable::__internals::utils
The namespace containing utility functions for the Steppable library.
Definition argParse.cpp:40
void programSafeExit(const int status)
Exit the program safely.
Definition platform.hpp:59
std::tm localtime_xp(std::time_t *timer)
Definition platform.hpp:68
std::filesystem::path getConfDirectory()
Definition platform.cpp:89
std::filesystem::path getHomeDirectory()
Definition platform.cpp:43
Untitled