[erlang-bugs] A bug in file:pread or not?

Raimo Niskanen raimo+erlang-bugs@REDACTED
Thu Jan 8 15:55:42 CET 2009


On Mon, Dec 29, 2008 at 01:31:19AM +0100, Christian wrote:
> Sending a LocNum to file:pread/2 where the Size is zero returns eof
> rather than an empty binary.
> 
> 2> {ok, File} = file:open("transpose.erl", [binary, read, raw]).
> {ok,{file_descriptor,prim_file,{#Port<0.93>,7}}}
> 3> file:pread(File, []).
> {ok,[]}
> 4> file:pread(File, [{10,10}]).
> {ok,[<<"ranspose).">>]}
> 5> file:pread(File, [{10,1}]).
> {ok,[<<"r">>]}
> 6> file:pread(File, [{10,0}]).
> {ok,[eof]}
> 
> If I do:
> 
> 8> file:pread(File, [{10, 10}, {10, 1}, {10,0}]).
> {ok,[<<"ranspose).">>,<<"r">>,eof]}

This seems to be a bug. file:read was corrected for this
in some special case, but file:pread was forgotten then.
We will most probably fix it in a bugfix release.
It is now inconsistent since file:position followed
by file:read does not give the same as file:pread.



> 
> Then I see this syscalls being performed using 'strace':
> 
> pread64(7, "ranspose).", 10, 10)        = 10
> pread64(7, "r", 1, 10)                  = 1
> pread64(7, "", 0, 10)                   = 0
> 
> So it looks like the syscall tell you that zero bytes were read. It is
> just reported as having tried to read outside the file.
> _______________________________________________
> erlang-bugs mailing list
> erlang-bugs@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-bugs

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list