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)
60 #define strtok_r(x, y, z) mystrtok_r(x, y, z)
64 #define strlcpy(d, s, n) mystrlcpy(d, s, n)
70 #if defined(__MACH__) && defined(__APPLE__)
71 #include <TargetConditionals.h>
136extern double perf_freq;
138inline u64 os_get_time(
double mult)
141 QueryPerformanceCounter(&t);
142 return static_cast<double>(t.QuadPart) / (perf_freq / mult);
146inline u64
getTimeS() {
return os_get_time(1); }
147inline u64
getTimeMs() {
return os_get_time(1000); }
148inline u64
getTimeUs() {
return os_get_time(1000*1000); }
149inline u64
getTimeNs() {
return os_get_time(1000*1000*1000); }
155#if defined(CLOCK_MONOTONIC_RAW)
156 clock_gettime(CLOCK_MONOTONIC_RAW, ts);
157#elif defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK > 0
158 clock_gettime(CLOCK_MONOTONIC, ts);
160# if defined(_POSIX_MONOTONIC_CLOCK) && _POSIX_MONOTONIC_CLOCK == 0
162 if (clock_gettime(CLOCK_MONOTONIC, ts) == 0)
166 gettimeofday(&tv, NULL);
167 TIMEVAL_TO_TIMESPEC(&tv, ts);
182 return ((u64) ts.tv_sec) * 1000LL + ((u64) ts.tv_nsec) / 1000000LL;
189 return ((u64) ts.tv_sec) * 1000000LL + ((u64) ts.tv_nsec) / 1000LL;
196 return ((u64) ts.tv_sec) * 1000000000LL + ((u64) ts.tv_nsec);
209 FATAL_ERROR(
"Called getTime with invalid time precision");
220 if (new_time_ms >= old_time_ms) {
221 return (new_time_ms - old_time_ms);
224 return (old_time_ms - new_time_ms);
247#elif defined(__linux__)
249#elif defined(_WIN32) || defined(_WIN64)
251#elif defined(__DragonFly__) || defined(__FreeBSD__) || \
252 defined(__NetBSD__) || defined(__OpenBSD__)
254#elif defined(__APPLE__) && defined(__MACH__)
257 #elif TARGET_OS_IPHONE
266#elif defined(__sun) || defined(sun)
272#elif defined(__HAIKU__)
274#elif defined(__CYGWIN__)
276#elif defined(__unix__) || defined(__unix)
277 #if defined(_POSIX_VERSION)
316std::string QuoteArgv(
const std::string &arg);
319std::string ConvertError(DWORD error_code);
323int mt_snprintf(
char *buf,
const size_t buf_size,
const char *fmt, ...);
333bool open_url(
const std::string &url);
#define FATAL_ERROR(msg)
Definition debug.h:32
Definition porting.cpp:78
u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
Delta calculation function arguments.
Definition porting.h:218
std::string path_locale
Definition porting.cpp:161
bool secure_rand_fill_buf(void *buf, size_t len)
Definition porting.cpp:749
std::string path_share
Definition porting.cpp:159
int mt_snprintf(char *buf, const size_t buf_size, const char *fmt,...)
Definition porting.cpp:845
void os_get_clock(struct timespec *ts)
Definition porting.h:153
void signal_handler_init(void)
Definition porting.cpp:115
void osSpecificInit()
Definition porting.cpp:770
static void TrackFreedMemory(size_t amount)
Definition porting.h:310
bool open_directory(const std::string &path)
Opens a directory in the default file manager.
Definition porting.cpp:904
u64 getTimeS()
Definition porting.h:171
std::string path_cache
Definition porting.cpp:162
std::string path_user
Definition porting.cpp:160
u64 getTime(TimePrecision prec)
Definition porting.h:201
bool * signal_handler_killstatus()
Definition porting.cpp:86
u64 getTimeMs()
Definition porting.h:178
bool open_url(const std::string &url)
Opens URL in default web browser.
Definition porting.cpp:894
u64 getTimeNs()
Definition porting.h:192
const char * getPlatformName()
Definition porting.h:242
bool getCurrentExecPath(char *buf, size_t len)
Definition porting.cpp:405
std::string getDataPath(const char *subpath)
Definition porting.cpp:165
void initializePaths()
Definition porting.cpp:614
void attachOrCreateConsole()
Definition porting.cpp:783
void preciseSleepUs(u64 sleep_time)
Definition porting.h:227
static void TriggerMemoryTrim()
Definition porting.h:311
u64 getTimeUs()
Definition porting.h:185
const std::string & get_sysinfo()
Definition porting.cpp:266
#define sleep_us(x)
Definition porting.h:46
#define SLEEP_ACCURACY_US
Definition porting.h:43