30 #define _WIN32_WINNT 0x0501
44 #define SWPRINTF_CHARSTRING L"%S"
46 #define SWPRINTF_CHARSTRING L"%s"
56 #define sleep_ms(x) Sleep(x)
62 #if (defined(linux) || defined(__linux)) && !defined(__linux__)
65 #if (defined(__linux__) || defined(__GNU__)) && !defined(_GNU_SOURCE)
69 #define sleep_ms(x) usleep(x*1000)
73 #define ALIGNOF(x) __alignof(x)
74 #define strtok_r(x, y, z) strtok_s(x, y, z)
75 #define strtof(x, y) (float)strtod(x, y)
76 #define strtoll(x, y, z) _strtoi64(x, y, z)
77 #define strtoull(x, y, z) _strtoui64(x, y, z)
78 #define strcasecmp(x, y) stricmp(x, y)
79 #define strncasecmp(x, y, n) strnicmp(x, y, n)
81 #define ALIGNOF(x) __alignof__(x)
85 #define strtok_r(x, y, z) mystrtok_r(x, y, z)
93 #if defined(__FreeBSD__) || defined(__NetBSD__) || \
94 defined(__OpenBSD__) || defined(__DragonFly__) || \
95 defined(__APPLE__) || \
96 defined(__sun) || defined(sun) || \
97 defined(__QNX__) || defined(__QNXNTO__)
103 #define strlcpy(d, s, n) mystrlcpy(d, s, n)
106 #define PADDING(x, y) ((ALIGNOF(y) - ((uintptr_t)(x) & (ALIGNOF(y) - 1))) & (ALIGNOF(y) - 1))
108 #if defined(__APPLE__)
109 #include <mach-o/dyld.h>
110 #include <CoreFoundation/CoreFoundation.h>
114 #include <sys/time.h>
117 #if defined(__MACH__) && defined(__APPLE__)
118 #include <mach/clock.h>
119 #include <mach/mach.h>
186 extern double perf_freq;
188 inline u64 os_get_time(
double mult)
191 QueryPerformanceCounter(&t);
192 return static_cast<double>(t.QuadPart) / (perf_freq / mult);
196 inline u64
getTimeS() {
return os_get_time(1); }
197 inline u64
getTimeMs() {
return os_get_time(1000); }
198 inline u64
getTimeUs() {
return os_get_time(1000*1000); }
199 inline u64
getTimeNs() {
return os_get_time(1000*1000*1000); }
205 #if defined(__MACH__) && defined(__APPLE__)
210 host_get_clock_service(mach_host_self(), CALENDAR_CLOCK, &cclock);
211 clock_get_time(cclock, &mts);
212 mach_port_deallocate(mach_task_self(), cclock);
213 ts->tv_sec = mts.tv_sec;
214 ts->tv_nsec = mts.tv_nsec;
215 #elif defined(CLOCK_MONOTONIC_RAW)
216 clock_gettime(CLOCK_MONOTONIC_RAW, ts);
217 #elif defined(_POSIX_MONOTONIC_CLOCK)
218 clock_gettime(CLOCK_MONOTONIC, ts);
221 gettimeofday(&tv, NULL);
222 TIMEVAL_TO_TIMESPEC(&tv, ts);
237 return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
244 return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
251 return ts.tv_sec * 1000000000 + ts.tv_nsec;
264 FATAL_ERROR(
"Called getTime with invalid time precision");
275 if (new_time_ms >= old_time_ms) {
276 return (new_time_ms - old_time_ms);
279 return (old_time_ms - new_time_ms);
287 #elif defined(__linux__)
289 #elif defined(_WIN32) || defined(_WIN64)
291 #elif defined(__DragonFly__) || defined(__FreeBSD__) || \
292 defined(__NetBSD__) || defined(__OpenBSD__)
294 #elif defined(__APPLE__) && defined(__MACH__)
297 #elif TARGET_OS_IPHONE
304 #elif defined(__hpux)
306 #elif defined(__sun) || defined(sun)
312 #elif defined(__HAIKU__)
314 #elif defined(__CYGWIN__)
316 #elif defined(__unix__) || defined(__unix)
317 #if defined(_POSIX_VERSION)
333 int mt_snprintf(
char *buf,
const size_t buf_size,
const char *fmt, ...);
343 bool open_url(
const std::string &url);
#define FATAL_ERROR(msg)
Definition: debug.h:58
TimePrecision
Definition: gettime.h:26
@ PRECISION_SECONDS
Definition: gettime.h:27
@ PRECISION_NANO
Definition: gettime.h:30
@ PRECISION_MICRO
Definition: gettime.h:29
@ PRECISION_MILLI
Definition: gettime.h:28
Definition: porting.cpp:73
u64 getDeltaMs(u64 old_time_ms, u64 new_time_ms)
Delta calculation function arguments.
Definition: porting.h:273
std::string path_locale
Definition: porting.cpp:158
bool secure_rand_fill_buf(void *buf, size_t len)
Definition: porting.cpp:668
std::string path_share
Definition: porting.cpp:156
int mt_snprintf(char *buf, const size_t buf_size, const char *fmt,...)
Definition: porting.cpp:700
void migrateCachePath()
Definition: porting.cpp:523
void os_get_clock(struct timespec *ts)
Definition: porting.h:203
void signal_handler_init(void)
Definition: porting.cpp:111
bool open_directory(const std::string &path)
Opens a directory in the default file manager.
Definition: porting.cpp:754
u64 getTimeS()
Definition: porting.h:226
std::string path_cache
Definition: porting.cpp:159
std::string path_user
Definition: porting.cpp:157
u64 getTime(TimePrecision prec)
Definition: porting.h:256
bool * signal_handler_killstatus()
Definition: porting.cpp:81
u64 getTimeMs()
Definition: porting.h:233
bool open_url(const std::string &url)
Opens URL in default web browser.
Definition: porting.cpp:744
u64 getTimeNs()
Definition: porting.h:247
std::string get_sysinfo()
Definition: porting.cpp:192
std::string getDataPath(const char *subpath)
Definition: porting.cpp:162
void initializePaths()
Definition: porting.cpp:543
void attachOrCreateConsole()
Definition: porting.cpp:687
const char * getPlatformName()
Definition: porting.h:282
u64 getTimeUs()
Definition: porting.h:240