Commit 3e0c90e4 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Avoid using wine_get_build/data_dir() from libwine.

parent 9122bc10
......@@ -56,3 +56,10 @@ C_SRCS = \
wcstring.c
RC_SRCS = version.rc
server_EXTRADEFS = \
-DBINDIR=\"${bindir}\" \
-DDLLDIR=\"${dlldir}\" \
-DBIN_TO_DLLDIR=\"`$(MAKEDEP) -R ${bindir} ${dlldir}`\" \
-DDLL_TO_BINDIR=\"`$(MAKEDEP) -R ${dlldir} ${bindir}`\" \
-DBIN_TO_DATADIR=\"`$(MAKEDEP) -R ${bindir} ${datadir}/wine`\"
......@@ -408,9 +408,9 @@ static void set_wow64_environment( WCHAR **env )
/* set the Wine paths */
set_wine_path_variable( env, winedatadirW, wine_get_data_dir() );
set_wine_path_variable( env, winedatadirW, data_dir );
set_wine_path_variable( env, winehomedirW, home );
set_wine_path_variable( env, winebuilddirW, wine_get_build_dir() );
set_wine_path_variable( env, winebuilddirW, build_dir );
set_wine_path_variable( env, wineconfigdirW, config_dir );
for (i = 0; (p = wine_dll_enum_load_path( i )); i++)
{
......
......@@ -2715,7 +2715,7 @@ static NTSTATUS find_builtin_dll( const WCHAR *name, WINE_MODREF **pwm,
void **module, pe_image_info_t *image_info, struct stat *st,
char **so_name )
{
const char *path, *build_dir = wine_get_build_dir();
const char *path;
unsigned int i, pos, len, namelen, maxlen = 0;
char *ptr, *file;
NTSTATUS status = STATUS_DLL_NOT_FOUND;
......
......@@ -39,7 +39,6 @@
#include "winbase.h"
#include "winnls.h"
#include "ntdll_misc.h"
#include "wine/library.h"
#include "wine/debug.h"
WINE_DEFAULT_DEBUG_CHANNEL(nls);
......@@ -758,8 +757,6 @@ static const struct { const char *name; UINT cp; } charset_names[] =
static void load_unix_cptable( unsigned int cp )
{
const char *build_dir = wine_get_build_dir();
const char *data_dir = wine_get_data_dir();
const char *dir = build_dir ? build_dir : data_dir;
struct stat st;
char *name;
......
......@@ -96,6 +96,7 @@ extern void heap_set_debug_flags( HANDLE handle ) DECLSPEC_HIDDEN;
extern void init_unix_codepage(void) DECLSPEC_HIDDEN;
extern void init_locale( HMODULE module ) DECLSPEC_HIDDEN;
extern void init_user_process_params( SIZE_T data_size ) DECLSPEC_HIDDEN;
extern void init_paths(void) DECLSPEC_HIDDEN;
extern char **build_envp( const WCHAR *envW ) DECLSPEC_HIDDEN;
extern NTSTATUS restart_process( RTL_USER_PROCESS_PARAMETERS *params, NTSTATUS status ) DECLSPEC_HIDDEN;
......@@ -104,6 +105,8 @@ extern char **__wine_main_argv;
extern WCHAR **__wine_main_wargv;
/* server support */
extern const char *build_dir DECLSPEC_HIDDEN;
extern const char *data_dir DECLSPEC_HIDDEN;
extern const char *config_dir DECLSPEC_HIDDEN;
extern timeout_t server_start_time DECLSPEC_HIDDEN;
extern unsigned int server_cpus DECLSPEC_HIDDEN;
......
......@@ -1008,7 +1008,7 @@ static const char *get_alternate_loader( char **ret_env )
*ret_env = NULL;
if (wine_get_build_dir()) loader = is_win64 ? "loader/wine" : "loader/wine64";
if (build_dir) loader = is_win64 ? "loader/wine" : "loader/wine64";
if (loader_env)
{
......
......@@ -113,8 +113,11 @@ static const enum cpu_type client_cpu = CPU_ARM64;
#error Unsupported CPU
#endif
const char *build_dir = NULL;
const char *data_dir = NULL;
const char *config_dir = NULL;
static const char *server_dir;
static const char *bin_dir;
unsigned int server_cpus = 0;
BOOL is_wow64 = FALSE;
......@@ -177,6 +180,35 @@ static void fatal_perror( const char *err, ... )
exit(1);
}
/* canonicalize path and return its directory name */
static char *realpath_dirname( const char *name )
{
char *p, *fullpath = realpath( name, NULL );
if (fullpath)
{
p = strrchr( fullpath, '/' );
if (p == fullpath) p++;
if (p) *p = 0;
}
return fullpath;
}
/* if string ends with tail, remove it */
static char *remove_tail( const char *str, const char *tail )
{
size_t len = strlen( str );
size_t tail_len = strlen( tail );
char *ret;
if (len < tail_len) return NULL;
if (strcmp( str + len - tail_len, tail )) return NULL;
ret = malloc( len - tail_len + 1 );
memcpy( ret, str, len - tail_len );
ret[len - tail_len] = 0;
return ret;
}
/* build a path from the specified dir and name */
static char *build_path( const char *dir, const char *name )
{
......@@ -1280,6 +1312,42 @@ static const char *init_config_dir(void)
/***********************************************************************
* init_paths
*/
void init_paths(void)
{
const char *dll_dir = NULL;
#ifdef HAVE_DLADDR
Dl_info info;
if (dladdr( init_paths, &info ) && info.dli_fname[0] == '/')
dll_dir = realpath_dirname( info.dli_fname );
#endif
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
bin_dir = realpath_dirname( "/proc/self/exe" );
#elif defined (__FreeBSD__) || defined(__DragonFly__)
bin_dir = realpath_dirname( "/proc/curproc/file" );
#else
bin_dir = realpath_dirname( __wine_main_argv[0] );
#endif
if (dll_dir) build_dir = remove_tail( dll_dir, "/dlls/ntdll" );
else if (bin_dir) build_dir = remove_tail( bin_dir, "/loader" );
if (!build_dir)
{
if (!bin_dir) bin_dir = dll_dir ? build_path( dll_dir, DLL_TO_BINDIR ) : BINDIR;
else if (!dll_dir) dll_dir = build_path( bin_dir, BIN_TO_DLLDIR );
data_dir = build_path( bin_dir, BIN_TO_DATADIR );
}
config_dir = init_config_dir();
}
/***********************************************************************
* setup_config_dir
*
* Setup the wine configuration dir.
......@@ -1524,8 +1592,6 @@ void server_init_process(void)
obj_handle_t version;
const char *env_socket = getenv( "WINESERVERSOCKET" );
config_dir = init_config_dir();
server_pid = -1;
if (env_socket)
{
......
......@@ -299,6 +299,7 @@ TEB *thread_init(void)
signal_init_thread( teb );
virtual_init_threading();
debug_init();
init_paths();
set_process_name( __wine_main_argc, __wine_main_argv );
/* initialize time values in user_shared_data */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment