# HG changeset patch # User John W. Eaton # Date 1711042335 14400 # Node ID a0ea07a4c04325c460469db54bc15cf769d71d4a # Parent c5dc54712378f716c06c5f8b4fe77000ec204e97 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. diff -r c5dc54712378 -r a0ea07a4c043 libinterp/corefcn/syscalls.cc --- 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);