diff options
author | Dan Gudmundsson <[email protected]> | 2017-04-28 11:48:14 +0200 |
---|---|---|
committer | Dan Gudmundsson <[email protected]> | 2017-04-28 11:48:14 +0200 |
commit | 86f6a985670008690695b304c6606b054d2f27c3 (patch) | |
tree | e491e1714101417aa8a315156209b321d5f64444 /erts/etc/common/escript.c | |
parent | 9fad2fdd57fafca649a358e9d6b62c061fe6cf27 (diff) | |
parent | fab97e165a79db10b7b560be5aefc7489982bced (diff) | |
download | otp-86f6a985670008690695b304c6606b054d2f27c3.tar.gz otp-86f6a985670008690695b304c6606b054d2f27c3.tar.bz2 otp-86f6a985670008690695b304c6606b054d2f27c3.zip |
Merge branch 'dgud/erts/erlscript_name'
* dgud/erts/erlscript_name:
Rename argv[0] from beam to invoking program name
OTP-14381
Diffstat (limited to 'erts/etc/common/escript.c')
-rw-r--r-- | erts/etc/common/escript.c | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/erts/etc/common/escript.c b/erts/etc/common/escript.c index 4134a3ff36..c28e45a044 100644 --- a/erts/etc/common/escript.c +++ b/erts/etc/common/escript.c @@ -155,6 +155,29 @@ free_env_val(char *value) efree(value); #endif } + +static void +set_env(char *key, char *value) +{ +#ifdef __WIN32__ + WCHAR wkey[MAXPATHLEN]; + WCHAR wvalue[MAXPATHLEN]; + MultiByteToWideChar(CP_UTF8, 0, key, -1, wkey, MAXPATHLEN); + MultiByteToWideChar(CP_UTF8, 0, value, -1, wvalue, MAXPATHLEN); + if (!SetEnvironmentVariableW(wkey, wvalue)) + error("SetEnvironmentVariable(\"%s\", \"%s\") failed!", key, value); +#else + size_t size = strlen(key) + 1 + strlen(value) + 1; + char *str = emalloc(size); + sprintf(str, "%s=%s", key, value); + if (putenv(str) != 0) + error("putenv(\"%s\") failed!", str); +#ifdef HAVE_COPYING_PUTENV + efree(str); +#endif +#endif +} + /* * Find absolute path to this program */ @@ -548,7 +571,12 @@ main(int argc, char** argv) while (--eargc_base >= 0) { UNSHIFT(eargv_base[eargc_base]); } - + + /* + * Add scriptname to env + */ + set_env("ESCRIPT_NAME", scriptname); + /* * Invoke Erlang with the collected options. */ |