Skip to content
Permalink
Browse files

Get executable name before mangling with argv

This fixes getting of executable name on OpenBSD.
  • Loading branch information...
vrurg committed May 23, 2019
1 parent 55fdc78 commit 79629bde6729ad0d8019325d88d11a2e1aff0568
Showing with 15 additions and 15 deletions.
  1. +15 −15 src/vm/moar/runner/main.c
@@ -183,6 +183,21 @@ int wmain(int argc, wchar_t *wargv[])
MVMuint32 debugserverport = 0;
int start_suspended = 0;

/* Retrieve the executable directory path. */

exec_path_size = 4096;
exec_path = (char*)malloc(exec_path_size);
res = MVM_exepath(exec_path, &exec_path_size);
while (res < 0 && exec_path_size < 4096*8) {
exec_path_size *= 2;
exec_path = (char*)realloc(exec_path, exec_path_size);
res = MVM_exepath(exec_path, &exec_path_size);
}
if (res < 0) {
fprintf(stderr, "ERROR: Could not retrieve executable path.\n");
return EXIT_FAILURE;
}

/* Filter out VM arguments from the command line. */

for (; (flag = parse_flag(argv[argi])) != NOT_A_FLAG; ++argi) {
@@ -250,21 +265,6 @@ int wmain(int argc, wchar_t *wargv[])
}
#endif

/* Retrieve the executable directory path. */

exec_path_size = 4096;
exec_path = (char*)malloc(exec_path_size);
res = MVM_exepath(exec_path, &exec_path_size);
while (res < 0 && exec_path_size < 4096*8) {
exec_path_size *= 2;
exec_path = (char*)realloc(exec_path, exec_path_size);
res = MVM_exepath(exec_path, &exec_path_size);
}
if (res < 0) {
fprintf(stderr, "ERROR: Could not retrieve executable path.\n");
return EXIT_FAILURE;
}

/* The +1 is the trailing \0 terminating the string. */
dir_path_temp = (char*)malloc(exec_path_size + 1);
memcpy(dir_path_temp, exec_path, exec_path_size + 1);

0 comments on commit 79629bd

Please sign in to comment.
You can’t perform that action at this time.