Commit | Line | Data |
---|---|---|
0c67ffe3 | 1 | /* |
ba578a61 | 2 | char id_signal[] = "@(#)signal_.c 1.3"; |
0c67ffe3 DW |
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. | |
06da74d1 DW |
19 | * |
20 | * This routine arranges to trap user specified signals so that it can | |
21 | * pass the signum fortran style - by address. (boo) | |
0c67ffe3 DW |
22 | */ |
23 | ||
24 | #include "../libI77/f_errno.h" | |
25 | ||
06da74d1 | 26 | int (*dispatch[17])(); |
0c67ffe3 | 27 | int (*signal())(); |
06da74d1 | 28 | int sig_trap(); |
0c67ffe3 DW |
29 | |
30 | long signal_(sigp, procp, flag) | |
31 | long *sigp, *flag; | |
32 | int (*procp)(); | |
33 | { | |
ba578a61 DW |
34 | int (*oldsig)(); |
35 | int (*oldispatch)(); | |
36 | ||
37 | oldispatch = dispatch[*sigp]; | |
38 | ||
0c67ffe3 DW |
39 | if (*sigp < 0 || *sigp > 16) |
40 | return(-((long)(errno=F_ERARG))); | |
41 | ||
42 | if (*flag < 0) /* function address passed */ | |
06da74d1 DW |
43 | { |
44 | dispatch[*sigp] = procp; | |
ba578a61 | 45 | oldsig = signal((int)*sigp, sig_trap); |
06da74d1 | 46 | } |
0c67ffe3 DW |
47 | |
48 | else /* integer value passed */ | |
ba578a61 DW |
49 | oldsig = signal((int)*sigp, (int)*flag); |
50 | ||
51 | if (oldsig == sig_trap) | |
52 | return((long)oldispatch); | |
53 | return((long)oldsig); | |
0c67ffe3 | 54 | } |
06da74d1 DW |
55 | |
56 | sig_trap(sn) | |
57 | int sn; | |
58 | { | |
59 | long lsn = (long)sn; | |
60 | return((*dispatch[sn])(&lsn)); | |
61 | } |