From bug-octave-request at bevo dot che dot wisc dot edu Fri Sep 1 01:00:30 2000 Subject: File ID and file descriptor confusion - the fcntl bug From: "John W. Eaton" To: jmr at ieeta dot pt Cc: bug-octave at bevo dot che dot wisc dot edu Date: Fri, 1 Sep 2000 00:57:04 -0500 (CDT) On 31-Aug-2000, Joćo Manuel Rodrigues wrote: | | -------- | Bug report for Octave 2.0.14 configured for alpha-suse-linux-gnu | | Description: | ----------- | | The fopen function in Octave returns an integer (the FID) that can be used | to refer to the file in other C-style I/O functions like fread, fwrite, etc. | One is tempted to think that this FID is equal to the file descriptor (FD) | used by the operating system calls open(), read(), write(), etc. Not so! | I found this the hard way, while trying to debug an .oct function that calls | ioctl() on a device opened by Octave's fopen. | | Well, while skimming through Octave 2.0.16 source code, I found that the | fcntl builtin function is making the same mistake. | | (Note: I'm running Octave 2.0.14 but I read the 2.0.16 source code which | probably is identical in this respect.) The changes I made for the 2.0.x sources are appended below. Similar changes have been checked in to the 2.1.x CVS archive. | 1) You might consider renaming variable fid as fd in order to stress the | difference between "internal" file descriptor and "external" file ID. | 2) It's quite annoying that the functions octave_stream_list::get_file_number() | and octave_base_stream::file_number() in octave-2.0.16/src/oct-stream.cc have | such similar names but refer to different numbers: an FID in the former and an | FD in the second. It certainly fooled me for a while. Renaming should be | considered. Would you like to submit a patch that does these things? Thanks, jwe ----------------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.che.wisc.edu/octave/octave.html How to fund new projects: http://www.che.wisc.edu/octave/funding.html Subscription information: http://www.che.wisc.edu/octave/archive.html -----------------------------------------------------------------------