[erlang-questions] Bug or feature or my ignorance?

Joe Armstrong erlang@REDACTED
Sun Nov 1 18:14:49 CET 2015

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]),
    %% reopen file and write from byte 11 onwards
    {ok, S1} = file:open("tmp",[raw,write,binary]),

> bug:test().

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?


More information about the erlang-questions mailing list