aboutsummaryrefslogtreecommitdiffstats
path: root/lib/erl_interface
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-08-30 16:31:53 +0200
committerSverker Eriksson <[email protected]>2016-08-30 16:31:53 +0200
commit9f794b187208729728a3e5c11ed2e8f959174a5c (patch)
tree9beb8d7de2a96b540f7402e65faa7ae5a91e4c9d /lib/erl_interface
parent925984e94f2c1933bb659dfb626c191982b7c8d4 (diff)
parentdde235711d95ee9949d1df4a5f6c142493ee3a55 (diff)
downloadotp-9f794b187208729728a3e5c11ed2e8f959174a5c.tar.gz
otp-9f794b187208729728a3e5c11ed2e8f959174a5c.tar.bz2
otp-9f794b187208729728a3e5c11ed2e8f959174a5c.zip
Merge branch 'sverker/erl_interface-win-home/OTP-13849' into maint
* sverker/erl_interface-win-home: erl_interface: Look for .erlang.cookie in windows directory erl_interface: Refactor get_home()
Diffstat (limited to 'lib/erl_interface')
-rw-r--r--lib/erl_interface/src/connect/ei_connect.c40
1 files changed, 24 insertions, 16 deletions
diff --git a/lib/erl_interface/src/connect/ei_connect.c b/lib/erl_interface/src/connect/ei_connect.c
index 6dc51adee1..624100ad49 100644
--- a/lib/erl_interface/src/connect/ei_connect.c
+++ b/lib/erl_interface/src/connect/ei_connect.c
@@ -1708,28 +1708,36 @@ 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 {
+ int len = GetWindowsDirectory(buf, size);
+ if (len) {
+ return (len < size);
+ }
+ }
+#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;
}