Random portability stuff
*/
-#ifndef PORTING_HEADER
-#define PORTING_HEADER
+#pragma once
#ifdef _WIN32
#ifdef _WIN32_WINNT
#define sleep_ms(x) Sleep(x)
#else
#include <unistd.h>
- #include <stdint.h> //for uintptr_t
+ #include <cstdint> //for uintptr_t
// Use standard Posix macro for Linux
#if (defined(linux) || defined(__linux)) && !defined(__linux__)
#ifndef _WIN32 // Posix
#include <sys/time.h>
- #include <time.h>
- #if defined(__MACH__) && defined(__APPLE__)
+ #include <ctime>
+
+#if defined(__MACH__) && defined(__APPLE__)
#include <mach/clock.h>
#include <mach/mach.h>
#endif
Signal handler (grabs Ctrl-C on POSIX systems)
*/
-void signal_handler_init(void);
+void signal_handler_init();
// Returns a pointer to a bool.
// When the bool is true, program should quit.
-bool * signal_handler_killstatus(void);
+bool * signal_handler_killstatus();
/*
Path of static data directory.
{
struct timespec ts;
os_get_clock(&ts);
- return ts.tv_sec * 1000 + ts.tv_nsec / 1000000;
+ return ((u64) ts.tv_sec) * 1000LL + ((u64) ts.tv_nsec) / 1000000LL;
}
inline u64 getTimeUs()
{
struct timespec ts;
os_get_clock(&ts);
- return ts.tv_sec * 1000000 + ts.tv_nsec / 1000;
+ return ((u64) ts.tv_sec) * 1000000LL + ((u64) ts.tv_nsec) / 1000LL;
}
inline u64 getTimeNs()
{
struct timespec ts;
os_get_clock(&ts);
- return ts.tv_sec * 1000000000 + ts.tv_nsec;
+ return ((u64) ts.tv_sec) * 1000000000LL + ((u64) ts.tv_nsec);
}
#endif
{
if (new_time_ms >= old_time_ms) {
return (new_time_ms - old_time_ms);
- } else {
- return (old_time_ms - new_time_ms);
}
+
+ return (old_time_ms - new_time_ms);
}
inline const char *getPlatformName()
#else
"SunOS"
#endif
+#elif defined(__HAIKU__)
+ "Haiku"
#elif defined(__CYGWIN__)
"Cygwin"
#elif defined(__unix__) || defined(__unix)
bool secure_rand_fill_buf(void *buf, size_t len);
// This attaches to the parents process console, or creates a new one if it doesnt exist.
-void attachOrCreateConsole(void);
+void attachOrCreateConsole();
+
+int mt_snprintf(char *buf, const size_t buf_size, const char *fmt, ...);
+
+/**
+ * Opens URL in default web browser
+ *
+ * Must begin with http:// or https://, and not contain any new lines
+ *
+ * @param url The URL
+ * @return true on success, false on failure
+ */
+bool open_url(const std::string &url);
+
+/**
+ * Opens a directory in the default file manager
+ *
+ * The directory must exist.
+ *
+ * @param path Path to directory
+ * @return true on success, false on failure
+ */
+bool open_directory(const std::string &path);
+
} // namespace porting
#ifdef __ANDROID__
#include "porting_android.h"
#endif
-
-#endif // PORTING_HEADER
-