summaryrefslogtreecommitdiff
path: root/driver/utils/getLocation.c
blob: fcbe1b940c2fbfed5bed5e4ef16be5a60aba067a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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;
}