libwine: Add a helper function to set the dll directory.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
oldstable
Alexandre Julliard 2017-06-26 13:37:25 +02:00
parent 161f3fc417
commit 56b14d637f
1 changed files with 35 additions and 15 deletions

View File

@ -330,6 +330,16 @@ static int is_valid_bindir( const char *bindir )
return ret;
}
/* check if dlldir is valid by checking for ntdll */
static int is_valid_dlldir( const char *dlldir )
{
struct stat st;
char *path = build_path( dlldir, "ntdll.dll.so" );
int ret = (stat( path, &st ) != -1);
free( path );
return ret;
}
/* check if basedir is a valid build dir by checking for wineserver and ntdll */
/* helper for running_from_build_dir */
static inline int is_valid_build_dir( char *basedir, int baselen )
@ -381,6 +391,7 @@ static int set_bindir( char *dir )
if (is_valid_bindir( dir ))
{
bindir = dir;
dlldir = build_path( bindir, BIN_TO_DLLDIR );
}
else
{
@ -390,26 +401,39 @@ static int set_bindir( char *dir )
return bindir || build_dir;
}
/* try to set the specified directory as dlldir, or set build_dir if it's inside the build directory */
static int set_dlldir( char *libdir )
{
char *path;
if (!libdir) return 0;
path = build_path( libdir, LIB_TO_DLLDIR );
if (is_valid_dlldir( path ))
{
dlldir = path;
bindir = build_path( libdir, LIB_TO_BINDIR );
}
else
{
build_dir = running_from_build_dir( libdir );
free( path );
}
free( libdir );
return dlldir || build_dir;
}
/* initialize the argv0 path */
void wine_init_argv0_path( const char *argv0 )
{
const char *basename;
char *libdir = NULL;
if (!(basename = strrchr( argv0, '/' ))) basename = argv0;
else basename++;
if (set_bindir( get_runtime_exedir() )) goto done;
libdir = get_runtime_libdir();
if (libdir && !bindir && !build_dir)
{
build_dir = running_from_build_dir( libdir );
if (!build_dir) bindir = build_path( libdir, LIB_TO_BINDIR );
}
if (!libdir && !bindir && !build_dir)
set_bindir( get_runtime_argvdir( argv0 ));
if (set_dlldir( get_runtime_libdir() )) goto done;
set_bindir( get_runtime_argvdir( argv0 ));
done:
if (build_dir)
@ -418,13 +442,9 @@ done:
}
else
{
if (libdir) dlldir = build_path( libdir, LIB_TO_DLLDIR );
else if (bindir) dlldir = build_path( bindir, BIN_TO_DLLDIR );
if (bindir) datadir = build_path( bindir, BIN_TO_DATADIR );
argv0_name = xstrdup( basename );
}
free( libdir );
}
/* return the configuration directory ($WINEPREFIX or $HOME/.wine) */