delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/10/03:31:24

Xref: news2.mv.net comp.os.msdos.djgpp:5809
From: snarfy AT goodguy DOT goodnet DOT com (Snarfy AT GoodNet DOT Com)
Newsgroups: comp.os.msdos.djgpp
Subject: finding out if you are already in an exception?
Date: 10 Jul 1996 06:21:46 GMT
Organization: GoodNet
Lines: 50
Message-ID: <4rvi5r$gc@news1.goodnet.com>
NNTP-Posting-Host: goodnet.com
Keywords: exception threads tasking
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp


I'm writing a program that does a lot of exception handling, and I need
to find out if I'm in an exception in my signal handler.  I found a
variable in <sys/exceptn.h> called '__djgpp_exception_inprog' that is
commented as /* Nested exception count */.  This variable is perfect
for what I need, but when I compile, I get undefined references to it.
Is there something specific that I should be linking with?

The code below should theoretically do nothing when you hit control-c, since
it longjmp's to the state the machine was in when you hit control-c.  If
you hold down Control-C though, it occasionally blows up.  The only thing
I can think of is that it's already in an exception when control-c was
hit. Charles? :)


-------------------------cut here-------------------------
#include <setjmp.h>
#include <conio.h>
#include <sys/exceptn.h>
#include <stdio.h>
#include <signal.h>

jmp_buf my_buf;
void (*old_sig_handler)(int);


void my_sig_handler(int signum)
{
    /* if(__djgpp_exception_inprog > 1) return; */
    memcpy(my_buf, __djgpp_exception_state, sizeof(jmp_buf));
    longjmp(my_buf, 1);
}


main()
{
   printf("hit Control-C to test this...\n");
   old_sig_handler = signal(SIGINT, my_sig_handler);
   for(;;) {printf("testing\n");}
   return(0);
}
-------------------------cut here-------------------------


--Thanks.
Josh
snarfy AT goodnet DOT com


- Raw text -


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