11#if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
24 #define SWPRINTF_CHARSTRING L"%S"
26 #define SWPRINTF_CHARSTRING L"%s"
32 #define sleep_ms(x) Sleep(x)
33 #define sleep_us(x) Sleep((x)/1000)
35 #define SLEEP_ACCURACY_US 2000
37 #define setenv(n,v,o) _putenv_s(n,v)
38 #define unsetenv(n) _putenv_s(n,"")
43 #define SLEEP_ACCURACY_US 200
45 #define sleep_ms(x) usleep((x)*1000)
46 #define sleep_us(x) usleep(x)
50 #define strtok_r(x, y, z) strtok_s(x, y, z)
51 #define strtof(x, y) (float)strtod(x, y)
52 #define strtoll(x, y, z) _strtoi64(x, y, z)
53 #define strtoull(x, y, z) _strtoui64(x, y, z)
54 #define strcasecmp(x, y) stricmp(x, y)
55 #define strncasecmp(x, y, n) strnicmp(x, y, n)
59 #define strlcpy(d, s, n) mystrlcpy(d, s, n)
65 #if defined(__MACH__) && defined(__APPLE__)
66 #include <TargetConditionals.h>
139extern double perf_freq;
141inline u64 os_get_time(
double mult)
144 QueryPerformanceCounter(&t);
145 return static_cast<double>(t.QuadPart) / (perf_freq / mult);
149inline u64
getTimeS() {
return os_get_time(1); }
150inline u64
getTimeMs() {
return os_get_time(1000); }
151inline u64
getTimeUs() {
return os_get_time(1000*1000); }
152inline u64
getTimeNs() {
return os_get_time(1000*1000*1000); }
158#if defined(CLOCK_MONOTONIC_RAW)
159 clock_gettime(CLOCK_MONOTONIC_RAW, ts);
160#elif defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
161 clock_gettime(CLOCK_MONOTONIC, ts);
163# if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK == 0
165 if (clock_gettime(CLOCK_MONOTONIC, ts) == 0)
169 gettimeofday(&tv, NULL);
170 TIMEVAL_TO_TIMESPEC(&tv, ts);
185 return ((u64) ts.tv_sec) * 1000LL + ((u64) ts.tv_nsec) / 1000000LL;
192 return ((u64) ts.tv_sec) * 1000000LL + ((u64) ts.tv_nsec) / 1000LL;
199 return ((u64) ts.tv_sec) * 1000000000LL + ((u64) ts.tv_nsec);
212 FATAL_ERROR(
"Called getTime with invalid time precision");
223 if (new_time_ms >= old_time_ms) {
224 return (new_time_ms - old_time_ms);
227 return (old_time_ms - new_time_ms);
250#elif defined(__linux__)
252#elif defined(_WIN32) || defined(_WIN64)
254#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
255 defined(__NetBSD__) || defined(__OpenBSD__)
257#elif defined(__APPLE__) && defined(__MACH__)
260 #elif TARGET_OS_IPHONE
269#elif defined(__sun) || defined(sun)
275#elif defined(__HAIKU__)
277#elif defined(__CYGWIN__)
279#elif defined(__unix__) || defined(__unix)
280 #if defined(_POSIX_VERSION)
320[[nodiscard]] std::string QuoteArgv(
const std::string &arg);
323[[nodiscard]] std::string ConvertError(DWORD error_code);
327int mt_snprintf(
char *buf,
const size_t buf_size,
const char *fmt, ...);
337bool open_url(
const std::string &url);
#define FATAL_ERROR(msg)
Definition debug.h:32
Definition porting.cpp:85
u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
Delta calculation function arguments.
Definition porting.h:221
std::string path_locale
Definition porting.cpp:164
bool secure_rand_fill_buf(void *buf, size_t len)
Definition porting.cpp:761
u32 getMemorySizeMB()
Definition porting.cpp:274
std::string path_share
Definition porting.cpp:162
volatile std::sig_atomic_t * signal_handler_killstatus()
Definition porting.cpp:93
int mt_snprintf(char *buf, const size_t buf_size, const char *fmt,...)
Definition porting.cpp:857
void os_get_clock(struct timespec *ts)
Definition porting.h:156
void signal_handler_init(void)
Definition porting.cpp:118
void osSpecificInit()
Definition porting.cpp:782
static void TrackFreedMemory(size_t amount)
Definition porting.h:314
bool open_directory(const std::string &path)
Opens a directory in the default file manager.
Definition porting.cpp:916
u64 getTimeS()
Definition porting.h:174
std::string path_cache
Definition porting.cpp:165
std::string path_user
Definition porting.cpp:163
u64 getTime(TimePrecision prec)
Definition porting.h:204
u64 getTimeMs()
Definition porting.h:181
bool open_url(const std::string &url)
Opens URL in default web browser.
Definition porting.cpp:906
u64 getTimeNs()
Definition porting.h:195
const char * getPlatformName()
Definition porting.h:245
bool getCurrentExecPath(char *buf, size_t len)
Definition porting.cpp:427
std::string getDataPath(const char *subpath)
Definition porting.cpp:168
void initializePaths()
Definition porting.cpp:631
void attachOrCreateConsole()
Definition porting.cpp:795
void preciseSleepUs(u64 sleep_time)
Definition porting.h:230
static void TriggerMemoryTrim()
Definition porting.h:315
u64 getTimeUs()
Definition porting.h:188
const std::string & get_sysinfo()
Definition porting.cpp:268
#define sleep_us(x)
Definition porting.h:46
#define SLEEP_ACCURACY_US
Definition porting.h:43