summaryrefslogtreecommitdiffstats
path: root/libdimension/platform.c
diff options
context:
space:
mode:
Diffstat (limited to 'libdimension/platform.c')
-rw-r--r--libdimension/platform.c33
1 files changed, 31 insertions, 2 deletions
diff --git a/libdimension/platform.c b/libdimension/platform.c
index 6ac15c0..be7e7a8 100644
--- a/libdimension/platform.c
+++ b/libdimension/platform.c
@@ -19,8 +19,37 @@
*************************************************************************/
#include "dimension_impl.h"
-#include <unistd.h> /* For sysconf() */
-#include <sched.h> /* For sched_getaffinity() */
+#include <unistd.h> /* For sysconf() */
+#include <arpa/inet.h> /* For htonl() */
+#include <execinfo.h> /* For backtrace() etc. */
+#include <sys/syscall.h> /* For gettid() where supported */
+#include <sched.h> /* For sched_getaffinity() */
+
+void
+dmnsn_backtrace(FILE *file)
+{
+ const size_t size = 128;
+ void *buffer[size];
+
+ int nptrs = backtrace(buffer, size);
+ backtrace_symbols_fd(buffer, nptrs, fileno(file));
+}
+
+bool
+dmnsn_is_main_thread()
+{
+#ifdef SYS_gettid
+ return getpid() == syscall(SYS_gettid);
+#else
+ return true;
+#endif
+}
+
+bool
+dmnsn_is_little_endian()
+{
+ return htonl(1) != 1;
+}
size_t
dmnsn_ncpus()