aboutsummaryrefslogtreecommitdiffstats
path: root/erts
diff options
context:
space:
mode:
authorBjörn Gustavsson <bjorn@erlang.org>2013-02-05 09:13:41 +0100
committerBjörn Gustavsson <bjorn@erlang.org>2013-02-11 14:08:46 +0100
commitb00651f9701f6d352b270af3700abce0e65aa5b6 (patch)
tree3c4eae19b479d024ec0c6624b7356b06a4a93ef1 /erts
parent0aed93263414750a63d65908599ca2e73943b0a7 (diff)
downloadotp-b00651f9701f6d352b270af3700abce0e65aa5b6.tar.gz
otp-b00651f9701f6d352b270af3700abce0e65aa5b6.tar.bz2
otp-b00651f9701f6d352b270af3700abce0e65aa5b6.zip
prim_file: Always open non-file ports in binary mode
Ports for operations that did not directly operate on a file (such as listing the files in a directory) was always opened in a binary mode, but there was still code that supported such port opened in non-binary mode. Since we are about to update the code reading directories, and we don't want to bother we supporting non-binary ports, make sure that we force the use of binary mode.
Diffstat (limited to 'erts')
-rw-r--r--erts/preloaded/src/erl_prim_loader.erl4
-rw-r--r--erts/preloaded/src/prim_file.erl34
2 files changed, 7 insertions, 31 deletions
diff --git a/erts/preloaded/src/erl_prim_loader.erl b/erts/preloaded/src/erl_prim_loader.erl
index d36fdeba3f..c2fac8c0fc 100644
--- a/erts/preloaded/src/erl_prim_loader.erl
+++ b/erts/preloaded/src/erl_prim_loader.erl
@@ -149,7 +149,7 @@ start_it("inet", Id, Pid, Hosts) ->
start_it("efile", Id, Pid, _Hosts) ->
process_flag(trap_exit, true),
- {ok, Port} = prim_file:open([binary]),
+ {ok, Port} = prim_file:start(),
init_ack(Pid),
MultiGet = case erlang:system_info(thread_pool_size) of
0 -> false;
@@ -434,7 +434,7 @@ efile_multi_get_file_from_port2(_MFs, 0, _Max, State, _Paths, _Fun, _Ref, Ret) -
efile_par_get_file(Ref, State, {Mod,File} = MF, Paths, Pid, Fun) ->
%% One port for each file read in "parallel":
- case prim_file:open([binary]) of
+ case prim_file:start() of
{ok, Port} ->
Port0 = State#state.data,
State1 = State#state{data = Port},
diff --git a/erts/preloaded/src/prim_file.erl b/erts/preloaded/src/prim_file.erl
index 50adf9c89d..71ec97eb89 100644
--- a/erts/preloaded/src/prim_file.erl
+++ b/erts/preloaded/src/prim_file.erl
@@ -210,12 +210,7 @@ open(_, _) ->
%% Opens a port that can be used for open/3 or read_file/2.
%% Returns {ok, Port} | {error, Reason}.
open(Portopts) when is_list(Portopts) ->
- case drv_open(?FD_DRV, Portopts) of
- {error, _} = Error ->
- Error;
- Other ->
- Other
- end;
+ drv_open(?FD_DRV, [binary|Portopts]);
open(_) ->
{error, badarg}.
@@ -607,13 +602,7 @@ sendfile(#file_descriptor{module = ?MODULE, data = {Port, _}},
%% Returns {ok, Port}, the Port should be used as first argument in all
%% the following functions. Returns {error, Reason} upon failure.
start() ->
- try erlang:open_port({spawn, ?DRV}, [binary]) of
- Port ->
- {ok, Port}
- catch
- error:Reason ->
- {error, Reason}
- end.
+ drv_open(?DRV, [binary]).
stop(Port) when is_port(Port) ->
try erlang:port_close(Port) of
@@ -923,7 +912,7 @@ list_dir_int(Port, Dir) ->
%% Returns {ok, Port} when successful.
drv_open(Driver, Portopts) ->
- try erlang:open_port({spawn, Driver}, Portopts) of
+ try erlang:open_port({spawn_driver, Driver}, Portopts) of
Port ->
{ok, Port}
catch
@@ -1205,18 +1194,12 @@ translate_response(?FILE_RESP_N2DATA = X, L0) when is_list(L0) ->
end;
translate_response(?FILE_RESP_EOF, []) ->
eof;
-translate_response(?FILE_RESP_FNAME, []) ->
- ok;
translate_response(?FILE_RESP_FNAME, Data) when is_binary(Data) ->
{ok, prim_file:internal_native2name(Data)};
-translate_response(?FILE_RESP_FNAME, Data) ->
- {ok, Data};
translate_response(?FILE_RESP_LFNAME, []) ->
ok;
translate_response(?FILE_RESP_LFNAME, Data) when is_binary(Data) ->
{append, transform_lfname(Data)};
-translate_response(?FILE_RESP_LFNAME, Data) ->
- {append, transform_lfname(Data)};
translate_response(?FILE_RESP_ALL_DATA, Data) ->
{ok, Data};
translate_response(X, Data) ->
@@ -1332,15 +1315,8 @@ transform_ldata(0, List, [Size | Sizes], R) ->
{Front, Rear} = lists_split(List, Size),
transform_ldata(0, Rear, Sizes, [Front | R]).
-transform_lfname(<<>>) -> [];
-transform_lfname(<<L:16, Name:L/binary, Names/binary>>) ->
- [ prim_file:internal_native2name(Name) | transform_lfname(Names)];
-transform_lfname([]) -> [];
-transform_lfname([L1,L2|Names]) ->
- L = (L1 bsl 8) bor L2,
- {Name, Rest} = lists_split(Names, L),
- [Name | transform_lfname(Rest)].
-
+transform_lfname(Names) ->
+ [prim_file:internal_native2name(Name) || <<L:16,Name:L/binary>> <= Names].
lists_split(List, 0) when is_list(List) ->
{[], List};