www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/13/09:57:37

From: "John M. Aldrich" <fighteer AT cs DOT com>
Newsgroups: comp.os.msdos.djgpp
Subject: Re: SIGINT handling & stdio
Date: Thu, 12 Dec 1996 19:46:51 -0800
Organization: Three pounds of chaos and a pinch of salt
Lines: 52
Message-ID: <32B0D1AB.40E4@cs.com>
References: <q6d8wf6bvh DOT fsf AT raptor DOT IRO DOT UMontreal DOT CA>
Reply-To: fighteer AT cs DOT com
NNTP-Posting-Host: ppp211.cs.com
Mime-Version: 1.0
To: Marc Feeley <feeley AT raptor DOT IRO DOT UMontreal DOT CA>
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

Marc Feeley wrote:
> 
> I want to port a program that uses stdio and handles ctrl-c interrupts
> with signal(SIGINT,...).  The program below is a small example.  It
> seems that when getchar is called, a ctrl-c will NOT call the signal
> handler; the program simply terminates.  This is strange because if I
> replace getchar with getkey then the program works fine.
> Unfortunately I can't use getkey in my program because the input is
> not necessarily from the console (it might be a redirection).

What are you running this program under?  In DOS with CWSDPMI it works
perfectly for me.  Well, not exactly _perfectly_, but at least it works
as written.

Some comments:

> void user_signal_handler (void) { intr = 1; }

This is defined wrong.  ANSI signal handlers take an int as an
argument.  gcc gives me the following warning:

sigint.c: In function `main':
sigint.c:11: warning: passing arg 2 of `signal' from incompatible
pointer type

> void main (void)

This is wrong, too.  main() MUST return an int!  It doesn't matter how
small your program is; you cannot omit this.

> {
>   int c;
>   signal (SIGINT, user_signal_handler);
>   while ((c=getchar()) != 'q')
>     {
>       if (intr) { printf ("interrupt\n"); intr = 0; }
>       printf ("got %d\n", c);
>     }
> }

-- 
John M. Aldrich <fighteer AT cs DOT com>                      

* Anything that happens, happens.
* Anything that, in happening, causes something else to happen,
  causes something else to happen.
* Anything that, in happening, causes itself to happen again, happens
  again.
* It doesn't necessarily do it in chronological order, though.
 
                                       --- Douglas Adams

- Raw text -


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