From 56b14d637fdd213e0377526c2b98d2f36384332e Mon Sep 17 00:00:00 2001 From: Alexandre Julliard Date: Mon, 26 Jun 2017 13:37:25 +0200 Subject: [PATCH] libwine: Add a helper function to set the dll directory. Signed-off-by: Alexandre Julliard --- libs/wine/config.c | 50 ++++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 15 deletions(-) diff --git a/libs/wine/config.c b/libs/wine/config.c index 129a56593a9..f85910bfc8f 100644 --- a/libs/wine/config.c +++ b/libs/wine/config.c @@ -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) */