delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2005/06/09/07:57:08

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
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 <stdio.h> 
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

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML><HEAD>
<META http-equiv=3DContent-Type content=3D"text/html; charset=3DUS-ASCII">
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR></HEAD>
<BODY id=3Drole_body style=3D"FONT-SIZE: 10pt; COLOR: #000000; FONT-FAMILY:=20=
Arial"=20
bottomMargin=3D7 leftMargin=3D7 topMargin=3D7 rightMargin=3D7><FONT id=3Drol=
e_document=20
face=3DArial color=3D#000000 size=3D2>
<DIV>&nbsp;=20
<META content=3D"MSHTML 6.00.2800.1141" name=3DGENERATOR><FONT id=3Drolx_doc=
ument=20
face=3DArial color=3D#000000 size=3D2><FONT id=3Drolx_document face=3DArial=20=
color=3D#000000=20
size=3D2>
<DIV>
<DIV><FONT style=3D"BACKGROUND-COLOR: transparent" face=3DArial color=3D#000=
000=20
size=3D2><FONT id=3Drolx_document face=3DArial color=3D#000000 size=3D2><FON=
T=20
id=3Drolx_document face=3DArial color=3D#000000 size=3D2>&nbsp;</DIV>
<BLOCKQUOTE style=3D"PADDING-LEFT: 0px; MARGIN-LEFT: 0px">
  <DIV>&gt;when I redirect output in DOS with "&gt;file" and then I interrup=
t a=20
  GCC-compiled &gt;program</DIV>
  <DIV>&gt;with crtl-c , then the last(&lt;32768 bytes ?) &nbsp;output from=20=
the=20
  program is lost.</DIV>
  <DIV>&gt;</DIV>
  <DIV>&gt;is it possible to make GCC close the redirection file properly as=
 it=20
  does,</DIV>
  <DIV>&gt;when the program terminates without keyboard-interrupt ?</DIV>
  <DIV>&gt;</DIV>
  <DIV>&gt;-Guenter</DIV></FONT></FONT></FONT></BLOCKQUOTE>
<BLOCKQUOTE style=3D"PADDING-LEFT: 0px; MARGIN-LEFT: 0px"><FONT=20
  style=3D"BACKGROUND-COLOR: transparent" face=3DArial color=3D#000000 size=
=3D2>
  <DIV><BR>&gt;&gt;Output is buffered when redirected to a file.&nbsp; You c=
an=20
  use setbuf() to<BR>&gt;&gt;shut the buffering off for your=20
  programs.<BR></DIV></FONT></BLOCKQUOTE></DIV>
<DIV></DIV>
<DIV>OK, I found setbuf. See below.</DIV>
<DIV>But the program shall run with and without redirection, this is not kno=
wn=20
at compile-time.</DIV>
<DIV>So setbuf would have to be included in the error-handler.</DIV>
<DIV>I don't know how to do this and which routine is given control,</DIV>
<DIV>when crtl-C is pressed.</DIV>
<DIV>In earlier years I had just made a small assembly routine which traps</=
DIV>
<DIV>the corresponding interrupt, but nowadays with DOS running in a Windows=
=20
XP-box</DIV>
<DIV>I don't know whether that still works.</DIV>
<DIV>&nbsp;</DIV>
<DIV>Or is there a utility which recovers the lost buffer and writes it to=20
another file ?</DIV>
<DIV>The data should still be somewhere in RAM</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>&nbsp;</DIV>
<DIV>#include &lt;stdio.h&gt; <BR>void setbuf(FILE *file, char *buffer);=20
<BR>&nbsp;<BR>Description <BR>----------- <BR>&nbsp;<BR>This function modifi=
es=20
the buffering characteristics of FILE. First, <BR>if the file already has a=20
buffer, it is freed. If there was any <BR>pending data in it, it is lost, so=
=20
this function should only be used <BR>immediately after a call to `fopen'.=20
<BR>&nbsp;<BR>If the BUFFER passed is `NULL', the file is set to unbuffered.=
 If=20
a <BR>non-`NULL' buffer is passed, it must be at least `BUFSIZ' bytes in=20
<BR>size, and the file is set to fully buffered. <BR>&nbsp;<BR>*Note=20
setbuffer::. *Note setlinebuf::. *Note setvbuf::. <BR>&nbsp;<BR>Return Value=
=20
<BR>------------ <BR>&nbsp;<BR>None. </DIV>
<DIV>&nbsp;</DIV></FONT></FONT></DIV></FONT></BODY></HTML>

-------------------------------1118317601--

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019