libwine: Make the various directory functions obsolete.

Signed-off-by: Alexandre Julliard <julliard@winehq.org>
This commit is contained in:
Alexandre Julliard 2020-04-27 12:36:15 +02:00
parent ba1495f7c2
commit 98682cfd01
4 changed files with 142 additions and 136 deletions

View File

@ -41,11 +41,6 @@ extern "C" {
/* configuration */
extern const char *wine_get_build_dir(void);
extern const char *wine_get_config_dir(void);
extern const char *wine_get_data_dir(void);
extern const char *wine_get_server_dir(void);
extern const char *wine_get_user_name(void);
extern const char *wine_get_version(void);
extern const char *wine_get_build_id(void);
extern void wine_init_argv0_path( const char *argv0 );
@ -55,7 +50,6 @@ extern void wine_exec_wine_binary( const char *name, char **argv, const char *en
typedef void (*load_dll_callback_t)( void *, const char * );
extern void wine_dll_set_callback( load_dll_callback_t load );
extern const char *wine_dll_enum_load_path( unsigned int index );
extern void __wine_dll_register( const IMAGE_NT_HEADERS *header, const char *filename );
extern void wine_init( int argc, char *argv[], char *error, int error_size );

View File

@ -40,25 +40,18 @@
#define _POSIX_SPAWN_DISABLE_ASLR 0x0100
#endif
#endif
#include "wine/asm.h"
#include "wine/library.h"
static const char server_config_dir[] = "/.wine"; /* config dir relative to $HOME */
static const char server_root_prefix[] = "/tmp/.wine"; /* prefix for server root dir */
static const char server_dir_prefix[] = "/server-"; /* prefix for server dir */
static char *bindir;
static char *dlldir;
static char *datadir;
static char *config_dir;
static char *server_dir;
static char *build_dir;
static char *user_name;
const char *build_dir;
static char *argv0_name;
static char *wineserver64;
#ifdef __GNUC__
static void fatal_error( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
static void fatal_perror( const char *err, ... ) __attribute__((noreturn,format(printf,1,2)));
#endif
#if defined(__linux__) || defined(__FreeBSD_kernel__) || defined(__NetBSD__)
@ -81,19 +74,6 @@ static void fatal_error( const char *err, ... )
exit(1);
}
/* die on a fatal error */
static void fatal_perror( const char *err, ... )
{
va_list args;
va_start( args, err );
fprintf( stderr, "wine: " );
vfprintf( stderr, err, args );
perror( " " );
va_end( args );
exit(1);
}
/* malloc wrapper */
static void *xmalloc( size_t size )
{
@ -121,13 +101,6 @@ static inline int strendswith( const char* str, const char* end )
return len >= tail && !strcmp( str + len - tail, end );
}
/* remove all trailing slashes from a path name */
static inline void remove_trailing_slashes( char *path )
{
int len = strlen( path );
while (len > 1 && path[len-1] == '/') path[--len] = 0;
}
/* build a path from the specified dir and name */
static char *build_path( const char *dir, const char *name )
{
@ -221,35 +194,6 @@ static char *get_runtime_argvdir( const char *argv0 )
return bindir;
}
/* initialize the server directory value */
static void init_server_dir( dev_t dev, ino_t ino )
{
char *p, *root;
#ifdef __ANDROID__ /* there's no /tmp dir on Android */
root = build_path( config_dir, ".wineserver" );
#else
root = xmalloc( sizeof(server_root_prefix) + 12 );
sprintf( root, "%s-%u", server_root_prefix, getuid() );
#endif
server_dir = xmalloc( strlen(root) + sizeof(server_dir_prefix) + 2*sizeof(dev) + 2*sizeof(ino) + 2 );
strcpy( server_dir, root );
strcat( server_dir, server_dir_prefix );
p = server_dir + strlen(server_dir);
if (dev != (unsigned long)dev)
p += sprintf( p, "%lx%08lx-", (unsigned long)((unsigned long long)dev >> 32), (unsigned long)dev );
else
p += sprintf( p, "%lx-", (unsigned long)dev );
if (ino != (unsigned long)ino)
sprintf( p, "%lx%08lx", (unsigned long)((unsigned long long)ino >> 32), (unsigned long)ino );
else
sprintf( p, "%lx", (unsigned long)ino );
free( root );
}
/* retrieve the default dll dir */
const char *get_dlldir( const char **default_dlldir )
{
@ -257,62 +201,6 @@ const char *get_dlldir( const char **default_dlldir )
return dlldir;
}
/* initialize all the paths values */
static void init_paths(void)
{
struct stat st;
const char *home = getenv( "HOME" );
const char *user = NULL;
const char *prefix = getenv( "WINEPREFIX" );
char uid_str[32];
struct passwd *pwd = getpwuid( getuid() );
if (pwd)
{
user = pwd->pw_name;
if (!home) home = pwd->pw_dir;
}
if (!user)
{
sprintf( uid_str, "%lu", (unsigned long)getuid() );
user = uid_str;
}
user_name = xstrdup( user );
/* build config_dir */
if (prefix)
{
config_dir = xstrdup( prefix );
remove_trailing_slashes( config_dir );
if (config_dir[0] != '/')
fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
if (stat( config_dir, &st ) == -1)
{
if (errno == ENOENT) return; /* will be created later on */
fatal_perror( "cannot open %s as specified in WINEPREFIX", config_dir );
}
}
else
{
if (!home) fatal_error( "could not determine your home directory\n" );
if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
config_dir = xmalloc( strlen(home) + sizeof(server_config_dir) );
strcpy( config_dir, home );
remove_trailing_slashes( config_dir );
strcat( config_dir, server_config_dir );
if (stat( config_dir, &st ) == -1)
{
if (errno == ENOENT) return; /* will be created later on */
fatal_perror( "cannot open %s", config_dir );
}
}
if (!S_ISDIR(st.st_mode)) fatal_error( "%s is not a directory\n", config_dir );
if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );
init_server_dir( st.st_dev, st.st_ino );
}
/* check if bindir is valid by checking for wineserver */
static int is_valid_bindir( const char *bindir )
{
@ -451,27 +339,142 @@ done:
}
}
#ifdef __ASM_OBSOLETE
static const char server_config_dir[] = "/.wine"; /* config dir relative to $HOME */
static const char server_root_prefix[] = "/tmp/.wine"; /* prefix for server root dir */
static const char server_dir_prefix[] = "/server-"; /* prefix for server dir */
static char *config_dir;
static char *server_dir;
static char *user_name;
/* remove all trailing slashes from a path name */
static inline void remove_trailing_slashes( char *path )
{
int len = strlen( path );
while (len > 1 && path[len-1] == '/') path[--len] = 0;
}
/* die on a fatal error */
static void fatal_perror( const char *err, ... )
{
va_list args;
va_start( args, err );
fprintf( stderr, "wine: " );
vfprintf( stderr, err, args );
perror( " " );
va_end( args );
exit(1);
}
/* initialize the server directory value */
static void init_server_dir( dev_t dev, ino_t ino )
{
char *p, *root;
#ifdef __ANDROID__ /* there's no /tmp dir on Android */
root = build_path( config_dir, ".wineserver" );
#else
root = xmalloc( sizeof(server_root_prefix) + 12 );
sprintf( root, "%s-%u", server_root_prefix, getuid() );
#endif
server_dir = xmalloc( strlen(root) + sizeof(server_dir_prefix) + 2*sizeof(dev) + 2*sizeof(ino) + 2 );
strcpy( server_dir, root );
strcat( server_dir, server_dir_prefix );
p = server_dir + strlen(server_dir);
if (dev != (unsigned long)dev)
p += sprintf( p, "%lx%08lx-", (unsigned long)((unsigned long long)dev >> 32), (unsigned long)dev );
else
p += sprintf( p, "%lx-", (unsigned long)dev );
if (ino != (unsigned long)ino)
sprintf( p, "%lx%08lx", (unsigned long)((unsigned long long)ino >> 32), (unsigned long)ino );
else
sprintf( p, "%lx", (unsigned long)ino );
free( root );
}
/* initialize all the paths values */
static void init_paths(void)
{
struct stat st;
const char *home = getenv( "HOME" );
const char *user = NULL;
const char *prefix = getenv( "WINEPREFIX" );
char uid_str[32];
struct passwd *pwd = getpwuid( getuid() );
if (pwd)
{
user = pwd->pw_name;
if (!home) home = pwd->pw_dir;
}
if (!user)
{
sprintf( uid_str, "%lu", (unsigned long)getuid() );
user = uid_str;
}
user_name = xstrdup( user );
/* build config_dir */
if (prefix)
{
config_dir = xstrdup( prefix );
remove_trailing_slashes( config_dir );
if (config_dir[0] != '/')
fatal_error( "invalid directory %s in WINEPREFIX: not an absolute path\n", prefix );
if (stat( config_dir, &st ) == -1)
{
if (errno == ENOENT) return; /* will be created later on */
fatal_perror( "cannot open %s as specified in WINEPREFIX", config_dir );
}
}
else
{
if (!home) fatal_error( "could not determine your home directory\n" );
if (home[0] != '/') fatal_error( "your home directory %s is not an absolute path\n", home );
config_dir = xmalloc( strlen(home) + sizeof(server_config_dir) );
strcpy( config_dir, home );
remove_trailing_slashes( config_dir );
strcat( config_dir, server_config_dir );
if (stat( config_dir, &st ) == -1)
{
if (errno == ENOENT) return; /* will be created later on */
fatal_perror( "cannot open %s", config_dir );
}
}
if (!S_ISDIR(st.st_mode)) fatal_error( "%s is not a directory\n", config_dir );
if (st.st_uid != getuid()) fatal_error( "%s is not owned by you\n", config_dir );
init_server_dir( st.st_dev, st.st_ino );
}
/* return the configuration directory ($WINEPREFIX or $HOME/.wine) */
const char *wine_get_config_dir(void)
const char *wine_get_config_dir_obsolete(void)
{
if (!config_dir) init_paths();
return config_dir;
}
/* retrieve the wine data dir */
const char *wine_get_data_dir(void)
const char *wine_get_data_dir_obsolete(void)
{
return datadir;
}
/* retrieve the wine build dir (if we are running from there) */
const char *wine_get_build_dir(void)
const char *wine_get_build_dir_obsolete(void)
{
return build_dir;
}
/* return the full name of the server directory (the one containing the socket) */
const char *wine_get_server_dir(void)
const char *wine_get_server_dir_obsolete(void)
{
if (!server_dir)
{
@ -492,12 +495,20 @@ const char *wine_get_server_dir(void)
}
/* return the current user name */
const char *wine_get_user_name(void)
const char *wine_get_user_name_obsolete(void)
{
if (!user_name) init_paths();
return user_name;
}
__ASM_OBSOLETE(wine_get_build_dir);
__ASM_OBSOLETE(wine_get_config_dir);
__ASM_OBSOLETE(wine_get_data_dir);
__ASM_OBSOLETE(wine_get_server_dir);
__ASM_OBSOLETE(wine_get_user_name);
#endif /* __ASM_OBSOLETE */
/* return the standard version string */
const char *wine_get_version(void)
{

View File

@ -94,7 +94,7 @@ static const IMAGE_NT_HEADERS *main_exe;
static load_dll_callback_t load_dll_callback;
static const char *build_dir;
extern const char *build_dir;
static const char *default_dlldir;
static const char **dll_paths;
static unsigned int nb_dll_paths;
@ -132,7 +132,7 @@ static void build_dll_path(void)
dll_path_maxlen = strlen(dlldir);
dll_paths[nb_dll_paths++] = dlldir;
}
else if ((build_dir = wine_get_build_dir()))
else if (build_dir)
{
dll_path_maxlen = strlen(build_dir) + sizeof("/programs");
}
@ -494,20 +494,20 @@ void wine_dll_set_callback( load_dll_callback_t load )
}
#ifdef __ASM_OBSOLETE
/***********************************************************************
* wine_dll_enum_load_path
*
* Enumerate the dll load path.
*/
const char *wine_dll_enum_load_path( unsigned int index )
const char *wine_dll_enum_load_path_obsolete( unsigned int index )
{
if (index >= nb_dll_paths) return NULL;
return dll_paths[index];
}
#ifdef __ASM_OBSOLETE
/*
* These functions provide wrappers around dlopen() and associated
* functions. They work around a bug in glibc 2.1.x where calling
@ -789,6 +789,7 @@ int wine_dll_get_owner_obsolete( const char *name, char *buffer, int size, int *
__ASM_OBSOLETE(wine_dlopen);
__ASM_OBSOLETE(wine_dlsym);
__ASM_OBSOLETE(wine_dlclose);
__ASM_OBSOLETE(wine_dll_enum_load_path);
__ASM_OBSOLETE(wine_dll_get_owner);
__ASM_OBSOLETE(wine_dll_load);
__ASM_OBSOLETE(wine_dll_load_main_exe);

View File

@ -9,15 +9,9 @@ WINE_1.0
wine_anon_mmap;
wine_casemap_lower;
wine_casemap_upper;
wine_dll_enum_load_path;
wine_dll_set_callback;
wine_exec_wine_binary;
wine_get_build_dir;
wine_get_build_id;
wine_get_config_dir;
wine_get_data_dir;
wine_get_server_dir;
wine_get_user_name;
wine_get_version;
wine_init;
wine_init_argv0_path;
@ -86,6 +80,7 @@ WINE_1.0
wine_dbgstr_an;
wine_dbgstr_wn;
wine_dlclose;
wine_dll_enum_load_path;
wine_dll_get_owner;
wine_dll_load;
wine_dll_load_main_exe;
@ -93,13 +88,18 @@ WINE_1.0
wine_dlopen;
wine_dlsym;
wine_fold_string;
wine_get_build_dir;
wine_get_config_dir;
wine_get_cs;
wine_get_data_dir;
wine_get_ds;
wine_get_es;
wine_get_fs;
wine_get_gs;
wine_get_server_dir;
wine_get_sortkey;
wine_get_ss;
wine_get_user_name;
wine_is_dbcs_leadbyte;
wine_ldt_alloc_entries;
wine_ldt_alloc_fs;