File: interrupt.h

package info (click to toggle)
scanmem 0.13-1
  • links: PTS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,188 kB
  • ctags: 527
  • sloc: ansic: 3,889; python: 1,490; xml: 1,410; sh: 1,034; exp: 342; makefile: 33
file content (26 lines) | stat: -rw-r--r-- 691 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
/*

 $Id: interrupt.h,v 1.5 2007-04-11 10:43:26+01 taviso Exp $

*/

#ifndef _INTERRUPT_INC
#define _INTERRUPT_INC

/* small header file to manage interrupted commands */

static sigjmp_buf jmpbuf;       /* used when aborting a command due to interrupt */
static sighandler_t oldsig;     /* reinstalled before longjmp */
static unsigned intused;

/* signal handler to handle interrupt during a commands */
static void interrupted(int n)
{
    (void) n;
    siglongjmp(jmpbuf, 1);
}

#define INTERRUPTABLE() ((oldsig = signal(SIGINT, interrupted)), intused = 1, sigsetjmp(jmpbuf, 1))
#define ENDINTERRUPTABLE() (intused ? ((void) signal(SIGINT, oldsig), intused = 0) : (intused = 0))

#endif