aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSverker Eriksson <[email protected]>2016-06-21 18:12:42 +0200
committerSverker Eriksson <[email protected]>2016-06-21 18:12:42 +0200
commit093062c4c5b6a9374070f6a0f2c97dcdfcbc3d53 (patch)
tree1d6520bae10197ced505fa50f4f56558ef3e8d13
parent3f64be5c822e1ee4d1dc2a4289e4906d789c64ac (diff)
downloadotp-093062c4c5b6a9374070f6a0f2c97dcdfcbc3d53.tar.gz
otp-093062c4c5b6a9374070f6a0f2c97dcdfcbc3d53.tar.bz2
otp-093062c4c5b6a9374070f6a0f2c97dcdfcbc3d53.zip
erl_interface: Refactor get_home()
by separating WIN32 and other implementation more.
-rw-r--r--lib/erl_interface/src/connect/ei_connect.c34
1 files changed, 18 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..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;
}