X-Authentication-Warning: delorie.com: mail set sender to djgpp-bounces using -f From: Sterten AT aol DOT com Message-ID: <1a3.3557173b.2fd98621@aol.com> Date: Thu, 9 Jun 2005 07:46:41 EDT Subject: Re: data lost after crtl-c To: djgpp AT delorie DOT com MIME-Version: 1.0 Content-Type: multipart/alternative; boundary="-----------------------------1118317601" X-Mailer: 9.0 SE for Windows sub 5007 Reply-To: djgpp AT delorie DOT com -------------------------------1118317601 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: 7bit >when I redirect output in DOS with ">file" and then I interrupt a GCC-compiled >program >with crtl-c , then the last(<32768 bytes ?) output from the program is lost. > >is it possible to make GCC close the redirection file properly as it does, >when the program terminates without keyboard-interrupt ? > >-Guenter >>Output is buffered when redirected to a file. You can use setbuf() to >>shut the buffering off for your programs. OK, I found setbuf. See below. But the program shall run with and without redirection, this is not known at compile-time. So setbuf would have to be included in the error-handler. I don't know how to do this and which routine is given control, when crtl-C is pressed. In earlier years I had just made a small assembly routine which traps the corresponding interrupt, but nowadays with DOS running in a Windows XP-box I don't know whether that still works. Or is there a utility which recovers the lost buffer and writes it to another file ? The data should still be somewhere in RAM #include void setbuf(FILE *file, char *buffer); Description ----------- This function modifies the buffering characteristics of FILE. First, if the file already has a buffer, it is freed. If there was any pending data in it, it is lost, so this function should only be used immediately after a call to `fopen'. If the BUFFER passed is `NULL', the file is set to unbuffered. If a non-`NULL' buffer is passed, it must be at least `BUFSIZ' bytes in size, and the file is set to fully buffered. *Note setbuffer::. *Note setlinebuf::. *Note setvbuf::. Return Value ------------ None. -------------------------------1118317601 Content-Type: text/html; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable
 =20
 
>when I redirect output in DOS with ">file" and then I interrup= t a=20 GCC-compiled >program
>with crtl-c , then the last(<32768 bytes ?)  output from=20= the=20 program is lost.
>
>is it possible to make GCC close the redirection file properly as= it=20 does,
>when the program terminates without keyboard-interrupt ?
>
>-Guenter

>>Output is buffered when redirected to a file.  You c= an=20 use setbuf() to
>>shut the buffering off for your=20 programs.
OK, I found setbuf. See below.
But the program shall run with and without redirection, this is not kno= wn=20 at compile-time.
So setbuf would have to be included in the error-handler.
I don't know how to do this and which routine is given control,
when crtl-C is pressed.
In earlier years I had just made a small assembly routine which traps
the corresponding interrupt, but nowadays with DOS running in a Windows= =20 XP-box
I don't know whether that still works.
 
Or is there a utility which recovers the lost buffer and writes it to=20 another file ?
The data should still be somewhere in RAM
 
 
 
 
 
 
 
 
 
#include <stdio.h>
void setbuf(FILE *file, char *buffer);=20
 
Description
-----------
 
This function modifi= es=20 the buffering characteristics of FILE. First,
if the file already has a=20 buffer, it is freed. If there was any
pending data in it, it is lost, so= =20 this function should only be used
immediately after a call to `fopen'.=20
 
If the BUFFER passed is `NULL', the file is set to unbuffered.= If=20 a
non-`NULL' buffer is passed, it must be at least `BUFSIZ' bytes in=20
size, and the file is set to fully buffered.
 
*Note=20 setbuffer::. *Note setlinebuf::. *Note setvbuf::.
 
Return Value= =20
------------
 
None.
 
-------------------------------1118317601--