xref: /original-bsd/lib/libc/gen/signal.c (revision 53787e02)
1 /*
2  * Copyright (c) 1985 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #ifndef lint
8 static char sccsid[] = "@(#)signal.c	5.1 (Berkeley) 06/05/85";
9 #endif not lint
10 
11 /*
12  * Almost backwards compatible signal.
13  */
14 #include <signal.h>
15 
16 int (*
17 signal(s, a))()
18 	int s, (*a)();
19 {
20 	struct sigvec osv, sv;
21 	static int mask[NSIG];
22 	static int flags[NSIG];
23 
24 	sv.sv_handler = a;
25 	sv.sv_mask = mask[s];
26 	sv.sv_flags = flags[s];
27 	if (sigvec(s, &sv, &osv) < 0)
28 		return (BADSIG);
29 	if (sv.sv_mask != osv.sv_mask || sv.sv_flags != osv.sv_flags) {
30 		mask[s] = sv.sv_mask = osv.sv_mask;
31 		flags[s] = sv.sv_flags = osv.sv_flags;
32 		if (sigvec(s, &sv, 0) < 0)
33 			return (BADSIG);
34 	}
35 	return (osv.sv_handler);
36 }
37