extern "C" {
#endif
+#if defined(__linux__)
+// make realpath() available:
+#define _DEFAULT_SOURCE
+#endif
+
#if !defined(WAI_MALLOC) || !defined(WAI_FREE) || !defined(WAI_REALLOC)
#include <stdlib.h>
#endif
#pragma warning(push, 3)
#endif
#include <windows.h>
-#include <intrin.h>
+//#include <intrin.h> // not required and doesn't exist in old mingw environments
#if defined(_MSC_VER)
#pragma warning(pop)
#endif
return WAI_PREFIX(getModulePath_)(NULL, out, capacity, dirname_length);
}
-WAI_NOINLINE
+// GetModuleHandleEx() is not available on old mingw environments. We don't need getModulePath() yet.
+// Sacrifice it for the time being to improve backwards compatibility
+/* WAI_NOINLINE
WAI_FUNCSPEC
int WAI_PREFIX(getModulePath)(char* out, int capacity, int* dirname_length)
{
return length;
}
+ */
#elif defined(__linux__)
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
-#include <limits.h>
+// #include <limits.h> // not all linux distributions define PATH_MAX in limits.h because it depends on the filesystem. Therefore use...
+#include <linux/limits.h>
#ifndef __STDC_FORMAT_MACROS
#define __STDC_FORMAT_MACROS
#endif
if (!fgets(buffer, sizeof(buffer), maps))
break;
- if (sscanf(buffer, "%" PRIx64 "-%" PRIx64 " %s %" PRIx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
+ if (sscanf(buffer, "%" SCNx64 "-%" SCNx64 " %s %" SCNx64 " %x:%x %u %s\n", &low, &high, perms, &offset, &major, &minor, &inode, path) == 8)
{
uint64_t addr = (uint64_t)(uintptr_t)WAI_RETURN_ADDRESS();
if (low <= addr && addr <= high)