git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [msysGit] [PATCH v2] Add a Windows-specific fallback to getenv("HOME");

From
Torsten Bögershausen <tboegi@web.de>
Date
Jun 5, 2014, 08:32 UTC
Message-ID
<53902B2C.7050807@web.de>
In-Reply-To
<20140605080317.GA28029@camelia.ucw.cz>
On 2014-06-05 10.03, Stepan Kasal wrote:
Show 33 quoted lines
> From: Johannes Schindelin <johannes.schindelin@gmx.de>
> Date: Wed, 2 Jun 2010 00:41:33 +0200
> 
> If HOME is not set, use $HOMEDRIVE$HOMEPATH
> 
> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de>
> Signed-off-by: Stepan Kasal <kasal@ucw.cz>
> ---
> 
> Hello Karsten,
> thanks for your explanation.  There are more things to be done, but
> I hope you can ack this patch as a step forward.
> 
> Hello Dscho,
> I hope you can ack this as well: it is basically equivalent with your
> patch, tailored according to current upstream fashion,  ;-)
> 
> Stepan
> 
>  compat/mingw.c | 5 +++++
>  1 file changed, 5 insertions(+)
> 
> diff --git a/compat/mingw.c b/compat/mingw.c
> index a0e13bc..e108388 100644
> --- a/compat/mingw.c
> +++ b/compat/mingw.c
> @@ -1181,6 +1181,11 @@ char *mingw_getenv(const char *name)
>  		if (!result)
>  			result = getenv_cs("TEMP");
>  	}
> +	if (!result && !strcmp(name, "HOME")) {
> +		struct strbuf buf = STRBUF_INIT;
> +		strbuf_addf(&buf, "%s%s", getenv_cs("HOMEDRIVE"), getenv_cs("HOMEPATH"));

should we have a NULL pointer check here? What happens if %HOMEPATH% is not set for any reason ? getenv_cs will return NULL, and strbuf_addf() does not like that, as far as I know. And even if it converts a NULL pointer into "<NULL>" or "NULL", the result is not what we want. If HOMEDRIVE is set, but not HOMEPATH, we can fall back into the root of HOMEDRIVE:

	if (!result && !strcmp(name, "HOME")) {
		const char *homedrive = getenv_cs("HOMEDRIVE");
		const char *homepath = getenv_cs("HOMEPATH");
		if (!homepath)
			homepath = "";
        	if (homedrive) {
			struct strbuf buf = STRBUF_INIT;
			strbuf_addf(&buf, "%s%s", homedrive, homepath);
			result = strbuf_detach(&buf, NULL);
		}
	}
	return result;
}  
 
Previous: Stepan KasalNext: Stepan Kasal
Message 18 of 31 in “Add a Windows-specific fallback to getenv("HOME");”
  1. Add a Windows-specific fallback to getenv("HOME");Stepan Kasal, Jun 4, 2014
  2. Duy NguyenJun 4, 2014
  3. Erik Faye-LundJun 4, 2014
  4. Karsten BleesJun 4, 2014
  5. Johannes SchindelinJun 4, 2014
  6. Erik Faye-LundJun 4, 2014
  7. Johannes SchindelinJun 4, 2014
  8. Stepan KasalJun 4, 2014
  9. Johannes SchindelinJun 4, 2014
  10. Stepan KasalJun 4, 2014
  11. Johannes SchindelinJun 4, 2014
  12. Git for Windows SDKPhilip Oakley, Jun 6, 2014
  13. Duy NguyenJun 4, 2014
  14. Sebastian SchuberthJun 6, 2014
  15. Johannes SchindelinJun 4, 2014
  16. Karsten BleesJun 5, 2014
  17. Add a Windows-specific fallback to getenv("HOME");Stepan Kasal, Jun 5, 2014
  18. Torsten BögershausenJun 5, 2014
  19. Add a Windows-specific fallback to getenv("HOME");Stepan Kasal, Jun 5, 2014
  20. Karsten BleesJun 5, 2014
  21. Erik Faye-LundJun 5, 2014
  22. Karsten BleesJun 5, 2014
  23. Stepan KasalJun 6, 2014
  24. Stepan KasalJun 5, 2014
  25. Johannes SchindelinJun 5, 2014
  26. Karsten BleesJun 5, 2014
  27. Johannes SchindelinJun 5, 2014
  28. Stepan KasalJun 5, 2014
  29. Karsten BleesJun 5, 2014
  30. Stepan KasalJun 4, 2014
  31. Johannes SchindelinJun 4, 2014

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.