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

Christian chsu79@REDACTED
Mon Dec 29 01:31:18 CET 2008


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]}

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.



More information about the erlang-bugs mailing list