xref: /titanic_51/usr/src/lib/libast/common/stdio/fcloseall.c (revision 3e14f97f673e8a630f076077de35afdd43dc1587)
134f9b3eeSRoland Mainz /***********************************************************************
234f9b3eeSRoland Mainz *                                                                      *
334f9b3eeSRoland Mainz *               This software is part of the ast package               *
4*3e14f97fSRoger A. Faulkner *          Copyright (c) 1985-2010 AT&T Intellectual Property          *
534f9b3eeSRoland Mainz *                      and is licensed under the                       *
634f9b3eeSRoland Mainz *                  Common Public License, Version 1.0                  *
734f9b3eeSRoland Mainz *                    by AT&T Intellectual Property                     *
834f9b3eeSRoland Mainz *                                                                      *
934f9b3eeSRoland Mainz *                A copy of the License is available at                 *
1034f9b3eeSRoland Mainz *            http://www.opensource.org/licenses/cpl1.0.txt             *
1134f9b3eeSRoland Mainz *         (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9)         *
1234f9b3eeSRoland Mainz *                                                                      *
1334f9b3eeSRoland Mainz *              Information and Software Systems Research               *
1434f9b3eeSRoland Mainz *                            AT&T Research                             *
1534f9b3eeSRoland Mainz *                           Florham Park NJ                            *
1634f9b3eeSRoland Mainz *                                                                      *
1734f9b3eeSRoland Mainz *                 Glenn Fowler <gsf@research.att.com>                  *
1834f9b3eeSRoland Mainz *                  David Korn <dgk@research.att.com>                   *
1934f9b3eeSRoland Mainz *                   Phong Vo <kpv@research.att.com>                    *
2034f9b3eeSRoland Mainz *                                                                      *
2134f9b3eeSRoland Mainz ***********************************************************************/
2234f9b3eeSRoland Mainz #pragma prototyped
2334f9b3eeSRoland Mainz 
2434f9b3eeSRoland Mainz #include "stdhdr.h"
2534f9b3eeSRoland Mainz 
2634f9b3eeSRoland Mainz #define MAXLOOP		3
2734f9b3eeSRoland Mainz 
2834f9b3eeSRoland Mainz int
fcloseall(void)2934f9b3eeSRoland Mainz fcloseall(void)
3034f9b3eeSRoland Mainz {
3134f9b3eeSRoland Mainz 	Sfpool_t*	p;
3234f9b3eeSRoland Mainz 	Sfpool_t*	next;
3334f9b3eeSRoland Mainz 	int		n;
3434f9b3eeSRoland Mainz 	int		nclose;
3534f9b3eeSRoland Mainz 	int		count;
3634f9b3eeSRoland Mainz 	int		loop;
3734f9b3eeSRoland Mainz 
3834f9b3eeSRoland Mainz 	STDIO_INT(0, "fcloseall", int, (void), ())
3934f9b3eeSRoland Mainz 
4034f9b3eeSRoland Mainz 	for(loop = 0; loop < MAXLOOP; ++loop)
4134f9b3eeSRoland Mainz 	{	nclose = count = 0;
4234f9b3eeSRoland Mainz 		for(p = &_Sfpool; p; p = next)
4334f9b3eeSRoland Mainz 		{	/* find the next legitimate pool */
4434f9b3eeSRoland Mainz 			for(next = p->next; next; next = next->next)
4534f9b3eeSRoland Mainz 				if(next->n_sf > 0)
4634f9b3eeSRoland Mainz 					break;
4734f9b3eeSRoland Mainz 			for(n = 0; n < ((p == &_Sfpool) ? p->n_sf : 1); ++n)
4834f9b3eeSRoland Mainz 			{	count += 1;
4934f9b3eeSRoland Mainz 				if(sfclose(p->sf[n]) >= 0)
5034f9b3eeSRoland Mainz 					nclose += 1;
5134f9b3eeSRoland Mainz 			}
5234f9b3eeSRoland Mainz 		}
5334f9b3eeSRoland Mainz 		if(nclose == count)
5434f9b3eeSRoland Mainz 			break;
5534f9b3eeSRoland Mainz 	}
5634f9b3eeSRoland Mainz 	return 0; /* always return 0 per GNU */
5734f9b3eeSRoland Mainz }
58