1da2e3ebdSchin /***********************************************************************
2da2e3ebdSchin *                                                                      *
3da2e3ebdSchin *               This software is part of the ast package               *
4*b30d1939SAndy Fiddaman *          Copyright (c) 1985-2011 AT&T Intellectual Property          *
5da2e3ebdSchin *                      and is licensed under the                       *
6*b30d1939SAndy Fiddaman *                 Eclipse Public License, Version 1.0                  *
77c2fbfb3SApril Chin *                    by AT&T Intellectual Property                     *
8da2e3ebdSchin *                                                                      *
9da2e3ebdSchin *                A copy of the License is available at                 *
10*b30d1939SAndy Fiddaman *          http://www.eclipse.org/org/documents/epl-v10.html           *
11*b30d1939SAndy Fiddaman *         (with md5 checksum b35adb5213ca9657e911e9befb180842)         *
12da2e3ebdSchin *                                                                      *
13da2e3ebdSchin *              Information and Software Systems Research               *
14da2e3ebdSchin *                            AT&T Research                             *
15da2e3ebdSchin *                           Florham Park NJ                            *
16da2e3ebdSchin *                                                                      *
17da2e3ebdSchin *                 Glenn Fowler <gsf@research.att.com>                  *
18da2e3ebdSchin *                  David Korn <dgk@research.att.com>                   *
19da2e3ebdSchin *                   Phong Vo <kpv@research.att.com>                    *
20da2e3ebdSchin *                                                                      *
21da2e3ebdSchin ***********************************************************************/
2234f9b3eeSRoland Mainz #include	"sfhdr.h"
23da2e3ebdSchin 
2434f9b3eeSRoland Mainz /* Walk streams and run operations on them
2534f9b3eeSRoland Mainz **
2634f9b3eeSRoland Mainz ** Written by Kiem-Phong Vo.
2734f9b3eeSRoland Mainz */
28da2e3ebdSchin 
2934f9b3eeSRoland Mainz #if __STD_C
sfwalk(Sfwalk_f walkf,Void_t * data,int type)3034f9b3eeSRoland Mainz int sfwalk(Sfwalk_f walkf, Void_t* data, int type)
3134f9b3eeSRoland Mainz #else
3234f9b3eeSRoland Mainz int sfwalk(walkf, data, type)
3334f9b3eeSRoland Mainz Sfwalk_f	walkf;	/* return <0: stop, >=0: continue	*/
3434f9b3eeSRoland Mainz Void_t*		data;
3534f9b3eeSRoland Mainz int		type;	/* walk streams with all given flags	*/
3634f9b3eeSRoland Mainz #endif
37da2e3ebdSchin {
3834f9b3eeSRoland Mainz 	Sfpool_t	*p;
3934f9b3eeSRoland Mainz 	Sfio_t		*f;
4034f9b3eeSRoland Mainz 	int		n, rv;
41da2e3ebdSchin 
4234f9b3eeSRoland Mainz 	/* truly initializing std-streams before walking */
4334f9b3eeSRoland Mainz 	if(sfstdin->mode & SF_INIT)
4434f9b3eeSRoland Mainz 		_sfmode(sfstdin, (sfstdin->mode & SF_RDWR), 0);
4534f9b3eeSRoland Mainz 	if(sfstdout->mode & SF_INIT)
4634f9b3eeSRoland Mainz 		_sfmode(sfstdout, (sfstdout->mode & SF_RDWR), 0);
4734f9b3eeSRoland Mainz 	if(sfstderr->mode & SF_INIT)
4834f9b3eeSRoland Mainz 		_sfmode(sfstderr, (sfstderr->mode & SF_RDWR), 0);
49da2e3ebdSchin 
5034f9b3eeSRoland Mainz 	for(rv = 0, p = &_Sfpool; p; p = p->next)
5134f9b3eeSRoland Mainz 	{	for(n = 0; n < p->n_sf; )
5234f9b3eeSRoland Mainz 		{	f = p->sf[n];
53da2e3ebdSchin 
5434f9b3eeSRoland Mainz 			if(type != 0 && (f->_flags&type) != type )
5534f9b3eeSRoland Mainz 				continue; /* not in the interested set */
56da2e3ebdSchin 
5734f9b3eeSRoland Mainz 			if((rv = (*walkf)(f, data)) < 0)
5834f9b3eeSRoland Mainz 				return rv;
59da2e3ebdSchin 
6034f9b3eeSRoland Mainz 			if(p->sf[n] == f) /* move forward to next stream */
6134f9b3eeSRoland Mainz 				n += 1;
6234f9b3eeSRoland Mainz 			/* else - a sfclose() was done on current stream */
6334f9b3eeSRoland Mainz 		}
6434f9b3eeSRoland Mainz 	}
6534f9b3eeSRoland Mainz 
6634f9b3eeSRoland Mainz 	return rv;
67da2e3ebdSchin }
68