aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel
diff options
context:
space:
mode:
authorBjörn Gustavsson <[email protected]>2016-09-29 12:08:49 +0200
committerBjörn Gustavsson <[email protected]>2016-09-29 12:08:49 +0200
commit81082ce34fcaa97b0ef66a5e445fdbf2e3b9644c (patch)
tree50f1d9741ea92b233ed950270a045982aa8963bd /lib/kernel
parentb353bc12df008f9a30c5ec4f71b51ae70a3102d9 (diff)
parent07b0f4315b079cce7aeef7babdba1bbb686de611 (diff)
downloadotp-81082ce34fcaa97b0ef66a5e445fdbf2e3b9644c.tar.gz
otp-81082ce34fcaa97b0ef66a5e445fdbf2e3b9644c.tar.bz2
otp-81082ce34fcaa97b0ef66a5e445fdbf2e3b9644c.zip
Merge branch 'nathanl/kernel/write_file-uses-writev/PR-1149/OTP-13909'
* nathanl/kernel/write_file-uses-writev/PR-1149/OTP-13909: Let file:write_file/3 use writev
Diffstat (limited to 'lib/kernel')
-rw-r--r--lib/kernel/src/file.erl49
1 files changed, 30 insertions, 19 deletions
diff --git a/lib/kernel/src/file.erl b/lib/kernel/src/file.erl
index 58b601e456..1971df9038 100644
--- a/lib/kernel/src/file.erl
+++ b/lib/kernel/src/file.erl
@@ -397,25 +397,36 @@ write_file(Name, Bin) ->
Modes :: [mode()],
Reason :: posix() | badarg | terminated | system_limit.
-write_file(Name, Bin, ModeList) when is_list(ModeList) ->
- case make_binary(Bin) of
- B when is_binary(B) ->
- case open(Name, [binary, write |
- lists:delete(binary,
- lists:delete(write, ModeList))]) of
- {ok, Handle} ->
- case write(Handle, B) of
- ok ->
- close(Handle);
- E1 ->
- _ = close(Handle),
- E1
- end;
- E2 ->
- E2
- end;
- E3 ->
- E3
+write_file(Name, IOData, ModeList) when is_list(ModeList) ->
+ case lists:member(raw, ModeList) of
+ true ->
+ %% For backwards compatibility of error messages
+ try iolist_size(IOData) of
+ _Size -> do_write_file(Name, IOData, ModeList)
+ catch
+ error:Error -> {error, Error}
+ end;
+ false ->
+ case make_binary(IOData) of
+ Bin when is_binary(Bin) ->
+ do_write_file(Name, Bin, ModeList);
+ Error ->
+ Error
+ end
+ end.
+
+do_write_file(Name, IOData, ModeList) ->
+ case open(Name, [binary, write | ModeList]) of
+ {ok, Handle} ->
+ case write(Handle, IOData) of
+ ok ->
+ close(Handle);
+ E1 ->
+ _ = close(Handle),
+ E1
+ end;
+ E2 ->
+ E2
end.
%% Obsolete, undocumented, local node only, don't use!.