xref: /csrg-svn/usr.bin/f77/libF77/signal_.c (revision 24696)
110546Sdlw /*
222987Skre  * Copyright (c) 1980 Regents of the University of California.
322987Skre  * All rights reserved.  The Berkeley software License Agreement
422987Skre  * specifies the terms and conditions for redistribution.
510546Sdlw  *
6*24696Smckusick  *	@(#)signal_.c	5.3	09/11/85
722994Skre  *
810546Sdlw  * change the action for a specified signal
910546Sdlw  *
1010546Sdlw  * calling sequence:
1110546Sdlw  *	integer cursig, signal, savsig
1210546Sdlw  *	external proc
1310546Sdlw  *	cursig = signal(signum, proc, flag)
1410546Sdlw  * where:
1510546Sdlw  *	'cursig' will receive the current value of signal(2)
16*24696Smckusick  *	'signum' must be in the range 0 <= signum <= 32
1710546Sdlw  *
1810546Sdlw  *	If 'flag' is negative, 'proc' must be an external proceedure name.
1910546Sdlw  *
2010546Sdlw  *	If 'flag' is 0 or positive, it will be passed to signal(2) as the
2110546Sdlw  *	signal action flag. 0 resets the default action; 1 sets 'ignore'.
2210546Sdlw  *	'flag' may be the value returned from a previous call to signal.
2310546Sdlw  *
2410546Sdlw  * This routine arranges to trap user specified signals so that it can
2510546Sdlw  * pass the signum fortran style - by address. (boo)
2610546Sdlw  */
2710546Sdlw 
2810546Sdlw #include	"../libI77/f_errno.h"
2910546Sdlw 
30*24696Smckusick static int (*dispatch[33])();
3110546Sdlw int (*signal())();
3210546Sdlw int sig_trap();
3310546Sdlw 
3410546Sdlw long signal_(sigp, procp, flag)
3510546Sdlw long *sigp, *flag;
3610546Sdlw int (*procp)();
3710546Sdlw {
3810546Sdlw 	int (*oldsig)();
3910546Sdlw 	int (*oldispatch)();
4010546Sdlw 
4110546Sdlw 	oldispatch = dispatch[*sigp];
4210546Sdlw 
43*24696Smckusick 	if (*sigp < 0 || *sigp > 32)
4410546Sdlw 		return(-((long)(errno=F_ERARG)));
4510546Sdlw 
4610546Sdlw 	if (*flag < 0)	/* function address passed */
4710546Sdlw 	{
4810546Sdlw 		dispatch[*sigp] = procp;
4910546Sdlw 		oldsig = signal((int)*sigp, sig_trap);
5010546Sdlw 	}
5110546Sdlw 
5210546Sdlw 	else		/* integer value passed */
5310546Sdlw 		oldsig = signal((int)*sigp, (int)*flag);
5410546Sdlw 
5510546Sdlw 	if (oldsig == sig_trap)
5610546Sdlw 		return((long)oldispatch);
5710546Sdlw 	return((long)oldsig);
5810546Sdlw }
5910546Sdlw 
6010546Sdlw sig_trap(sn)
6110546Sdlw int sn;
6210546Sdlw {
6310546Sdlw 	long lsn = (long)sn;
6410546Sdlw 	return((*dispatch[sn])(&lsn));
6510546Sdlw }
66