1 /*
2 char id_signal[] = "@(#)signal_.c 1.4";
3 *
4 * change the action for a specified signal
5 *
6 * calling sequence:
7 * integer cursig, signal, savsig
8 * external proc
9 * cursig = signal(signum, proc, flag)
10 * where:
11 * 'cursig' will receive the current value of signal(2)
12 * 'signum' must be in the range 0 <= signum <= 16
13 *
14 * If 'flag' is negative, 'proc' must be an external proceedure name.
15 *
16 * If 'flag' is 0 or positive, it will be passed to signal(2) as the
17 * signal action flag. 0 resets the default action; 1 sets 'ignore'.
18 * 'flag' may be the value returned from a previous call to signal.
19 *
20 * This routine arranges to trap user specified signals so that it can
21 * pass the signum fortran style - by address. (boo)
22 */
23
24 #include "../libI77/f_errno.h"
25
26 static int (*dispatch[17])();
27 int (*signal())();
28 int sig_trap();
29
signal_(sigp,procp,flag)30 long signal_(sigp, procp, flag)
31 long *sigp, *flag;
32 int (*procp)();
33 {
34 int (*oldsig)();
35 int (*oldispatch)();
36
37 oldispatch = dispatch[*sigp];
38
39 if (*sigp < 0 || *sigp > 16)
40 return(-((long)(errno=F_ERARG)));
41
42 if (*flag < 0) /* function address passed */
43 {
44 dispatch[*sigp] = procp;
45 oldsig = signal((int)*sigp, sig_trap);
46 }
47
48 else /* integer value passed */
49 oldsig = signal((int)*sigp, (int)*flag);
50
51 if (oldsig == sig_trap)
52 return((long)oldispatch);
53 return((long)oldsig);
54 }
55
sig_trap(sn)56 sig_trap(sn)
57 int sn;
58 {
59 long lsn = (long)sn;
60 return((*dispatch[sn])(&lsn));
61 }
62