aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorJohn Högberg <[email protected]>2018-06-21 10:07:56 +0200
committerJohn Högberg <[email protected]>2018-06-21 12:34:33 +0200
commit718fcf2637aa1a2231399c03ae6984bb6143ffaf (patch)
tree4228788bb3885bc84f25871801d20c1bc6e8f775
parenta0ae44f324576104760a63fe6cf63e0ca31756fc (diff)
downloadotp-718fcf2637aa1a2231399c03ae6984bb6143ffaf.tar.gz
otp-718fcf2637aa1a2231399c03ae6984bb6143ffaf.tar.bz2
otp-718fcf2637aa1a2231399c03ae6984bb6143ffaf.zip
Fix environment case sensitivity issues on Windows
-rw-r--r--erts/emulator/sys/common/erl_osenv.c10
-rw-r--r--erts/emulator/test/bif_SUITE.erl16
2 files changed, 23 insertions, 3 deletions
diff --git a/erts/emulator/sys/common/erl_osenv.c b/erts/emulator/sys/common/erl_osenv.c
index 9f54d1dff0..487ff87116 100644
--- a/erts/emulator/sys/common/erl_osenv.c
+++ b/erts/emulator/sys/common/erl_osenv.c
@@ -75,7 +75,15 @@ static int compare_env_keys(const erts_osenv_data_t a, const erts_osenv_data_t b
#include "erl_rbtree.h"
static int compare_env_keys(const erts_osenv_data_t a, const erts_osenv_data_t b) {
- int relation = sys_memcmp(a.data, b.data, MIN(a.length, b.length));
+ int relation;
+
+#ifdef __WIN32__
+ /* Environment variables are case-insensitive on Windows. */
+ relation = _wcsnicmp((const WCHAR*)a.data, (const WCHAR*)b.data,
+ MIN(a.length, b.length) / sizeof(WCHAR));
+#else
+ relation = sys_memcmp(a.data, b.data, MIN(a.length, b.length));
+#endif
if(relation != 0) {
return relation;
diff --git a/erts/emulator/test/bif_SUITE.erl b/erts/emulator/test/bif_SUITE.erl
index 32bfcd5520..9e7bcd5255 100644
--- a/erts/emulator/test/bif_SUITE.erl
+++ b/erts/emulator/test/bif_SUITE.erl
@@ -36,7 +36,8 @@
error_stacktrace_during_call_trace/1,
group_leader_prio/1, group_leader_prio_dirty/1,
is_process_alive/1,
- process_info_blast/1]).
+ process_info_blast/1,
+ os_env_case_sensitivity/1]).
suite() ->
[{ct_hooks,[ts_install_cth]},
@@ -51,7 +52,7 @@ all() ->
erl_crash_dump_bytes, min_max, erlang_halt, is_builtin,
error_stacktrace, error_stacktrace_during_call_trace,
group_leader_prio, group_leader_prio_dirty,
- is_process_alive, process_info_blast].
+ is_process_alive, process_info_blast, os_env_case_sensitivity].
%% Uses erlang:display to test that erts_printf does not do deep recursion
display(Config) when is_list(Config) ->
@@ -443,6 +444,17 @@ os_env_long(Min, Max, Value) ->
true = os:unsetenv(EnvVar),
os_env_long(Min+1, Max, Value).
+os_env_case_sensitivity(Config) when is_list(Config) ->
+ %% The keys in os:getenv/putenv must be case-insensitive on Windows, and
+ %% case-sensitive elsewhere.
+ true = os:putenv("os_env_gurka", "gaffel"),
+ Expected = case os:type() of
+ {win32, _} -> "gaffel";
+ _ -> false
+ end,
+ Expected = os:getenv("OS_ENV_GURKA"),
+ ok.
+
%% Test that string:to_integer does not Halloc in wrong order.
otp_7526(Config) when is_list(Config) ->
ok = test_7526(256).