Date: Mon, 6 Aug 2001 09:48:39 +0300 (IDT) From: Eli Zaretskii X-Sender: eliz AT is To: Sterten cc: djgpp AT delorie DOT com Subject: Re: files not closed after GPF In-Reply-To: <20010805030625.08871.00002852@ng-fr1.aol.com> Message-ID: MIME-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII Reply-To: djgpp AT delorie DOT com Errors-To: nobody AT delorie DOT com X-Mailing-List: djgpp AT delorie DOT com X-Unsubscribes-To: listserv AT delorie DOT com Precedence: bulk On 5 Aug 2001, Sterten wrote: > when my DOS-gcc203-compiled-programm terminates with a > general protection fault , it obviously doesn't properly close > the open files. This is done by design: trying to close a handle (or do something else that involves a system call) might as well do something nasty like some irrepairable damage to your disk. A program that was hit by a GPF cannot be trusted! It could have its data structures corrupted, its stack smashed, etc., which means the handle you pass to a system call might not be what you think it is. You will meet similar behavior on any other OS, so you had better become used to deal with it. As others told you, use explicit system calls at strategic times to flush the buffered text, if you trace execution and base your debugging on that trace. You might even make the stream unbuffered (if you use `fprintf' and such to write to it), or use unbiffered I/O functions like `write'. The library function `fsync' will force the OS to deliver the data to disk for a particular file handle. Use it (after `fflush', if buffered I/O is in use) to make sure all the data is delivered to the file.