From 1f3ce8d2b9c07bee672efec9d6e3512633ffcf23 Mon Sep 17 00:00:00 2001 From: Siri Hansen Date: Tue, 15 Jan 2013 10:48:04 +0100 Subject: Make arguments given with -s option to erl aware of file name encoding OTP-10702 Arguments to functions started with the -s option to erl were converted to atoms with list_to_atom(binary_to_list(Bin)) and thus were always seen as latin1 encoded. For other arguments to erl the conversion (to string) would take into account the file name translation mode (set with +fnl, +fnu or +fna switch to erl) and try to convert using unicode:characters_to_list/2. The reason behind this is that it must be possible to give paths and filenames on the command line and get the expected encoding. With the same reasoning, this commit changes the behaviour for arguments to functions started with the -s option to also take into account the file name translation mode. The arguments are now converted to atoms by list_to_atom(unicode:characters_to_list(Bin,file:native_name_encoding()) --- erts/preloaded/src/init.erl | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/erts/preloaded/src/init.erl b/erts/preloaded/src/init.erl index 1d1087c7f2..61d8df2428 100644 --- a/erts/preloaded/src/init.erl +++ b/erts/preloaded/src/init.erl @@ -1,7 +1,7 @@ %% %% %CopyrightBegin% %% -%% Copyright Ericsson AB 1996-2012. All Rights Reserved. +%% Copyright Ericsson AB 1996-2013. All Rights Reserved. %% %% The contents of this file are subject to the Erlang Public License, %% Version 1.1, (the "License"); you may not use this file except in @@ -184,12 +184,16 @@ prepare_run_args({run, [M,F|Args]}) -> [b2a(M), b2a(F) | bs2ss(Args)]. b2a(Bin) when is_binary(Bin) -> - list_to_atom(binary_to_list(Bin)); + list_to_atom(b2s(Bin)); b2a(A) when is_atom(A) -> A. b2s(Bin) when is_binary(Bin) -> - binary_to_list(Bin); + try + unicode:characters_to_list(Bin,file:native_name_encoding()) + catch + _:_ -> binary_to_list(Bin) + end; b2s(L) when is_list(L) -> L. @@ -1260,11 +1264,7 @@ get_arguments([]) -> []. to_strings([H|T]) when is_atom(H) -> [atom_to_list(H)|to_strings(T)]; -to_strings([H|T]) when is_binary(H) -> [try - unicode:characters_to_list(H,file:native_name_encoding()) - catch - _:_ -> binary_to_list(H) - end|to_strings(T)]; +to_strings([H|T]) when is_binary(H) -> [b2s(H)|to_strings(T)]; to_strings([]) -> []. get_argument(Arg,Flags) -> -- cgit v1.2.3