public inbox for gdb-patches@sourceware.org
 help / color / mirror / Atom feed
* [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
@ 2020-06-02  3:49 Stephanos Ioannidis
  2020-06-02 15:15 ` Eli Zaretskii
  2020-06-02 17:49 ` Christian Biesinger
  0 siblings, 2 replies; 6+ messages in thread
From: Stephanos Ioannidis @ 2020-06-02  3:49 UTC (permalink / raw)
  To: gdb-patches; +Cc: Stephanos Ioannidis

`HOME` is not a default valid environment variable on Windows.

`USERPROFILE` environment variable should be used to resolve the user
home directory path.

Signed-off-by: Stephanos Ioannidis <root@stephanos.io>
---
 gdb/auto-load.c            |  4 ++++
 gdb/gdbsupport/pathstuff.c |  4 ++++
 gdb/main.c                 |  4 ++++
 gdb/windows-nat.c          |  4 ++++
 gnulib/import/glob.c       | 22 ++--------------------
 5 files changed, 18 insertions(+), 20 deletions(-)

diff --git a/gdb/auto-load.c b/gdb/auto-load.c
index 5a9f47f078..7f88967b82 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..eea1189e05 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.  */
+#  ifdef _WIN32
           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 */
-            }
+            home_dir = getenv ("USERPROFILE");
 #  else
           if (home_dir == NULL || home_dir[0] == '\0')
             {
-- 
2.26.2


^ permalink raw reply	[flat|nested] 6+ messages in thread

end of thread, other threads:[~2020-06-15 14:04 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-06-02  3:49 [PATCH] Use USERPROFILE environment variable to resolve home path on Windows Stephanos Ioannidis
2020-06-02 15:15 ` Eli Zaretskii
2020-06-02 15:49   ` Stephanos Ioannidis
2020-06-02 16:20     ` Eli Zaretskii
2020-06-02 17:49 ` Christian Biesinger
2020-06-15 14:04   ` Tom Tromey

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).