Commit 7c777af4 authored by Alexandre Julliard's avatar Alexandre Julliard

ntdll: Add a helper to build a path and exec it.

parent 26f11bdf
...@@ -297,14 +297,26 @@ static char *build_path( const char *dir, const char *name ) ...@@ -297,14 +297,26 @@ static char *build_path( const char *dir, const char *name )
size_t len = strlen( dir ); size_t len = strlen( dir );
char *ret = malloc( len + strlen( name ) + 2 ); char *ret = malloc( len + strlen( name ) + 2 );
memcpy( ret, dir, len ); if (len)
if (len && ret[len - 1] != '/') ret[len++] = '/'; {
if (name[0] == '/') name++; memcpy( ret, dir, len );
if (ret[len - 1] != '/') ret[len++] = '/';
if (name[0] == '/') name++;
}
strcpy( ret + len, name ); strcpy( ret + len, name );
return ret; return ret;
} }
/* build a path to a binary and exec it */
static void build_path_and_exec( const char *dir, const char *name, char **argv )
{
argv[0] = build_path( dir, name );
execv( argv[0], argv );
free( argv[0] );
}
static const char *get_pe_dir( WORD machine ) static const char *get_pe_dir( WORD machine )
{ {
if (!machine) machine = current_machine; if (!machine) machine = current_machine;
...@@ -564,34 +576,22 @@ static void exec_wineserver( char **argv ) ...@@ -564,34 +576,22 @@ static void exec_wineserver( char **argv )
if (!is_win64) /* look for 64-bit server */ if (!is_win64) /* look for 64-bit server */
{ {
char *loader = realpath_dirname( build_path( build_dir, "loader/wine64" )); char *loader = realpath_dirname( build_path( build_dir, "loader/wine64" ));
if (loader) if (loader) build_path_and_exec( loader, "../server/wineserver", argv );
{
argv[0] = build_path( loader, "../server/wineserver" );
execv( argv[0], argv );
}
} }
argv[0] = build_path( build_dir, "server/wineserver" ); build_path_and_exec( build_dir, "server/wineserver", argv );
execv( argv[0], argv );
return; return;
} }
argv[0] = build_path( bin_dir, "wineserver" ); build_path_and_exec( bin_dir, "wineserver", argv );
execv( argv[0], argv );
argv[0] = getenv( "WINESERVER" ); if ((path = getenv( "WINESERVER" ))) build_path_and_exec( "", path, argv );
if (argv[0]) execv( argv[0], argv );
if ((path = getenv( "PATH" ))) if ((path = getenv( "PATH" )))
{ {
for (path = strtok( strdup( path ), ":" ); path; path = strtok( NULL, ":" )) for (path = strtok( strdup( path ), ":" ); path; path = strtok( NULL, ":" ))
{ build_path_and_exec( path, "wineserver", argv );
argv[0] = build_path( path, "wineserver" );
execvp( argv[0], argv );
}
} }
build_path_and_exec( BINDIR, "wineserver", argv );
argv[0] = build_path( BINDIR, "wineserver" );
execv( argv[0], argv );
} }
......
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