aboutsummaryrefslogtreecommitdiffstats
path: root/lib/kernel/src/file_io_server.erl
diff options
context:
space:
mode:
authorRaimo Niskanen <[email protected]>2015-11-25 11:43:20 +0100
committerRaimo Niskanen <[email protected]>2015-11-26 11:04:50 +0100
commit5c6ddf14e8264e61225c0bb5cdc79d537f58be3f (patch)
tree3a58452aedc5e98e73e75cff33defee13e4cb98c /lib/kernel/src/file_io_server.erl
parent6b5ea6ecb4eed204496cf196d98e7453df02c6dd (diff)
downloadotp-5c6ddf14e8264e61225c0bb5cdc79d537f58be3f.tar.gz
otp-5c6ddf14e8264e61225c0bb5cdc79d537f58be3f.tar.bz2
otp-5c6ddf14e8264e61225c0bb5cdc79d537f58be3f.zip
Fix file:pread and :pwrite to use character encoding
Diffstat (limited to 'lib/kernel/src/file_io_server.erl')
-rw-r--r--lib/kernel/src/file_io_server.erl46
1 files changed, 39 insertions, 7 deletions
diff --git a/lib/kernel/src/file_io_server.erl b/lib/kernel/src/file_io_server.erl
index 5b2cae6b02..9c425d2175 100644
--- a/lib/kernel/src/file_io_server.erl
+++ b/lib/kernel/src/file_io_server.erl
@@ -214,26 +214,58 @@ file_request({allocate, Offset, Length},
#state{handle = Handle} = State) ->
Reply = ?PRIM_FILE:allocate(Handle, Offset, Length),
{reply, Reply, State};
+file_request({pread,At,Sz}, State)
+ when At =:= cur;
+ At =:= {cur,0} ->
+ case get_chars(Sz, latin1, State) of
+ {reply,Reply,NewState}
+ when is_list(Reply);
+ is_binary(Reply) ->
+ {reply,{ok,Reply},NewState};
+ {stop,_,Reply,NewState} ->
+ {error,Reply,NewState};
+ Other ->
+ Other
+ end;
file_request({pread,At,Sz},
- #state{handle=Handle,buf=Buf,read_mode=ReadMode}=State) ->
+ #state{handle=Handle,buf=Buf}=State) ->
case position(Handle, At, Buf) of
{error,_} = Reply ->
{error,Reply,State};
_ ->
- case ?PRIM_FILE:read(Handle, Sz) of
- {ok,Bin} when ReadMode =:= list ->
- std_reply({ok,binary_to_list(Bin)}, State);
- Reply ->
- std_reply(Reply, State)
+ case get_chars(Sz, latin1, State#state{buf= <<>>}) of
+ {reply,Reply,NewState}
+ when is_list(Reply);
+ is_binary(Reply) ->
+ {reply,{ok,Reply},NewState};
+ {stop,_,Reply,NewState} ->
+ {error,Reply,NewState};
+ Other ->
+ Other
end
end;
+file_request({pwrite,At,Data},
+ #state{buf= <<>>}=State)
+ when At =:= cur;
+ At =:= {cur,0} ->
+ case put_chars(Data, latin1, State) of
+ {stop,_,Reply,NewState} ->
+ {error,Reply,NewState};
+ Other ->
+ Other
+ end;
file_request({pwrite,At,Data},
#state{handle=Handle,buf=Buf}=State) ->
case position(Handle, At, Buf) of
{error,_} = Reply ->
{error,Reply,State};
_ ->
- std_reply(?PRIM_FILE:write(Handle, Data), State)
+ case put_chars(Data, latin1, State) of
+ {stop,_,Reply,NewState} ->
+ {error,Reply,NewState};
+ Other ->
+ Other
+ end
end;
file_request(datasync,
#state{handle=Handle}=State) ->