vboxwrapper, Win: error out if getenv("USERPROFILE") fails

This commit is contained in:
David Anderson 2024-07-18 22:32:35 -07:00
parent 46d6942462
commit 0883a68a81
1 changed files with 8 additions and 3 deletions

View File

@ -109,15 +109,20 @@ int VBOX_VM::initialize() {
} else { } else {
// If the override environment variable isn't specified then // If the override environment variable isn't specified then
// it is based of the current users HOME directory. // it is based of the current users HOME directory.
const char *home;
#ifdef _WIN32 #ifdef _WIN32
virtualbox_home_directory = getenv("USERPROFILE"); home = getenv("USERPROFILE");
if (home == NULL) {
vboxlog_msg("no USERPROFILE - exiting");
exit(1);
}
#else #else
const char *home = getenv("HOME"); home = getenv("HOME");
if (home == NULL) { if (home == NULL) {
home = getpwuid(getuid())->pw_dir; home = getpwuid(getuid())->pw_dir;
} }
virtualbox_home_directory = home;
#endif #endif
virtualbox_home_directory = home;
virtualbox_home_directory += "/.VirtualBox"; virtualbox_home_directory += "/.VirtualBox";
} }