From: Stepan Kasal Date: Thu, 05 Jun 2014 10:23:46 GMT Subject: [PATCH v3] Add a Windows-specific fallback to getenv("HOME"); Message-ID: <20140605102346.GA28309@camelia.ucw.cz> In-Reply-To: <53902B2C.7050807@web.de> From: Johannes Schindelin Date: Wed, 2 Jun 2010 00:41:33 +0200 If HOME is not set, use $HOMEDRIVE$HOMEPATH Signed-off-by: Johannes Schindelin Signed-off-by: Stepan Kasal --- On Thu, Jun 05, 2014 at 10:32:44AM +0200, Torsten Bögershausen wrote: > > + strbuf_addf(&buf, "%s%s", getenv_cs("HOMEDRIVE"), getenv_cs("HOMEPATH")); > should we have a NULL pointer check here? You are right, of course. > If HOMEDRIVE is set, but not HOMEPATH, we can fall back into the root of HOMEDRIVE: Indeed, but it means setting homepath="\\"; Updated according to your comments. Thanks, Stepan compat/mingw.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/compat/mingw.c b/compat/mingw.c index a0e13bc..14af013 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -1181,6 +1181,17 @@ char *mingw_getenv(const char *name) if (!result) result = getenv_cs("TEMP"); } + if (!result && !strcmp(name, "HOME")) { + const char *homedrive = getenv_cs("HOMEDRIVE"); + const char *homepath = getenv_cs("HOMEPATH"); + if (homedrive) { + struct strbuf buf = STRBUF_INIT; + if (!homepath) + homepath = "\\"; + strbuf_addf(&buf, "%s%s", homedrive, homepath); + result = strbuf_detach(&buf, NULL); + } + } return result; } -- 2.0.0.9635.g0be03cb -- -- *** Please reply-to-all at all times *** *** (do not pretend to know who is subscribed and who is not) *** *** Please avoid top-posting. *** The msysGit Wiki is here: https://github.com/msysgit/msysgit/wiki - Github accounts are free. You received this message because you are subscribed to the Google Groups "msysGit" group. To post to this group, send email to msysgit@googlegroups.com To unsubscribe from this group, send email to msysgit+unsubscribe@googlegroups.com For more options, and view previous threads, visit this group at http://groups.google.com/group/msysgit?hl=en_US?hl=en --- You received this message because you are subscribed to the Google Groups "msysGit" group. To unsubscribe from this group and stop receiving emails from it, send an email to msysgit+unsubscribe@googlegroups.com. For more options, visit https://groups.google.com/d/optout.