aboutsummaryrefslogtreecommitdiffstats
path: root/lib/stdlib
diff options
context:
space:
mode:
authorJosé Valim <[email protected]>2013-10-28 19:32:07 +0100
committerHenrik Nord <[email protected]>2014-01-10 11:17:23 +0100
commit2db2f977598dab05dc125acdc478c375cb66ddb8 (patch)
treef6da2134f13c6207f807613a467253176cbc1663 /lib/stdlib
parent039ea3a6ed5dc147478f294910ba042850db2383 (diff)
downloadotp-2db2f977598dab05dc125acdc478c375cb66ddb8.tar.gz
otp-2db2f977598dab05dc125acdc478c375cb66ddb8.tar.bz2
otp-2db2f977598dab05dc125acdc478c375cb66ddb8.zip
Handle binary input in console helpers
The standard_input may be set to binary mode via io:getopts/2 and in case such cases the "i/0" console helper got stuck as it was unable to match new lines in binaries.
Diffstat (limited to 'lib/stdlib')
-rw-r--r--lib/stdlib/src/c.erl7
1 files changed, 6 insertions, 1 deletions
diff --git a/lib/stdlib/src/c.erl b/lib/stdlib/src/c.erl
index fb6b8c8661..f23b5d4fe9 100644
--- a/lib/stdlib/src/c.erl
+++ b/lib/stdlib/src/c.erl
@@ -330,13 +330,18 @@ choice(F) ->
end.
get_line(P, Default) ->
- case io:get_line(P) of
+ case line_string(io:get_line(P)) of
"\n" ->
Default;
L ->
L
end.
+%% If the standard input is set to binary mode
+%% convert it to a list so we can properly match.
+line_string(Binary) when is_binary(Binary) -> unicode:characters_to_list(Binary);
+line_string(Other) -> Other.
+
mfa_string(Fun) when is_function(Fun) ->
{module,M} = erlang:fun_info(Fun, module),
{name,F} = erlang:fun_info(Fun, name),