Erlang/OTP Forums

Author Message

<  Erlang bugs mailing list  ~  prim_file bug

Guest
Posted: Fri Oct 20, 2006 10:44 am Reply with quote
Guest
Reading 0 bytes from a raw file returns eof, instead of {ok, []} or
{ok, <<>>}.

(non-raw file works, and the man page says that it should return {ok,
...}.)


Eshell V5.5.1 (abort with ^G)
1> {ok, F} = file:open("README", [read,raw]).
{ok,{file_descriptor,prim_file,{#Port<0.101>,5}}}
2> file:read(F, 0).
eof
3> {ok, G} = file:open("README", [read]).
{ok,<0.38.0>}
4> file:read(G, 0).
{ok,[]}



Tested in R10B-10 and R11B-1.


Here's a patch, but I'm not 100% sure it's correct.



Index: prim_file.erl
===================================================================
--- prim_file.erl (revision 6046)
+++ prim_file.erl (working copy)
@@ -296,7 +296,7 @@
read(#file_descriptor{module = ?MODULE, data = {Port, _}}, Size)
when is_integer(Size), 0 =< Size, Size < ?LARGEFILESIZE ->
case drv_command(Port, <<?FILE_READ, Size:64>>) of
- {ok, {0, _Data}} ->
+ {ok, {0, _Data}} when Size =/= 0 ->
eof;
{ok, 0} ->
eof;



Index: efile_drv.c
===================================================================
--- efile_drv.c (revision 6046)
+++ efile_drv.c (working copy)
@@ -2170,11 +2170,13 @@
reply_posix_error(desc, EBADF);
goto done;
}
+/*
if (size == 0) {
reply_Uint(desc, size);
goto done;
}
- if (desc->read_size >= size) {
+*/
+ if (desc->read_size > 0 && desc->read_size >= size) {
/* We already have all data */
TRACE_C('D');
reply_data(desc, desc->read_binp, desc->read_offset, size);



/martin
_______________________________________________
erlang-bugs mailing list
erlang-bugs@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-bugs
Post recived from mailinglist
Guest
Posted: Fri Oct 27, 2006 7:35 am Reply with quote
Guest
Thanks, Martin.

/ Gunilla

Martin Bjorklund wrote:
> Reading 0 bytes from a raw file returns eof, instead of {ok, []} or
> {ok, <<>>}.
>
> (non-raw file works, and the man page says that it should return {ok,
> ...}.)
>
>
> Eshell V5.5.1 (abort with ^G)
> 1> {ok, F} = file:open("README", [read,raw]).
> {ok,{file_descriptor,prim_file,{#Port<0.101>,5}}}
> 2> file:read(F, 0).
> eof
> 3> {ok, G} = file:open("README", [read]).
> {ok,<0.38.0>}
> 4> file:read(G, 0).
> {ok,[]}
>
>
>
> Tested in R10B-10 and R11B-1.
>
>
> Here's a patch, but I'm not 100% sure it's correct.
>
>
>
> Index: prim_file.erl
> ===================================================================
> --- prim_file.erl (revision 6046)
> +++ prim_file.erl (working copy)
> @@ -296,7 +296,7 @@
> read(#file_descriptor{module = ?MODULE, data = {Port, _}}, Size)
> when is_integer(Size), 0 =< Size, Size < ?LARGEFILESIZE ->
> case drv_command(Port, <<?FILE_READ, Size:64>>) of
> - {ok, {0, _Data}} ->
> + {ok, {0, _Data}} when Size =/= 0 ->
> eof;
> {ok, 0} ->
> eof;
>
>
>
> Index: efile_drv.c
> ===================================================================
> --- efile_drv.c (revision 6046)
> +++ efile_drv.c (working copy)
> @@ -2170,11 +2170,13 @@
> reply_posix_error(desc, EBADF);
> goto done;
> }
> +/*
> if (size == 0) {
> reply_Uint(desc, size);
> goto done;
> }
> - if (desc->read_size >= size) {
> +*/
> + if (desc->read_size > 0 && desc->read_size >= size) {
> /* We already have all data */
> TRACE_C('D');
> reply_data(desc, desc->read_binp, desc->read_offset, size);
>
>
>
> /martin

_______________________________________________
erlang-bugs mailing list
erlang-bugs@erlang.org
http://www.erlang.org/mailman/listinfo/erlang-bugs
Post recived from mailinglist

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum