summaryrefslogtreecommitdiff
path: root/hadrian/bindist/cwrappers/getLocation.c
diff options
context:
space:
mode:
Diffstat (limited to 'hadrian/bindist/cwrappers/getLocation.c')
-rw-r--r--hadrian/bindist/cwrappers/getLocation.c40
1 files changed, 40 insertions, 0 deletions
diff --git a/hadrian/bindist/cwrappers/getLocation.c b/hadrian/bindist/cwrappers/getLocation.c
new file mode 100644
index 0000000000..fcbe1b940c
--- /dev/null
+++ b/hadrian/bindist/cwrappers/getLocation.c
@@ -0,0 +1,40 @@
+
+#include "getLocation.h"
+#include <stdio.h>
+#include <windows.h>
+
+static void die(char *msg) {
+ fprintf(stderr, "%s", msg);
+ exit(1);
+}
+
+char *getExecutable(void) {
+ char *p;
+ int i;
+ int r;
+
+ i = 2048; /* plenty, PATH_MAX is 512 under Win32 */
+ p = malloc(i);
+ if (p == NULL) {
+ die("Malloc failed\n");
+ }
+ r = GetModuleFileNameA(NULL, p, i);
+ if (r == 0) {
+ die("getModuleFileName failed\n");
+ }
+ return p;
+}
+
+char *getExecutablePath(void) {
+ char *p;
+ char *f;
+
+ p = getExecutable();
+ f = strrchr(p, '\\');
+ if (f == NULL) {
+ die("No '\\' in executable location\n");
+ }
+ f[0] = '\0';
+ return p;
+}
+