xref: /onnv-gate/usr/src/lib/libast/common/sfio/sfwalk.c (revision 10898:1883b621b3ea)
1*10898Sroland.mainz@nrubsig.org /***********************************************************************
2*10898Sroland.mainz@nrubsig.org *                                                                      *
3*10898Sroland.mainz@nrubsig.org *               This software is part of the ast package               *
4*10898Sroland.mainz@nrubsig.org *          Copyright (c) 1985-2009 AT&T Intellectual Property          *
5*10898Sroland.mainz@nrubsig.org *                      and is licensed under the                       *
6*10898Sroland.mainz@nrubsig.org *                  Common Public License, Version 1.0                  *
7*10898Sroland.mainz@nrubsig.org *                    by AT&T Intellectual Property                     *
8*10898Sroland.mainz@nrubsig.org *                                                                      *
9*10898Sroland.mainz@nrubsig.org *                A copy of the License is available at                 *
10*10898Sroland.mainz@nrubsig.org *            http://www.opensource.org/licenses/cpl1.0.txt             *
11*10898Sroland.mainz@nrubsig.org *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
12*10898Sroland.mainz@nrubsig.org *                                                                      *
13*10898Sroland.mainz@nrubsig.org *              Information and Software Systems Research               *
14*10898Sroland.mainz@nrubsig.org *                            AT&T Research                             *
15*10898Sroland.mainz@nrubsig.org *                           Florham Park NJ                            *
16*10898Sroland.mainz@nrubsig.org *                                                                      *
17*10898Sroland.mainz@nrubsig.org *                 Glenn Fowler <gsf@research.att.com>                  *
18*10898Sroland.mainz@nrubsig.org *                  David Korn <dgk@research.att.com>                   *
19*10898Sroland.mainz@nrubsig.org *                   Phong Vo <kpv@research.att.com>                    *
20*10898Sroland.mainz@nrubsig.org *                                                                      *
21*10898Sroland.mainz@nrubsig.org ***********************************************************************/
22*10898Sroland.mainz@nrubsig.org #include	"sfhdr.h"
23*10898Sroland.mainz@nrubsig.org 
24*10898Sroland.mainz@nrubsig.org /* Walk streams and run operations on them
25*10898Sroland.mainz@nrubsig.org **
26*10898Sroland.mainz@nrubsig.org ** Written by Kiem-Phong Vo.
27*10898Sroland.mainz@nrubsig.org */
28*10898Sroland.mainz@nrubsig.org 
29*10898Sroland.mainz@nrubsig.org #if __STD_C
30*10898Sroland.mainz@nrubsig.org int sfwalk(Sfwalk_f walkf, Void_t* data, int type)
31*10898Sroland.mainz@nrubsig.org #else
32*10898Sroland.mainz@nrubsig.org int sfwalk(walkf, data, type)
33*10898Sroland.mainz@nrubsig.org Sfwalk_f	walkf;	/* return <0: stop, >=0: continue	*/
34*10898Sroland.mainz@nrubsig.org Void_t*		data;
35*10898Sroland.mainz@nrubsig.org int		type;	/* walk streams with all given flags	*/
36*10898Sroland.mainz@nrubsig.org #endif
37*10898Sroland.mainz@nrubsig.org {
38*10898Sroland.mainz@nrubsig.org 	Sfpool_t	*p;
39*10898Sroland.mainz@nrubsig.org 	Sfio_t		*f;
40*10898Sroland.mainz@nrubsig.org 	int		n, rv;
41*10898Sroland.mainz@nrubsig.org 
42*10898Sroland.mainz@nrubsig.org 	/* truly initializing std-streams before walking */
43*10898Sroland.mainz@nrubsig.org 	if(sfstdin->mode & SF_INIT)
44*10898Sroland.mainz@nrubsig.org 		_sfmode(sfstdin, (sfstdin->mode & SF_RDWR), 0);
45*10898Sroland.mainz@nrubsig.org 	if(sfstdout->mode & SF_INIT)
46*10898Sroland.mainz@nrubsig.org 		_sfmode(sfstdout, (sfstdout->mode & SF_RDWR), 0);
47*10898Sroland.mainz@nrubsig.org 	if(sfstderr->mode & SF_INIT)
48*10898Sroland.mainz@nrubsig.org 		_sfmode(sfstderr, (sfstderr->mode & SF_RDWR), 0);
49*10898Sroland.mainz@nrubsig.org 
50*10898Sroland.mainz@nrubsig.org 	for(rv = 0, p = &_Sfpool; p; p = p->next)
51*10898Sroland.mainz@nrubsig.org 	{	for(n = 0; n < p->n_sf; )
52*10898Sroland.mainz@nrubsig.org 		{	f = p->sf[n];
53*10898Sroland.mainz@nrubsig.org 
54*10898Sroland.mainz@nrubsig.org 			if(type != 0 && (f->_flags&type) != type )
55*10898Sroland.mainz@nrubsig.org 				continue; /* not in the interested set */
56*10898Sroland.mainz@nrubsig.org 
57*10898Sroland.mainz@nrubsig.org 			if((rv = (*walkf)(f, data)) < 0)
58*10898Sroland.mainz@nrubsig.org 				return rv;
59*10898Sroland.mainz@nrubsig.org 
60*10898Sroland.mainz@nrubsig.org 			if(p->sf[n] == f) /* move forward to next stream */
61*10898Sroland.mainz@nrubsig.org 				n += 1;
62*10898Sroland.mainz@nrubsig.org 			/* else - a sfclose() was done on current stream */
63*10898Sroland.mainz@nrubsig.org 		}
64*10898Sroland.mainz@nrubsig.org 	}
65*10898Sroland.mainz@nrubsig.org 
66*10898Sroland.mainz@nrubsig.org 	return rv;
67*10898Sroland.mainz@nrubsig.org }
68