diff options
Diffstat (limited to 'src/util/os_installation.c')
-rw-r--r-- | src/util/os_installation.c | 135 |
1 files changed, 2 insertions, 133 deletions
diff --git a/src/util/os_installation.c b/src/util/os_installation.c index 8d9c6e622..104a98da6 100644 --- a/src/util/os_installation.c +++ b/src/util/os_installation.c | |||
@@ -39,8 +39,6 @@ | |||
39 | #if DARWIN | 39 | #if DARWIN |
40 | #include <mach-o/ldsyms.h> | 40 | #include <mach-o/ldsyms.h> |
41 | #include <mach-o/dyld.h> | 41 | #include <mach-o/dyld.h> |
42 | #elif WINDOWS | ||
43 | #include <windows.h> | ||
44 | #endif | 42 | #endif |
45 | 43 | ||
46 | 44 | ||
@@ -212,124 +210,6 @@ get_path_from_proc_exe() | |||
212 | #endif | 210 | #endif |
213 | 211 | ||
214 | 212 | ||
215 | #if WINDOWS | ||
216 | static HINSTANCE dll_instance; | ||
217 | |||
218 | |||
219 | /** | ||
220 | * GNUNET_util_cl_init() in common_logging.c is preferred. | ||
221 | * This function is only for thread-local storage (not used in GNUnet) | ||
222 | * and hInstance saving. | ||
223 | */ | ||
224 | BOOL WINAPI | ||
225 | DllMain(HINSTANCE hinstDLL, DWORD fdwReason, LPVOID lpvReserved) | ||
226 | { | ||
227 | switch (fdwReason) | ||
228 | { | ||
229 | case DLL_PROCESS_ATTACH: | ||
230 | dll_instance = hinstDLL; | ||
231 | break; | ||
232 | |||
233 | case DLL_THREAD_ATTACH: | ||
234 | break; | ||
235 | |||
236 | case DLL_THREAD_DETACH: | ||
237 | break; | ||
238 | |||
239 | case DLL_PROCESS_DETACH: | ||
240 | break; | ||
241 | } | ||
242 | return TRUE; | ||
243 | } | ||
244 | |||
245 | |||
246 | /** | ||
247 | * Try to determine path with win32-specific function | ||
248 | * | ||
249 | * @return NULL on error | ||
250 | */ | ||
251 | static char * | ||
252 | get_path_from_module_filename() | ||
253 | { | ||
254 | size_t pathlen = 512; | ||
255 | DWORD real_pathlen; | ||
256 | wchar_t *idx; | ||
257 | wchar_t *modulepath = NULL; | ||
258 | char *upath; | ||
259 | uint8_t *u8_string; | ||
260 | size_t u8_string_length; | ||
261 | |||
262 | /* This braindead function won't tell us how much space it needs, so | ||
263 | * we start at 1024 and double the space up if it doesn't fit, until | ||
264 | * it fits, or we exceed the threshold. | ||
265 | */ | ||
266 | do | ||
267 | { | ||
268 | pathlen = pathlen * 2; | ||
269 | modulepath = GNUNET_realloc(modulepath, pathlen * sizeof(wchar_t)); | ||
270 | SetLastError(0); | ||
271 | real_pathlen = | ||
272 | GetModuleFileNameW(dll_instance, modulepath, pathlen * sizeof(wchar_t)); | ||
273 | } | ||
274 | while (real_pathlen >= pathlen && pathlen < 16 * 1024); | ||
275 | if (real_pathlen >= pathlen) | ||
276 | GNUNET_assert(0); | ||
277 | /* To be safe */ | ||
278 | modulepath[real_pathlen] = '\0'; | ||
279 | |||
280 | idx = modulepath + real_pathlen; | ||
281 | while ((idx > modulepath) && (*idx != L'\\') && (*idx != L'/')) | ||
282 | idx--; | ||
283 | *idx = L'\0'; | ||
284 | |||
285 | /* Now modulepath holds full path to the directory where libgnunetutil is. | ||
286 | * This directory should look like <GNUNET_PREFIX>/bin or <GNUNET_PREFIX>. | ||
287 | */ | ||
288 | if (wcschr(modulepath, L'/') || wcschr(modulepath, L'\\')) | ||
289 | { | ||
290 | /* At least one directory component (i.e. we're not in a root directory) */ | ||
291 | wchar_t *dirname = idx; | ||
292 | while ((dirname > modulepath) && (*dirname != L'\\') && (*dirname != L'/')) | ||
293 | dirname--; | ||
294 | *dirname = L'\0'; | ||
295 | if (dirname > modulepath) | ||
296 | { | ||
297 | dirname++; | ||
298 | /* Now modulepath holds full path to the parent directory of the directory | ||
299 | * where libgnunetutil is. | ||
300 | * dirname holds the name of the directory where libgnunetutil is. | ||
301 | */ | ||
302 | if (wcsicmp(dirname, L"bin") == 0) | ||
303 | { | ||
304 | /* pass */ | ||
305 | } | ||
306 | else | ||
307 | { | ||
308 | /* Roll back our changes to modulepath */ | ||
309 | dirname--; | ||
310 | *dirname = L'/'; | ||
311 | } | ||
312 | } | ||
313 | } | ||
314 | |||
315 | /* modulepath is GNUNET_PREFIX */ | ||
316 | u8_string = | ||
317 | u16_to_u8(modulepath, wcslen(modulepath), NULL, &u8_string_length); | ||
318 | if (NULL == u8_string) | ||
319 | GNUNET_assert(0); | ||
320 | |||
321 | upath = GNUNET_malloc(u8_string_length + 1); | ||
322 | GNUNET_memcpy(upath, u8_string, u8_string_length); | ||
323 | upath[u8_string_length] = '\0'; | ||
324 | |||
325 | free(u8_string); | ||
326 | GNUNET_free(modulepath); | ||
327 | |||
328 | return upath; | ||
329 | } | ||
330 | #endif | ||
331 | |||
332 | |||
333 | #if DARWIN | 213 | #if DARWIN |
334 | /** | 214 | /** |
335 | * Signature of the '_NSGetExecutablePath" function. | 215 | * Signature of the '_NSGetExecutablePath" function. |
@@ -433,12 +313,9 @@ get_path_from_PATH(const char *binary) | |||
433 | 313 | ||
434 | if (NULL == (p = getenv("PATH"))) | 314 | if (NULL == (p = getenv("PATH"))) |
435 | return NULL; | 315 | return NULL; |
436 | #if WINDOWS | 316 | |
437 | /* On W32 look in CWD first. */ | ||
438 | GNUNET_asprintf(&path, ".%c%s", PATH_SEPARATOR, p); | ||
439 | #else | ||
440 | path = GNUNET_strdup(p); /* because we write on it */ | 317 | path = GNUNET_strdup(p); /* because we write on it */ |
441 | #endif | 318 | |
442 | buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1); | 319 | buf = GNUNET_malloc(strlen(path) + strlen(binary) + 1 + 1); |
443 | pos = path; | 320 | pos = path; |
444 | while (NULL != (end = strchr(pos, PATH_SEPARATOR))) | 321 | while (NULL != (end = strchr(pos, PATH_SEPARATOR))) |
@@ -512,10 +389,6 @@ os_get_gnunet_path() | |||
512 | if (NULL != (ret = get_path_from_proc_exe())) | 389 | if (NULL != (ret = get_path_from_proc_exe())) |
513 | return ret; | 390 | return ret; |
514 | #endif | 391 | #endif |
515 | #if WINDOWS | ||
516 | if (NULL != (ret = get_path_from_module_filename())) | ||
517 | return ret; | ||
518 | #endif | ||
519 | #if DARWIN | 392 | #if DARWIN |
520 | if (NULL != (ret = get_path_from_dyld_image())) | 393 | if (NULL != (ret = get_path_from_dyld_image())) |
521 | return ret; | 394 | return ret; |
@@ -548,10 +421,6 @@ os_get_exec_path() | |||
548 | if (NULL != (ret = get_path_from_proc_exe())) | 421 | if (NULL != (ret = get_path_from_proc_exe())) |
549 | return ret; | 422 | return ret; |
550 | #endif | 423 | #endif |
551 | #if WINDOWS | ||
552 | if (NULL != (ret = get_path_from_module_filename())) | ||
553 | return ret; | ||
554 | #endif | ||
555 | #if DARWIN | 424 | #if DARWIN |
556 | if (NULL != (ret = get_path_from_NSGetExecutablePath())) | 425 | if (NULL != (ret = get_path_from_NSGetExecutablePath())) |
557 | return ret; | 426 | return ret; |