From bug-request at octave dot org Fri Dec 9 06:34:32 2005 Subject: puts(1) closes stdout stream From: David Bateman To: bug at octave dot org Date: Fri, 09 Dec 2005 13:30:13 +0100 This is a multi-part message in MIME format. --------------050904030808040306040008 Content-Type: text/plain; charset=ISO-8859-1; format=flowed Content-Transfer-Encoding: 7bit It seems that puts(1) closes the stdout stream. I'm not quite sure how it does this, but it seems to be due to the stdout_stream::fail variable being set when octave_stream_list::insert is called. The result is that the next call to fopen returns fid = 1 and this results in a file that can't be closed with fclose.. The test for this is puts(1);nm=tmpnam();fid=fopen(nm,'w'),fclose(fid); What I propose as a fix is to have Fputs clear the error on octave_stdout stream systematically. A better fix would be to figure out why the stdout_stream::fail variable being true causes octave_stream_list::insert to think that stdout is closed. Please find attached a proposed patch that fixes this. Regards David 2005-12-09 David Bateman * file_io.cc (Fputs): systematically call stdout_stream.error(true) to clear error state of stdout stream. -- David Bateman David dot Bateman at motorola dot com Motorola Labs - Paris +33 1 69 35 48 04 (Ph) Parc Les Algorithmes, Commune de St Aubin +33 1 69 35 77 01 (Fax) 91193 Gif-Sur-Yvette FRANCE The information contained in this communication has been classified as: [x] General Business Information [ ] Motorola Internal Use Only [ ] Motorola Confidential Proprietary --------------050904030808040306040008 Content-Type: text/plain; name="patch" Content-Transfer-Encoding: 7bit Content-Disposition: inline; filename="patch" *** ./src/file-io.cc.orig3 2005-12-08 18:11:43.000000000 +0100 --- ./src/file-io.cc 2005-12-09 11:08:09.000000000 +0100 *************** *** 898,904 **** octave_value retval = -1; if (args.length () == 1) ! retval = stdout_stream.puts (args(0), who); else print_usage (who); --- 898,909 ---- octave_value retval = -1; if (args.length () == 1) ! { ! retval = stdout_stream.puts (args(0), who); ! ! // Clear the error on the stream. ! stdout_stream.error(true); ! } else print_usage (who); --------------050904030808040306040008-- ------------------------------------------------------------- Octave is freely available under the terms of the GNU GPL. Octave's home on the web: http://www.octave.org How to fund new projects: http://www.octave.org/funding.html Subscription information: http://www.octave.org/archive.html -------------------------------------------------------------