xref: /onnv-gate/usr/src/lib/libast/common/sfio/sfraise.c (revision 12068:08a39a083754)
14887Schin /***********************************************************************
24887Schin *                                                                      *
34887Schin *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
54887Schin *                      and is licensed under the                       *
64887Schin *                  Common Public License, Version 1.0                  *
78462SApril.Chin@Sun.COM *                    by AT&T Intellectual Property                     *
84887Schin *                                                                      *
94887Schin *                A copy of the License is available at                 *
104887Schin *            http://www.opensource.org/licenses/cpl1.0.txt             *
114887Schin *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
124887Schin *                                                                      *
134887Schin *              Information and Software Systems Research               *
144887Schin *                            AT&T Research                             *
154887Schin *                           Florham Park NJ                            *
164887Schin *                                                                      *
174887Schin *                 Glenn Fowler <gsf@research.att.com>                  *
184887Schin *                  David Korn <dgk@research.att.com>                   *
194887Schin *                   Phong Vo <kpv@research.att.com>                    *
204887Schin *                                                                      *
214887Schin ***********************************************************************/
224887Schin #include	"sfhdr.h"
234887Schin 
244887Schin /*	Invoke event handlers for a stream
254887Schin **
264887Schin **	Written by Kiem-Phong Vo.
274887Schin */
284887Schin 
294887Schin #if __STD_C
_sfraiseall(int type,Void_t * data)304887Schin static int _sfraiseall(int type, Void_t* data)
314887Schin #else
324887Schin static int _sfraiseall(type, data)
334887Schin int	type;	/* type of event	*/
344887Schin Void_t*	data;	/* associated data	*/
354887Schin #endif
364887Schin {
374887Schin 	Sfio_t		*f;
384887Schin 	Sfpool_t	*p, *next;
394887Schin 	int		n, rv;
404887Schin 
414887Schin 	rv = 0;
424887Schin 	for(p = &_Sfpool; p; p = next)
434887Schin 	{
444887Schin 		for(next = p->next; next; next = next->next)
454887Schin 			if(next->n_sf > 0)
464887Schin 				break;
474887Schin 		for(n = 0; n < p->n_sf; ++n)
484887Schin 		{	f = p->sf[n];
494887Schin 			if(sfraise(f, type, data) < 0)
504887Schin 				rv -= 1;
514887Schin 		}
524887Schin 	}
534887Schin 	return rv;
544887Schin }
554887Schin 
564887Schin #if __STD_C
sfraise(Sfio_t * f,int type,Void_t * data)574887Schin int sfraise(Sfio_t* f, int type, Void_t* data)
584887Schin #else
594887Schin int sfraise(f, type, data)
604887Schin Sfio_t*	f;	/* stream		*/
614887Schin int	type;	/* type of event	*/
624887Schin Void_t*	data;	/* associated data	*/
634887Schin #endif
644887Schin {
654887Schin 	reg Sfdisc_t	*disc, *next, *d;
664887Schin 	reg int		local, rv;
678462SApril.Chin@Sun.COM 	SFMTXDECL(f);
684887Schin 
694887Schin 	if(!f)
704887Schin 		return _sfraiseall(type,data);
714887Schin 
728462SApril.Chin@Sun.COM 	SFMTXENTER(f, -1);
734887Schin 
744887Schin 	GETLOCAL(f,local);
754887Schin 	if(!SFKILLED(f) &&
764887Schin 	   !(local &&
774887Schin 	     (type == SF_NEW || type == SF_CLOSING ||
784887Schin 	      type == SF_FINAL || type == SF_ATEXIT)) &&
794887Schin 	   SFMODE(f,local) != (f->mode&SF_RDWR) && _sfmode(f,0,local) < 0)
804887Schin 		SFMTXRETURN(f, -1);
814887Schin 	SFLOCK(f,local);
824887Schin 
834887Schin 	for(disc = f->disc; disc; )
844887Schin 	{	next = disc->disc;
854887Schin 		if(type == SF_FINAL)
864887Schin 			f->disc = next;
874887Schin 
884887Schin 		if(disc->exceptf)
894887Schin 		{	SFOPEN(f,0);
904887Schin 			if((rv = (*disc->exceptf)(f,type,data,disc)) != 0 )
914887Schin 				SFMTXRETURN(f, rv);
924887Schin 			SFLOCK(f,0);
934887Schin 		}
944887Schin 
954887Schin 		if((disc = next) )
964887Schin 		{	/* make sure that "next" hasn't been popped */
974887Schin 			for(d = f->disc; d; d = d->disc)
984887Schin 				if(d == disc)
994887Schin 					break;
1004887Schin 			if(!d)
1014887Schin 				disc = f->disc;
1024887Schin 		}
1034887Schin 	}
1044887Schin 
1054887Schin 	SFOPEN(f,local);
1064887Schin 	SFMTXRETURN(f, 0);
1074887Schin }
108