xref: /titanic_41/usr/src/lib/libc/port/gen/ssignal.c (revision fa9e4066f08beec538e775443c5be79dd423fcab)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 2004 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 /*	Copyright (c) 1988 AT&T	*/
30 /*	  All Rights Reserved  	*/
31 
32 
33 /*
34  *	ssignal, gsignal: software signals
35  */
36 #pragma weak gsignal = _gsignal
37 #pragma weak ssignal = _ssignal
38 
39 #include "synonyms.h"
40 #include <sys/types.h>
41 #include <signal.h>
42 
43 /* Highest allowable user signal number */
44 #define	MAXSIGNUM	17
45 
46 /* Lowest allowable signal number (lowest user number is always 1) */
47 #define	MINSIG	(-4)
48 
49 /* Table of signal values */
50 static int (*sigs[MAXSIGNUM-MINSIG+1])(int);
51 
52 int (*
53 ssignal(int sig, int (*action)(int)))(int)
54 {
55 	int (*savefn)(int);
56 
57 	if (sig >= MINSIG && sig <= MAXSIGNUM) {
58 		savefn = sigs[sig-MINSIG];
59 		sigs[sig-MINSIG] = action;
60 	} else
61 		savefn = (int(*)(int))SIG_DFL;
62 
63 	return (savefn);
64 }
65 
66 int
67 gsignal(int sig)
68 {
69 	int (*sigfn)(int);
70 
71 	if (sig < MINSIG || sig > MAXSIGNUM ||
72 	    (sigfn = sigs[sig-MINSIG]) == (int(*)(int))SIG_DFL)
73 		return (0);
74 	else if (sigfn == (int(*)(int))SIG_IGN)
75 		return (1);
76 	else {
77 		sigs[sig-MINSIG] = (int(*)(int))SIG_DFL;
78 		return ((*sigfn)(sig));
79 	}
80 }
81