/
util.c
64 lines (54 loc) · 1.42 KB
/
util.c
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
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
/*
* util.c: Simple runtime tools for the Win32 platform
*
* Author:
* Miguel de Icaza
*
* (C) 2002 Ximian, Inc. (http://www.ximian.com)
*/
#include <config.h>
#include <windows.h>
#include <mono/metadata/metadata.h>
#include <mono/metadata/assembly.h>
#include <mono/os/util.h>
#ifdef UNDER_CE
#undef GetModuleFileName
#define GetModuleFileName ceGetModuleFileNameA
DWORD ceGetModuleFileNameA(HMODULE hModule, char* lpFilename, DWORD nSize)
{
DWORD res = 0;
wchar_t* wbuff = (wchar_t*)LocalAlloc(LPTR, nSize*2);
res = GetModuleFileNameW(hModule, wbuff, nSize);
if (res) {
int len = wcslen(wbuff);
WideCharToMultiByte(CP_ACP, 0, wbuff, len, lpFilename, len, NULL, NULL);
}
LocalFree(wbuff);
return res;
}
#endif
/*
* mono_set_rootdir:
*
* Informs the runtime of the root directory for the Mono installation,
* the vm_file
*/
void
mono_set_rootdir (void)
{
gunichar2 moddir [MAXPATHLEN];
gchar *bindir, *installdir, *root, *utf8name, *config;
GetModuleFileNameW (NULL, moddir, MAXPATHLEN);
utf8name = g_utf16_to_utf8 (moddir, -1, NULL, NULL, NULL);
bindir = g_path_get_dirname (utf8name);
installdir = g_path_get_dirname (bindir);
root = g_build_path (G_DIR_SEPARATOR_S, installdir, "lib", NULL);
mono_assembly_setrootdir (root);
config = g_build_filename (root, "etc", NULL);
mono_internal_set_config_dir (etc);
g_free (config);
g_free (root);
g_free (installdir);
g_free (bindir);
g_free (utf8name);
}