MINGW-packages/mingw-w64-gdb/0005-W32-Always-check-USERPROFILE-if-HOME-is-not-set.patch
2021-10-25 10:14:49 +03:00

112 lines
3.6 KiB
Diff

From 117c802d2e17efa95a366ed4b0e3681019a2bbb8 Mon Sep 17 00:00:00 2001
From: Buster <rcopley@gmail.com>
Date: Sat, 26 Oct 2019 12:15:37 +0100
Subject: [PATCH 5/5] W32: Always check $USERPROFILE if $HOME is not set
---
gdb/auto-load.c | 4 ++++
gdb/windows-nat.c | 4 ++++
gdbsupport/pathstuff.cc | 12 ++++++++++++
gnulib/import/glob.c | 18 +-----------------
4 files changed, 21 insertions(+), 17 deletions(-)
diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 9cd70f174c3..ea667144366 100644
--- a/gdb/auto-load.c
+++ b/gdb/auto-load.c
@@ -477,6 +477,10 @@ file_is_auto_load_safe (const char *filename)
else
{
const char *homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == NULL)
+ homedir = getenv ("USERPROFILE");
+#endif
if (homedir == nullptr)
homedir = "$HOME";
home_config = (std::string (homedir) + SLASH_STRING
diff --git a/gdb/windows-nat.c b/gdb/windows-nat.c
index 05d95ea7d6a..947d172be4d 100644
--- a/gdb/windows-nat.c
+++ b/gdb/windows-nat.c
@@ -3273,6 +3273,10 @@ _initialize_check_for_gdb_ini ()
return;
homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == NULL)
+ homedir = getenv ("USERPROFILE");
+#endif
if (homedir)
{
char *p;
diff --git a/gdbsupport/pathstuff.cc b/gdbsupport/pathstuff.cc
index ad13900819e..e43cdc21dc1 100644
--- a/gdbsupport/pathstuff.cc
+++ b/gdbsupport/pathstuff.cc
@@ -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 && home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
@@ -298,6 +302,10 @@ get_standard_config_dir ()
#endif
const char *home = getenv ("HOME");
+#ifdef _WIN32
+ if (home == NULL)
+ home = getenv ("USERPROFILE");
+#endif
if (home != NULL && home[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
@@ -340,6 +348,10 @@ find_gdb_home_config_file (const char *name, struct stat *buf)
}
const char *homedir = getenv ("HOME");
+#ifdef _WIN32
+ if (homedir == nullptr)
+ homedir = getenv ("USERPROFILE");
+#endif
if (homedir != nullptr && homedir[0] != '\0')
{
/* Make sure the path is absolute and tilde-expanded. */
diff --git a/gnulib/import/glob.c b/gnulib/import/glob.c
index 1bfcafb7b36..25eda3e6a8e 100644
--- a/gnulib/import/glob.c
+++ b/gnulib/import/glob.c
@@ -620,23 +620,7 @@ __glob (const char *pattern, int flags, int (*errfunc) (const char *, int),
if (home_dir == NULL || home_dir[0] == '\0')
{
#ifdef WINDOWS32
- /* Windows NT defines HOMEDRIVE and HOMEPATH. But give
- preference to HOME, because the user can change HOME. */
- 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 */
+ home_dir = getenv ("USERPROFILE");
#else
int err;
struct passwd *p;
--
2.33.1.windows.1