1
0
mirror of https://github.com/OpenRCT2/OpenRCT2 synced 2026-01-23 06:44:38 +01:00
Files
OpenRCT2/src/openrct2/platform/Platform.Posix.cpp
2018-08-15 00:14:47 +02:00

102 lines
2.5 KiB
C++

/*****************************************************************************
* Copyright (c) 2014-2018 OpenRCT2 developers
*
* For a complete list of all authors, please refer to contributors.md
* Interested in contributing? Visit https://github.com/OpenRCT2/OpenRCT2
*
* OpenRCT2 is licensed under the GNU General Public License version 3.
*****************************************************************************/
#if defined(__unix__) || (defined(__APPLE__) && defined(__MACH__)) || defined(__FreeBSD__)
# include "../core/String.hpp"
# include "Platform2.h"
# include "platform.h"
# include <cstdlib>
# include <cstring>
# include <ctime>
# include <pwd.h>
namespace Platform
{
uint32_t GetTicks()
{
return platform_get_ticks();
}
std::string GetEnvironmentVariable(const std::string& name)
{
return String::ToStd(getenv(name.c_str()));
}
std::string GetEnvironmentPath(const char* name)
{
auto value = getenv(name);
if (value == nullptr)
{
return std::string();
}
else
{
auto colon = std::strchr(value, ':');
if (colon == nullptr)
{
return std::string(value);
}
else
{
return std::string(value, colon);
}
}
}
std::string GetHomePath()
{
std::string path;
auto pw = getpwuid(getuid());
if (pw != nullptr)
{
path = pw->pw_dir;
}
else
{
path = GetEnvironmentVariable("HOME");
}
if (path.empty())
{
path = "/";
}
return path;
}
std::string FormatShortDate(std::time_t timestamp)
{
char date[20];
std::strftime(date, sizeof(date), "%x", std::localtime(&timestamp));
return std::string(date);
}
std::string FormatTime(std::time_t timestamp)
{
char time[20];
std::strftime(time, sizeof(time), "%X", std::localtime(&timestamp));
return std::string(time);
}
bool IsColourTerminalSupported()
{
static bool hasChecked = false;
static bool isSupported = false;
if (!hasChecked)
{
auto term = GetEnvironmentVariable("TERM");
isSupported = term != "cons25" && term != "dumb" && term != "emacs";
hasChecked = true;
}
return isSupported;
}
} // namespace Platform
#endif