* [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
* Re: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
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 17:49 ` Christian Biesinger
1 sibling, 1 reply; 6+ messages in thread
From: Eli Zaretskii @ 2020-06-02 15:15 UTC (permalink / raw)
To: Stephanos Ioannidis; +Cc: gdb-patches
> From: Stephanos Ioannidis <root@stephanos.io>
> Date: Tue, 2 Jun 2020 12:49:42 +0900
> Cc: Stephanos Ioannidis <root@stephanos.io>
>
> `HOME` is not a default valid environment variable on Windows.
>
> `USERPROFILE` environment variable should be used to resolve the user
> home directory path.
AFAIU, putting files in USERPROFILE is against MS platform
recommendations. See
https://docs.microsoft.com/en-us/windows/win32/shell/csidl
Under CSIDL_PROFILE, it says:
Applications should not create files or folders at this level; they
should put their data under the locations referred to by
CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* RE: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
2020-06-02 15:15 ` Eli Zaretskii
@ 2020-06-02 15:49 ` Stephanos Ioannidis
2020-06-02 16:20 ` Eli Zaretskii
0 siblings, 1 reply; 6+ messages in thread
From: Stephanos Ioannidis @ 2020-06-02 15:49 UTC (permalink / raw)
To: Eli Zaretskii; +Cc: gdb-patches
Thanks for the feedback.
> AFAIU, putting files in USERPROFILE is against MS platform recommendations.
From what I can see, I do not think that is necessarily the case.
%USERPROFILE% points to the user-specific home directory on Windows (i.e. $HOME equivalent), which is one of the following:
* Windows XP or earlier: C:\Documents and Settings\username
* Windows Vista and later: C:\Users\username
Many modern Windows programs, including the ones from Microsoft, make use of %USERPROFILE% as the place to store various user-specific data; for example, the following is what I have under %USERPROFILE% on my Windows machine:
====
C:\Users\assem>dir .*
Volume in drive C is Windows
Volume Serial Number is 6A91-6C3C
Directory of C:\Users\assem
05/24/2020 09:29 PM <DIR> .
05/24/2020 09:29 PM <DIR> ..
12/25/2019 11:51 AM <DIR> .android
06/23/2019 02:36 AM <DIR> .AndroidStudio3.4
05/30/2020 03:05 PM 2,570 .bash_history
09/29/2019 12:21 AM <DIR> .cache
01/01/2020 12:17 PM <DIR> .dotnet
09/20/2019 02:05 PM <DIR> .eclipse
09/16/2019 08:44 PM <DIR> .ghidra
05/23/2020 04:26 PM 145 .gitconfig
11/19/2019 09:45 AM <DIR> .gradle
11/19/2019 09:45 AM <DIR> .idea
08/27/2019 07:58 PM <DIR> .jssc
11/24/2019 12:07 AM <DIR> .mcc
11/23/2019 11:57 PM <DIR> .mchp_packs
06/22/2019 03:13 PM <DIR> .mplabcomm
06/17/2019 08:09 PM <DIR> .nuget
06/17/2019 05:06 PM <DIR> .oracle_jre_usage
09/20/2019 02:05 PM <DIR> .p2
10/06/2019 02:55 PM <DIR> .ssh
12/09/2019 12:47 AM <DIR> .templateengine
05/24/2020 09:29 PM 17,012 .viminfo
06/17/2019 02:47 PM <DIR> .vscode
3 File(s) 19,727 bytes
20 Dir(s) 523,199,340,544 bytes free
====
In fact, I can see that gnulib itself already uses %HOMEDRIVE%%HOMEPATH (identical to %USERPROFILE%) in place of $HOME for Windows.
-----Original Message-----
From: Eli Zaretskii <eliz@gnu.org>
Sent: Wednesday, June 3, 2020 12:15 AM
To: Stephanos Ioannidis <root@stephanos.io>
Cc: gdb-patches@sourceware.org
Subject: Re: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
> From: Stephanos Ioannidis <root@stephanos.io>
> Date: Tue, 2 Jun 2020 12:49:42 +0900
> Cc: Stephanos Ioannidis <root@stephanos.io>
>
> `HOME` is not a default valid environment variable on Windows.
>
> `USERPROFILE` environment variable should be used to resolve the user
> home directory path.
AFAIU, putting files in USERPROFILE is against MS platform recommendations. See
https://docs.microsoft.com/en-us/windows/win32/shell/csidl
Under CSIDL_PROFILE, it says:
Applications should not create files or folders at this level; they
should put their data under the locations referred to by
CSIDL_APPDATA or CSIDL_LOCAL_APPDATA.
Thanks.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
2020-06-02 15:49 ` Stephanos Ioannidis
@ 2020-06-02 16:20 ` Eli Zaretskii
0 siblings, 0 replies; 6+ messages in thread
From: Eli Zaretskii @ 2020-06-02 16:20 UTC (permalink / raw)
To: Stephanos Ioannidis; +Cc: gdb-patches
> From: Stephanos Ioannidis <root@stephanos.io>
> CC: "gdb-patches@sourceware.org" <gdb-patches@sourceware.org>
> Date: Tue, 2 Jun 2020 15:49:03 +0000
>
> > AFAIU, putting files in USERPROFILE is against MS platform recommendations.
>
> >From what I can see, I do not think that is necessarily the case.
>
> %USERPROFILE% points to the user-specific home directory on Windows (i.e. $HOME equivalent), which is one of the following:
>
> * Windows XP or earlier: C:\Documents and Settings\username
> * Windows Vista and later: C:\Users\username
>
> Many modern Windows programs, including the ones from Microsoft, make use of %USERPROFILE% as the place to store various user-specific data; for example, the following is what I have under %USERPROFILE% on my Windows machine:
The fact that many programs violate these recommendations doesn't yet
mean those recommendations are null and void, nor that GDB should join
the club. Emacs, for example, didn't join that club.
Anyway, that's my opinion; if others don't mind putting our files
directly under USERPROFILE, they can override me.
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
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 17:49 ` Christian Biesinger
2020-06-15 14:04 ` Tom Tromey
1 sibling, 1 reply; 6+ messages in thread
From: Christian Biesinger @ 2020-06-02 17:49 UTC (permalink / raw)
To: Stephanos Ioannidis; +Cc: gdb-patches
On Mon, Jun 1, 2020 at 10:50 PM Stephanos Ioannidis <root@stephanos.io> wrote:
> --- 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
You're adding this in a lot of places; probably better to add a helper
function in gdbsupport to return the home/userprofile directory?
> 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
Gnulib is maintained elsewhere, please send patches to
bug-gnulib@gnu.org. If the change is also needed in GDB, it is best to
wait for Gnulib to add the patch and then use gnulib/update-gnulib.sh.
Though it's also possible to add a local patch.
Christian
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] Use USERPROFILE environment variable to resolve home path on Windows
2020-06-02 17:49 ` Christian Biesinger
@ 2020-06-15 14:04 ` Tom Tromey
0 siblings, 0 replies; 6+ messages in thread
From: Tom Tromey @ 2020-06-15 14:04 UTC (permalink / raw)
To: Christian Biesinger via Gdb-patches
Cc: Stephanos Ioannidis, Christian Biesinger
>>>>> "Christian" == Christian Biesinger via Gdb-patches <gdb-patches@sourceware.org> writes:
Christian> On Mon, Jun 1, 2020 at 10:50 PM Stephanos Ioannidis <root@stephanos.io> wrote:
>> --- 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
Christian> You're adding this in a lot of places; probably better to add a helper
Christian> function in gdbsupport to return the home/userprofile directory?
Agreed; there's also a use of $HOME in gdbsupport, so presumably this
would have to be fixed as well anyway.
Tom
^ 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).