blob: ff1af19c74f173fd62042a7d2311647522bbb046 [file] [log] [blame]
From e7cfeb6cd5d53a8708455680c13fd4c5f61bc78e Mon Sep 17 00:00:00 2001
From: Buster <rcopley@gmail.com>
Date: Sat, 26 Oct 2019 12:15:37 +0100
Subject: [PATCH] W32: Always check $USERPROFILE if $HOME is not set
---
gdb/auto-load.c | 4 ++++
gdb/gdbsupport/pathstuff.c | 4 ++++
gdb/main.c | 4 ++++
gdb/windows-nat.c | 4 ++++
gnulib/import/glob.c | 24 +++---------------------
5 files changed, 19 insertions(+), 21 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 5a9f47f078..8575ea1ecf 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -499,6 +499,10 @@ file_is_auto_load_safe (const char *filename, const char *debug_fmt, ...)
if (!advice_printed)
{
const char *homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == NULL)
+ homedir = getenv ("USERPROFILE");
+#endif
if (homedir == NULL)
homedir = "$HOME";
diff --git a/gdb/gdbsupport/pathstuff.c b/gdb/gdbsupport/pathstuff.c
index f9882a2635..a90587103c 100644
--- a/gdb/gdbsupport/pathstuff.c
+++ b/gdb/gdbsupport/pathstuff.c
@@ -231,6 +231,10 @@ get_standard_cache_dir ()
#endif
const char *home = getenv ("HOME");
+#ifdef _WIN32
+ if (home == NULL)
+ home = getenv ("USERPROFILE");
+#endif
if (home != NULL)
{
/* Make sure the path is absolute and tilde-expanded. */
diff --git a/gdb/main.c b/gdb/main.c
index 66a9e6a6d2..2a7228f20c 100644
--- a/gdb/main.c
+++ b/gdb/main.c
@@ -300,6 +300,10 @@ get_init_files (std::vector<std::string> *system_gdbinit,
}
const char *homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == NULL)
+ homedir = getenv ("USERPROFILE");
+#endif
/* If the .gdbinit file in the current directory is the same as
the $HOME/.gdbinit file, it should not be sourced. homebuf
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 31a5cabfb3..e60298ff60 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -3201,6 +3201,10 @@ _initialize_check_for_gdb_ini (void)
return;
homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == NULL)
+ homedir = getenv ("USERPROFILE");
+#endif
if (homedir)
{
char *p;
diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c
index 416d210b63..77888277db 100644
--- a/gnulib/import/glob.c
+++ b/gnulib/import/glob.c
@@ -663,27 +663,9 @@ glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
if (home_dir == NULL || home_dir[0] == '\0')
home_dir = "SYS:";
# else
-# ifdef WINDOWS32
- /* Windows NT defines HOMEDRIVE and HOMEPATH. But give preference
- to HOME, because the user can change HOME. */
- if (home_dir == NULL || home_dir[0] == '\0')
- {
- const char *home_drive = getenv ("HOMEDRIVE");
- const char *home_path = getenv ("HOMEPATH");
-
- if (home_drive != NULL && home_path != NULL)
- {
- size_t home_drive_len = strlen (home_drive);
- size_t home_path_len = strlen (home_path);
- char *mem = alloca (home_drive_len + home_path_len + 1);
-
- memcpy (mem, home_drive, home_drive_len);
- memcpy (mem + home_drive_len, home_path, home_path_len + 1);
- home_dir = mem;
- }
- else
- home_dir = "c:/users/default"; /* poor default */
- }
+# ifdef _WIN32
+ if (home_dir== NULL || home_dir[0] == '\0')
+ home_dir = getenv ("USERPROFILE");
# else
if (home_dir == NULL || home_dir[0] == '\0')
{
--
2.25.0.windows.1