From 093062c4c5b6a9374070f6a0f2c97dcdfcbc3d53 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 21 Jun 2016 18:12:42 +0200 Subject: erl_interface: Refactor get_home() by separating WIN32 and other implementation more. --- lib/erl_interface/src/connect/ei_connect.c | 34 ++++++++++++++++-------------- 1 file changed, 18 insertions(+), 16 deletions(-) (limited to 'lib/erl_interface/src/connect') diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c index 6dc51adee1..36fe65e607 100644 --- a/lib/erl_interface/src/connect/ei_connect.c +++ b/lib/erl_interface/src/connect/ei_connect.c @@ -1708,28 +1708,30 @@ error: static int get_home(char *buf, int size) { - char* homedrive; - char* homepath; - #ifdef __WIN32__ - homedrive = getenv("HOMEDRIVE"); - homepath = getenv("HOMEPATH"); -#else - homedrive = ""; - homepath = getenv("HOME"); -#endif + char* homedrive = getenv("HOMEDRIVE"); + char* homepath = getenv("HOMEPATH"); - if (!homedrive || !homepath) { - buf[0] = '.'; - buf[1] = '\0'; - return 1; - } else if (strlen(homedrive)+strlen(homepath) < size-1) { + if (homedrive && homepath) { + if (strlen(homedrive)+strlen(homepath) >= size) + return 0; strcpy(buf, homedrive); strcat(buf, homepath); return 1; } - - return 0; +#else + char* homepath = getenv("HOME"); + if (homepath) { + if (strlen(homepath) >= size) + return 0; + strcpy(buf, homepath); + return 1; + } +#endif + + buf[0] = '.'; + buf[1] = '\0'; + return 1; } -- cgit v1.2.3 From dde235711d95ee9949d1df4a5f6c142493ee3a55 Mon Sep 17 00:00:00 2001 From: Sverker Eriksson Date: Tue, 21 Jun 2016 18:32:16 +0200 Subject: erl_interface: Look for .erlang.cookie in windows directory the same as erlexec do to set -home command argument which is used to look for .erlang.cookie. --- lib/erl_interface/src/connect/ei_connect.c | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'lib/erl_interface/src/connect') diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c index 36fe65e607..624100ad49 100644 --- a/lib/erl_interface/src/connect/ei_connect.c +++ b/lib/erl_interface/src/connect/ei_connect.c @@ -1719,6 +1719,12 @@ static int get_home(char *buf, int size) strcat(buf, homepath); return 1; } + else { + int len = GetWindowsDirectory(buf, size); + if (len) { + return (len < size); + } + } #else char* homepath = getenv("HOME"); if (homepath) { -- cgit v1.2.3