xref: /onnv-gate/usr/src/lib/libast/common/sfio/sfwalk.c (revision 12068:08a39a083754)
110898Sroland.mainz@nrubsig.org /***********************************************************************
210898Sroland.mainz@nrubsig.org *                                                                      *
310898Sroland.mainz@nrubsig.org *               This software is part of the ast package               *
4*12068SRoger.Faulkner@Oracle.COM *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
510898Sroland.mainz@nrubsig.org *                      and is licensed under the                       *
610898Sroland.mainz@nrubsig.org *                  Common Public License, Version 1.0                  *
710898Sroland.mainz@nrubsig.org *                    by AT&T Intellectual Property                     *
810898Sroland.mainz@nrubsig.org *                                                                      *
910898Sroland.mainz@nrubsig.org *                A copy of the License is available at                 *
1010898Sroland.mainz@nrubsig.org *            http://www.opensource.org/licenses/cpl1.0.txt             *
1110898Sroland.mainz@nrubsig.org *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
1210898Sroland.mainz@nrubsig.org *                                                                      *
1310898Sroland.mainz@nrubsig.org *              Information and Software Systems Research               *
1410898Sroland.mainz@nrubsig.org *                            AT&T Research                             *
1510898Sroland.mainz@nrubsig.org *                           Florham Park NJ                            *
1610898Sroland.mainz@nrubsig.org *                                                                      *
1710898Sroland.mainz@nrubsig.org *                 Glenn Fowler <gsf@research.att.com>                  *
1810898Sroland.mainz@nrubsig.org *                  David Korn <dgk@research.att.com>                   *
1910898Sroland.mainz@nrubsig.org *                   Phong Vo <kpv@research.att.com>                    *
2010898Sroland.mainz@nrubsig.org *                                                                      *
2110898Sroland.mainz@nrubsig.org ***********************************************************************/
2210898Sroland.mainz@nrubsig.org #include	"sfhdr.h"
2310898Sroland.mainz@nrubsig.org 
2410898Sroland.mainz@nrubsig.org /* Walk streams and run operations on them
2510898Sroland.mainz@nrubsig.org **
2610898Sroland.mainz@nrubsig.org ** Written by Kiem-Phong Vo.
2710898Sroland.mainz@nrubsig.org */
2810898Sroland.mainz@nrubsig.org 
2910898Sroland.mainz@nrubsig.org #if __STD_C
sfwalk(Sfwalk_f walkf,Void_t * data,int type)3010898Sroland.mainz@nrubsig.org int sfwalk(Sfwalk_f walkf, Void_t* data, int type)
3110898Sroland.mainz@nrubsig.org #else
3210898Sroland.mainz@nrubsig.org int sfwalk(walkf, data, type)
3310898Sroland.mainz@nrubsig.org Sfwalk_f	walkf;	/* return <0: stop, >=0: continue	*/
3410898Sroland.mainz@nrubsig.org Void_t*		data;
3510898Sroland.mainz@nrubsig.org int		type;	/* walk streams with all given flags	*/
3610898Sroland.mainz@nrubsig.org #endif
3710898Sroland.mainz@nrubsig.org {
3810898Sroland.mainz@nrubsig.org 	Sfpool_t	*p;
3910898Sroland.mainz@nrubsig.org 	Sfio_t		*f;
4010898Sroland.mainz@nrubsig.org 	int		n, rv;
4110898Sroland.mainz@nrubsig.org 
4210898Sroland.mainz@nrubsig.org 	/* truly initializing std-streams before walking */
4310898Sroland.mainz@nrubsig.org 	if(sfstdin->mode & SF_INIT)
4410898Sroland.mainz@nrubsig.org 		_sfmode(sfstdin, (sfstdin->mode & SF_RDWR), 0);
4510898Sroland.mainz@nrubsig.org 	if(sfstdout->mode & SF_INIT)
4610898Sroland.mainz@nrubsig.org 		_sfmode(sfstdout, (sfstdout->mode & SF_RDWR), 0);
4710898Sroland.mainz@nrubsig.org 	if(sfstderr->mode & SF_INIT)
4810898Sroland.mainz@nrubsig.org 		_sfmode(sfstderr, (sfstderr->mode & SF_RDWR), 0);
4910898Sroland.mainz@nrubsig.org 
5010898Sroland.mainz@nrubsig.org 	for(rv = 0, p = &_Sfpool; p; p = p->next)
5110898Sroland.mainz@nrubsig.org 	{	for(n = 0; n < p->n_sf; )
5210898Sroland.mainz@nrubsig.org 		{	f = p->sf[n];
5310898Sroland.mainz@nrubsig.org 
5410898Sroland.mainz@nrubsig.org 			if(type != 0 && (f->_flags&type) != type )
5510898Sroland.mainz@nrubsig.org 				continue; /* not in the interested set */
5610898Sroland.mainz@nrubsig.org 
5710898Sroland.mainz@nrubsig.org 			if((rv = (*walkf)(f, data)) < 0)
5810898Sroland.mainz@nrubsig.org 				return rv;
5910898Sroland.mainz@nrubsig.org 
6010898Sroland.mainz@nrubsig.org 			if(p->sf[n] == f) /* move forward to next stream */
6110898Sroland.mainz@nrubsig.org 				n += 1;
6210898Sroland.mainz@nrubsig.org 			/* else - a sfclose() was done on current stream */
6310898Sroland.mainz@nrubsig.org 		}
6410898Sroland.mainz@nrubsig.org 	}
6510898Sroland.mainz@nrubsig.org 
6610898Sroland.mainz@nrubsig.org 	return rv;
6710898Sroland.mainz@nrubsig.org }
68