Added search path relative to running binary on Windows.

In contrast to *IX it doesn't make much sense to add compile time defined
search paths to Windows binaries: There's no standard path like /usr/local/bin
(and there are no symbolic links to link from there to another location).

On the other hand it's (again in contrast to *IX) easy for Windows binaries
to determine their own paths. Therefore it's appropriate to make use of that
to add run time defined default search paths.
This commit is contained in:
Oliver Schmidt
2013-05-06 23:20:56 +02:00
parent 983c6285e1
commit 55667b94fb
5 changed files with 60 additions and 1 deletions

View File

@@ -157,6 +157,48 @@ void AddSubSearchPathFromEnv (SearchPath* P, const char* EnvVar, const char* Sub
void AddSubSearchPathFromWinBin (SearchPath* P, const char* SubDir)
{
/* Windows only:
* Add a search path from the running binary, adding a subdirectory to
* the parent directory of the directory containing the binary.
*/
#if defined(_MSC_VER)
char Dir[_MAX_PATH];
char* Ptr;
if (_get_pgmptr (&Ptr) != 0) {
return;
}
strcpy (Dir, Ptr);
/* Remove binary name */
Ptr = strrchr (Dir, '\\');
if (Ptr == 0) {
return;
}
*Ptr = '\0';
/* Check for 'bin' directory */
Ptr = strrchr (Dir, '\\');
if (Ptr == 0) {
return;
}
if (strcmp (Ptr++, "\\bin") != 0) {
return;
}
/* Append SubDir */
strcpy (Ptr, SubDir);
/* Add the search path */
AddSearchPath (P, Dir);
#endif
}
int PushSearchPath (SearchPath* P, const char* NewPath)
/* Add a new search path to the head of an existing search path list, provided
* that it's not already there. If the path is already at the first position,