[erlang-questions] Bug or feature or my ignorance?
Sergej Jurečko
sergej.jurecko@REDACTED
Sun Nov 1 18:17:47 CET 2015
You must open with read parameter as well. Otherwise file will be truncated on open.
Sergej
> On 01 Nov 2015, at 18:14, Joe Armstrong <erlang@REDACTED> wrote:
>
> Is this a bug or feature or just my ignorance?
>
> I have a file which I open for write and then I do a
> random access pwrite at byte 11 of the file
> but bytes 0..10 get overwritten.
>
> Here's the example:
>
>
>
> test() ->
> %% make a file with 10 bytes
> {ok, S} = file:open("tmp",[raw,write,binary]),
> file:pwrite(S,0,<<0,1,2,3,4,5,6,7,8,9>>),
> file:close(S),
> %% reopen file and write from byte 11 onwards
> {ok, S1} = file:open("tmp",[raw,write,binary]),
> file:pwrite(S1,10,<<10,11,12,13,14,15>>),
> file:close(S1),
> file:read_file("tmp").
>
>
>> bug:test().
> {ok,<<0,0,0,0,0,0,0,0,0,0,10,11,12,13,14,15>>}
>
> If I open the file in mode [raw,write,binary,append]
> Then file beginning is not overwritten.
>
> So opening an existing file for writing and writing to the end of file
> messes up the portion of the file that I have not written to.
>
> Is this the expected behaviour?
>
> /Joe
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://erlang.org/mailman/listinfo/erlang-questions
More information about the erlang-questions
mailing list