aboutsummaryrefslogtreecommitdiffstats
path: root/erts/preloaded/src/prim_file.erl
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2013-02-05 09:13:41 +0100
committerBjörn Gustavsson <[email protected]>2013-02-11 14:08:46 +0100
commitb00651f9701f6d352b270af3700abce0e65aa5b6 (patch)
tree3c4eae19b479d024ec0c6624b7356b06a4a93ef1 /erts/preloaded/src/prim_file.erl
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/preloaded/src/prim_file.erl')
-rw-r--r--erts/preloaded/src/prim_file.erl34
1 files changed, 5 insertions, 29 deletions
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};