… | |
… | |
386 | #else |
386 | #else |
387 | |
387 | |
388 | int |
388 | int |
389 | main (int argc, char *argv[]) |
389 | main (int argc, char *argv[]) |
390 | { |
390 | { |
391 | u_setenv ("URLADER_EXEPATH", argv [0]); |
|
|
392 | |
|
|
393 | pack_handle = u_open (argv [0]); |
|
|
394 | if (!u_valid (pack_handle)) |
|
|
395 | u_fatal ("unable to open executable pack"); |
|
|
396 | |
|
|
397 | if (!getcwd (currdir, sizeof (currdir))) |
391 | if (!getcwd (currdir, sizeof (currdir))) |
398 | strcpy (currdir, "."); |
392 | strcpy (currdir, "."); |
399 | |
393 | |
|
|
394 | { |
|
|
395 | const char *exe_path = 0; |
|
|
396 | |
|
|
397 | if (strchr (argv [0], '/')) |
|
|
398 | exe_path = argv [0]; |
|
|
399 | else |
|
|
400 | { |
|
|
401 | const char *p, *path = getenv ("PATH"); |
|
|
402 | |
|
|
403 | if (!path) |
|
|
404 | u_fatal ("unable to find executable, try running with full path."); |
|
|
405 | |
|
|
406 | for (p = path; ; ) |
|
|
407 | { |
|
|
408 | const char *e = p; |
|
|
409 | int l; |
|
|
410 | |
|
|
411 | while (*e && *e != ':') |
|
|
412 | ++e; |
|
|
413 | |
|
|
414 | l = e - p; |
|
|
415 | memcpy (tmppath, p, l); |
|
|
416 | |
|
|
417 | if (!l) |
|
|
418 | tmppath [l++] = '.'; |
|
|
419 | |
|
|
420 | tmppath [l++] = '/'; |
|
|
421 | |
|
|
422 | strcpy (tmppath + l, argv [0]); |
|
|
423 | |
|
|
424 | if (!access (tmppath, X_OK)) |
|
|
425 | break; |
|
|
426 | |
|
|
427 | p = e; |
|
|
428 | if (!*p) |
|
|
429 | u_fatal ("unable to find executable, try running with full path."); |
|
|
430 | |
|
|
431 | ++p; |
|
|
432 | } |
|
|
433 | |
|
|
434 | exe_path = tmppath; |
|
|
435 | } |
|
|
436 | |
|
|
437 | pack_handle = u_open (exe_path); |
|
|
438 | if (!u_valid (pack_handle)) |
|
|
439 | u_fatal ("unable to open executable for reading - permissions problem?"); |
|
|
440 | |
|
|
441 | u_setenv ("URLADER_EXEPATH", exe_path); |
|
|
442 | } |
|
|
443 | |
400 | #if 0 |
444 | #if 0 |
401 | /* intersperse hostname, for whatever reason */ |
445 | /* intersperse hostname, for whatever reason */ |
402 | |
446 | |
403 | if (gethostname (tmppath, sizeof (tmppath))) |
447 | if (gethostname (tmppath, sizeof (tmppath))) |
404 | strcpy (tmppath, "default"); |
448 | strcpy (tmppath, "default"); |