From: Twig6943 <119701717+Twig6943@users.noreply.github.com> --- dlls/mountmgr.sys/unixlib.c | 21 +++++++++++++++++++-- dlls/ntdll/unix/loader.c | 13 ++++++++++++- server/request.c | 26 ++++++++++++++++++++++---- 3 files changed, 53 insertions(+), 7 deletions(-) diff --git a/dlls/mountmgr.sys/unixlib.c b/dlls/mountmgr.sys/unixlib.c index f84027f36ef..e1b10169c92 100644 --- a/dlls/mountmgr.sys/unixlib.c +++ b/dlls/mountmgr.sys/unixlib.c @@ -99,8 +99,25 @@ static char *get_dosdevices_path( const char *dev ) if (prefix) asprintf( &path, "%s/dosdevices/%s", prefix, dev ); else - asprintf( &path, "%s/.local/share/wine/dosdevices/%s", getenv( "HOME" ), dev ); - + { + const char *xdg_data_home = getenv( "XDG_DATA_HOME" ); + const char *home = getenv( "HOME" ); + char *data_home; + struct stat st; + if (xdg_data_home && xdg_data_home[0] == '/') + { + if (!(data_home = strdup( xdg_data_home ))) return NULL; + } + else + { + if (!home || asprintf( &data_home, "%s/.local/share", home ) == -1) return NULL; + } + if (stat( data_home, &st ) == 0 && S_ISDIR(st.st_mode)) + asprintf( &path, "%s/wine/dosdevices/%s", data_home, dev ); + else if (home) + asprintf( &path, "%s/.wine/dosdevices/%s", home, dev ); + free( data_home ); + } return path; } diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c index 914eb9a0116..1b9d1522537 100644 --- a/dlls/ntdll/unix/loader.c +++ b/dlls/ntdll/unix/loader.c @@ -376,9 +376,20 @@ static void set_config_dir(void) } else { + const char *xdg_data_home = getenv( "XDG_DATA_HOME" ); + char *data_home; + struct stat st; if (!home_dir) fatal_error( "could not determine your home directory\n" ); if (home_dir[0] != '/') fatal_error( "the home directory %s is not an absolute path\n", home_dir ); - config_dir = build_path( home_dir, ".local/share/wine" ); + if (xdg_data_home && xdg_data_home[0] == '/') + data_home = strdup( xdg_data_home ); + else + data_home = build_path( home_dir, ".local/share" ); + if (stat( data_home, &st ) == 0 && S_ISDIR(st.st_mode)) + config_dir = build_path( data_home, "wine" ); + else + config_dir = build_path( home_dir, ".wine" ); + free( data_home ); } } diff --git a/server/request.c b/server/request.c index 18031abcaa1..7d2eae5bec5 100644 --- a/server/request.c +++ b/server/request.c @@ -612,6 +612,8 @@ static char *create_server_dir( int force ) else { const char *home = getenv( "HOME" ); + const char *xdg_data_home = getenv( "XDG_DATA_HOME" ); + char *data_home; if (!home) { struct passwd *pwd = getpwuid( getuid() ); @@ -619,10 +621,26 @@ static char *create_server_dir( int force ) } 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 ); - if (!(config_dir = malloc( strlen(home) + sizeof("/.local/share/wine") ))) fatal_error( "out of memory\n" ); - strcpy( config_dir, home ); - for (p = config_dir + strlen(config_dir); p > config_dir; p--) if (p[-1] != '/') break; - strcpy( p, "/.local/share/wine" ); + if (xdg_data_home && xdg_data_home[0] == '/') + { + if (!(data_home = strdup( xdg_data_home ))) fatal_error( "out of memory\n" ); + } + else + { + if (asprintf( &data_home, "%s/.local/share", home ) == -1) fatal_error( "out of memory\n" ); + } + if (stat( data_home, &st ) == 0 && S_ISDIR(st.st_mode)) + { + if (asprintf( &config_dir, "%s/wine", data_home ) == -1) fatal_error( "out of memory\n" ); + } + else + { + if (!(config_dir = malloc( strlen(home) + sizeof("/.wine") ))) fatal_error( "out of memory\n" ); + strcpy( config_dir, home ); + for (p = config_dir + strlen(config_dir); p > config_dir; p--) if (p[-1] != '/') break; + strcpy( p, "/.wine" ); + } + free( data_home ); } if (chdir( config_dir ) == -1) -- GitLab https://gitlab.winehq.org/wine/wine/-/merge_requests/10543