Fixed SearchPath to handle a ';'-separated path as first argument.
This commit is contained in:
parent
ddcc85effb
commit
9400e2d727
|
@ -489,17 +489,20 @@ static BOOL DIR_TryPath( const DOS_FULL_NAME *dir, LPCSTR name,
|
||||||
* DIR_TryEnvironmentPath
|
* DIR_TryEnvironmentPath
|
||||||
*
|
*
|
||||||
* Helper function for DIR_SearchPath.
|
* Helper function for DIR_SearchPath.
|
||||||
|
* Search in the specified path, or in $PATH if NULL.
|
||||||
*/
|
*/
|
||||||
static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name )
|
static BOOL DIR_TryEnvironmentPath( LPCSTR name, DOS_FULL_NAME *full_name, LPCSTR envpath )
|
||||||
{
|
{
|
||||||
LPSTR path, next, buffer;
|
LPSTR path, next, buffer;
|
||||||
BOOL ret = FALSE;
|
BOOL ret = FALSE;
|
||||||
INT len = strlen(name);
|
INT len = strlen(name);
|
||||||
DWORD size = GetEnvironmentVariableA( "PATH", NULL, 0 );
|
DWORD size;
|
||||||
|
|
||||||
|
size = envpath ? strlen(envpath)+1 : GetEnvironmentVariableA( "PATH", NULL, 0 );
|
||||||
if (!size) return FALSE;
|
if (!size) return FALSE;
|
||||||
if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
|
if (!(path = HeapAlloc( GetProcessHeap(), 0, size ))) return FALSE;
|
||||||
if (!GetEnvironmentVariableA( "PATH", path, size )) goto done;
|
if (envpath) strcpy( path, envpath );
|
||||||
|
else if (!GetEnvironmentVariableA( "PATH", path, size )) goto done;
|
||||||
next = path;
|
next = path;
|
||||||
while (!ret && next)
|
while (!ret && next)
|
||||||
{
|
{
|
||||||
|
@ -563,7 +566,6 @@ static BOOL DIR_TryModulePath( LPCSTR name, DOS_FULL_NAME *full_name, BOOL win32
|
||||||
DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
||||||
DOS_FULL_NAME *full_name, BOOL win32 )
|
DOS_FULL_NAME *full_name, BOOL win32 )
|
||||||
{
|
{
|
||||||
DWORD len;
|
|
||||||
LPCSTR p;
|
LPCSTR p;
|
||||||
LPSTR tmp = NULL;
|
LPSTR tmp = NULL;
|
||||||
BOOL ret = TRUE;
|
BOOL ret = TRUE;
|
||||||
|
@ -578,39 +580,37 @@ DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
||||||
path = NULL; /* Ignore path if name already contains a path */
|
path = NULL; /* Ignore path if name already contains a path */
|
||||||
if (path && !*path) path = NULL; /* Ignore empty path */
|
if (path && !*path) path = NULL; /* Ignore empty path */
|
||||||
|
|
||||||
len = strlen(name);
|
|
||||||
if (ext) len += strlen(ext);
|
|
||||||
if (path) len += strlen(path) + 1;
|
|
||||||
|
|
||||||
/* Allocate a buffer for the file name and extension */
|
/* Allocate a buffer for the file name and extension */
|
||||||
|
|
||||||
if (path || ext)
|
if (ext)
|
||||||
{
|
{
|
||||||
|
DWORD len = strlen(name) + strlen(ext);
|
||||||
if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
|
if (!(tmp = HeapAlloc( GetProcessHeap(), 0, len + 1 )))
|
||||||
{
|
{
|
||||||
SetLastError( ERROR_OUTOFMEMORY );
|
SetLastError( ERROR_OUTOFMEMORY );
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
if (path)
|
strcpy( tmp, name );
|
||||||
{
|
strcat( tmp, ext );
|
||||||
strcpy( tmp, path );
|
|
||||||
strcat( tmp, "\\" );
|
|
||||||
strcat( tmp, name );
|
|
||||||
}
|
|
||||||
else strcpy( tmp, name );
|
|
||||||
if (ext) strcat( tmp, ext );
|
|
||||||
name = tmp;
|
name = tmp;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* If we have an explicit path, everything's easy */
|
|
||||||
|
|
||||||
if (path || (*name && (name[1] == ':')) ||
|
/* If the name contains an explicit path, everything's easy */
|
||||||
strchr( name, '/' ) || strchr( name, '\\' ))
|
|
||||||
|
if ((*name && (name[1] == ':')) || strchr( name, '/' ) || strchr( name, '\\' ))
|
||||||
{
|
{
|
||||||
ret = DOSFS_GetFullName( name, TRUE, full_name );
|
ret = DOSFS_GetFullName( name, TRUE, full_name );
|
||||||
goto done;
|
goto done;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/* Search in the specified path */
|
||||||
|
|
||||||
|
if (path)
|
||||||
|
{
|
||||||
|
ret = DIR_TryEnvironmentPath( name, full_name, path );
|
||||||
|
goto done;
|
||||||
|
}
|
||||||
|
|
||||||
/* Try the path of the current executable (for Win32 search order) */
|
/* Try the path of the current executable (for Win32 search order) */
|
||||||
|
|
||||||
if (win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
|
if (win32 && DIR_TryModulePath( name, full_name, win32 )) goto done;
|
||||||
|
@ -635,7 +635,7 @@ DWORD DIR_SearchPath( LPCSTR path, LPCSTR name, LPCSTR ext,
|
||||||
|
|
||||||
/* Try all directories in path */
|
/* Try all directories in path */
|
||||||
|
|
||||||
ret = DIR_TryEnvironmentPath( name, full_name );
|
ret = DIR_TryEnvironmentPath( name, full_name, NULL );
|
||||||
|
|
||||||
done:
|
done:
|
||||||
if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
|
if (tmp) HeapFree( GetProcessHeap(), 0, tmp );
|
||||||
|
|
Loading…
Reference in New Issue