Mercurial > octave
changeset 33233:a0ea07a4c043
allow dup2, fcntl, and stat to work for files not known to Octave (bug #65393)
* syscalls.cc (Fdup2, Ffcntl, Fstat): If stream lookup fails, use
provided file ID.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 21 Mar 2024 13:32:15 -0400 |
parents | c5dc54712378 |
children | e104e9f0cf62 |
files | libinterp/corefcn/syscalls.cc |
diffstat | 1 files changed, 22 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/syscalls.cc Thu Mar 21 11:21:04 2024 -0400 +++ b/libinterp/corefcn/syscalls.cc Thu Mar 21 13:32:15 2024 -0400 @@ -127,12 +127,20 @@ stream_list& streams = interp.get_stream_list (); stream old_stream = streams.lookup (args(0), "dup2"); - stream new_stream = streams.lookup (args(1), "dup2"); int i_old = old_stream.file_number (); int i_new = new_stream.file_number (); + // If the file is not known to Octave, try the operation on the + // provided file ID. + + if (i_old < 0) + i_old = args(0).int_value (true); + + if (i_new < 0) + i_new = args(1).int_value (true); + if (i_old >= 0 && i_new >= 0) { std::string msg; @@ -451,6 +459,13 @@ int arg = args(2).int_value (true); // FIXME: Need better checking here? + + // If the file is not known to Octave, try the operation on the + // provided file ID. + + if (fid < 0) + fid = args(0).int_value (true); + if (fid < 0) error ("fcntl: invalid file id"); @@ -912,6 +927,12 @@ int fid = streams.get_file_number (args(0)); + // If the file is not known to Octave, try the operation on the + // provided file ID. + + if (fid < 0) + fid = args(0).int_value (true); + sys::file_fstat fs (fid); retval = mk_stat_result (fs);