www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/12/12/22:15:55

From: feeley AT raptor DOT IRO DOT UMontreal DOT CA (Marc Feeley)
Newsgroups: comp.os.msdos.djgpp
Subject: SIGINT handling & stdio
Date: 12 Dec 1996 10:06:10 -0500
Organization: /usr/lib/news/organization
Lines: 32
Distribution: world
Message-ID: <q6d8wf6bvh.fsf@raptor.IRO.UMontreal.CA>
NNTP-Posting-Host: raptor.iro.umontreal.ca
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

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).

Any suggestions?  I'm sure this problem must have come up before but
I can't find a suitable answer in the FAQ or the DJGPP doc.

Marc


#include <stdio.h>
#include <signal.h>

int intr = 0;

void user_signal_handler (void) { intr = 1; }

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

- Raw text -


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