Alexandre Julliard : ntdll: Store home directory and username at init time in the Unix library.
Alexandre Julliard
julliard at winehq.org
Wed Jun 24 15:47:34 CDT 2020
Module: wine
Branch: master
Commit: 36e55720b66743d161330183693949e4f8503cc7
URL: https://source.winehq.org/git/wine.git/?a=commit;h=36e55720b66743d161330183693949e4f8503cc7
Author: Alexandre Julliard <julliard at winehq.org>
Date: Wed Jun 24 09:20:33 2020 +0200
ntdll: Store home directory and username at init time in the Unix library.
Signed-off-by: Alexandre Julliard <julliard at winehq.org>
---
dlls/ntdll/unix/loader.c | 38 +++++++++++++++++++++++++++++---------
dlls/ntdll/unix/unix_private.h | 2 ++
2 files changed, 31 insertions(+), 9 deletions(-)
diff --git a/dlls/ntdll/unix/loader.c b/dlls/ntdll/unix/loader.c
index 73c24eff54..1045870f9b 100644
--- a/dlls/ntdll/unix/loader.c
+++ b/dlls/ntdll/unix/loader.c
@@ -123,9 +123,11 @@ static const char *dll_dir;
static const char **dll_paths;
static SIZE_T dll_path_maxlen;
+const char *home_dir = NULL;
const char *data_dir = NULL;
const char *build_dir = NULL;
const char *config_dir = NULL;
+const char *user_name = NULL;
HMODULE ntdll_module = NULL;
struct file_id
@@ -285,6 +287,29 @@ static void set_dll_path(void)
}
+static void set_home_dir(void)
+{
+ const char *home = getenv( "HOME" );
+ const char *name = getenv( "USER" );
+ const char *p;
+
+ if (!home || !name)
+ {
+ struct passwd *pwd = getpwuid( getuid() );
+ if (pwd)
+ {
+ if (!home) home = pwd->pw_dir;
+ if (!name) name = pwd->pw_name;
+ }
+ if (!name) name = "wine";
+ }
+ if ((p = strrchr( name, '/' ))) name = p + 1;
+ if ((p = strrchr( name, '\\' ))) name = p + 1;
+ home_dir = strdup( home );
+ user_name = strdup( name );
+}
+
+
static void set_config_dir(void)
{
char *p, *dir;
@@ -299,15 +324,9 @@ static void set_config_dir(void)
}
else
{
- const char *home = getenv( "HOME" );
- if (!home)
- {
- struct passwd *pwd = getpwuid( getuid() );
- if (pwd) home = pwd->pw_dir;
- }
- 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 = build_path( home, ".wine" );
+ 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, ".wine" );
}
}
@@ -334,6 +353,7 @@ static void init_paths( int argc, char *argv[], char *envp[] )
}
set_dll_path();
+ set_home_dir();
set_config_dir();
}
diff --git a/dlls/ntdll/unix/unix_private.h b/dlls/ntdll/unix/unix_private.h
index 7dbfde43b3..7942aaf62e 100644
--- a/dlls/ntdll/unix/unix_private.h
+++ b/dlls/ntdll/unix/unix_private.h
@@ -124,9 +124,11 @@ extern NTSTATUS CDECL nt_to_unix_file_name( const UNICODE_STRING *nameW, ANSI_ST
extern NTSTATUS CDECL unix_to_nt_file_name( const ANSI_STRING *name, UNICODE_STRING *nt ) DECLSPEC_HIDDEN;
extern void CDECL set_show_dot_files( BOOL enable ) DECLSPEC_HIDDEN;
+extern const char *home_dir DECLSPEC_HIDDEN;
extern const char *data_dir DECLSPEC_HIDDEN;
extern const char *build_dir DECLSPEC_HIDDEN;
extern const char *config_dir DECLSPEC_HIDDEN;
+extern const char *user_name DECLSPEC_HIDDEN;
extern HMODULE ntdll_module DECLSPEC_HIDDEN;
extern USHORT *uctable DECLSPEC_HIDDEN;
extern USHORT *lctable DECLSPEC_HIDDEN;
More information about the wine-cvs
mailing list