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
41#undef timeval
42
43using namespace std::literals;
44
51{
61 inline void programSafeExit(const int status)
62 {
63#ifdef STP_BINDINGS
64 return;
65#endif
66
67#ifdef MACOSX
68 exit(status); // NOLINT(concurrency-mt-unsafe)
69#else
70 std::quick_exit(status);
71#endif
72 }
73
74 inline std::tm localtime_xp(std::time_t* timer)
75 {
76 std::tm bt{};
77#if defined(__unix__)
78 localtime_r(timer, &bt);
79#elif defined(WINDOWS)
80 localtime_s(&bt, timer);
81#else
82 static std::mutex mtx;
83 std::lock_guard<std::mutex> lock(mtx);
84 bt = *std::localtime(timer); // NOLINT(concurrency-mt-unsafe)
85#endif
86 return bt;
87 }
88
89 std::filesystem::path getHomeDirectory();
90
91 std::filesystem::path getConfDirectory();
92} // 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:61
std::tm localtime_xp(std::time_t *timer)
Definition platform.hpp:74
std::filesystem::path getConfDirectory()
Definition platform.cpp:87
std::filesystem::path getHomeDirectory()
Definition platform.cpp:43
Untitled