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