mirror of
https://github.com/mikpe/pdp10-tools.git
synced 2026-03-06 11:23:39 +00:00
pdp10_stdio:handle_fopen/2: handling writes after seeks may require reads, so try to get read access even if the user did not ask for it
This commit is contained in:
@@ -243,11 +243,21 @@ code_change(_OldVsn, State, _Extra) -> {ok, State}.
|
||||
|
||||
handle_fopen(Path, Modes) ->
|
||||
case iodir(Modes) of
|
||||
{ok, {Read, Write}} ->
|
||||
case file_open(Path, fopen_modes(Modes)) of
|
||||
{ok, IoDev} -> {ok, {IoDev, Read, Write}};
|
||||
{error, _Reason} = Error -> Error
|
||||
{ok, {Read = false, Write = true}} ->
|
||||
%% A write after a seek to a non octet-aligned nonet needs to reload the
|
||||
%% shiftreg, which requires a read. Therefore if the user did not request
|
||||
%% read access try to get it anyway.
|
||||
case file_open(Path, fopen_modes([read | Modes])) of
|
||||
{ok, IoDev} -> {ok, {IoDev, _Read = true, Write}};
|
||||
{error, _Reason} -> handle_fopen(Path, Modes, Read, Write)
|
||||
end;
|
||||
{ok, {Read, Write}} -> handle_fopen(Path, Modes, Read, Write);
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
handle_fopen(Path, Modes, Read, Write) ->
|
||||
case file_open(Path, fopen_modes(Modes)) of
|
||||
{ok, IoDev} -> {ok, {IoDev, Read, Write}};
|
||||
{error, _Reason} = Error -> Error
|
||||
end.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user