Mail Archives: djgpp/2005/06/09/07:57:08
-------------------------------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> =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> </DIV>
<BLOCKQUOTE style=3D"PADDING-LEFT: 0px; MARGIN-LEFT: 0px">
<DIV>>when I redirect output in DOS with ">file" and then I interrup=
t a=20
GCC-compiled >program</DIV>
<DIV>>with crtl-c , then the last(<32768 bytes ?) output from=20=
the=20
program is lost.</DIV>
<DIV>></DIV>
<DIV>>is it possible to make GCC close the redirection file properly as=
it=20
does,</DIV>
<DIV>>when the program terminates without keyboard-interrupt ?</DIV>
<DIV>></DIV>
<DIV>>-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>>>Output is buffered when redirected to a file. You c=
an=20
use setbuf() to<BR>>>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> </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> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV> </DIV>
<DIV>#include <stdio.h> <BR>void setbuf(FILE *file, char *buffer);=20
<BR> <BR>Description <BR>----------- <BR> <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> <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> <BR>*Note=20
setbuffer::. *Note setlinebuf::. *Note setvbuf::. <BR> <BR>Return Value=
=20
<BR>------------ <BR> <BR>None. </DIV>
<DIV> </DIV></FONT></FONT></DIV></FONT></BODY></HTML>
-------------------------------1118317601--
- Raw text -