xref: /onnv-gate/usr/src/lib/libast/common/stdio/fcloseall.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 #pragma prototyped
2310898Sroland.mainz@nrubsig.org 
2410898Sroland.mainz@nrubsig.org #include "stdhdr.h"
2510898Sroland.mainz@nrubsig.org 
2610898Sroland.mainz@nrubsig.org #define MAXLOOP		3
2710898Sroland.mainz@nrubsig.org 
2810898Sroland.mainz@nrubsig.org int
fcloseall(void)2910898Sroland.mainz@nrubsig.org fcloseall(void)
3010898Sroland.mainz@nrubsig.org {
3110898Sroland.mainz@nrubsig.org 	Sfpool_t*	p;
3210898Sroland.mainz@nrubsig.org 	Sfpool_t*	next;
3310898Sroland.mainz@nrubsig.org 	int		n;
3410898Sroland.mainz@nrubsig.org 	int		nclose;
3510898Sroland.mainz@nrubsig.org 	int		count;
3610898Sroland.mainz@nrubsig.org 	int		loop;
3710898Sroland.mainz@nrubsig.org 
3810898Sroland.mainz@nrubsig.org 	STDIO_INT(0, "fcloseall", int, (void), ())
3910898Sroland.mainz@nrubsig.org 
4010898Sroland.mainz@nrubsig.org 	for(loop = 0; loop < MAXLOOP; ++loop)
4110898Sroland.mainz@nrubsig.org 	{	nclose = count = 0;
4210898Sroland.mainz@nrubsig.org 		for(p = &_Sfpool; p; p = next)
4310898Sroland.mainz@nrubsig.org 		{	/* find the next legitimate pool */
4410898Sroland.mainz@nrubsig.org 			for(next = p->next; next; next = next->next)
4510898Sroland.mainz@nrubsig.org 				if(next->n_sf > 0)
4610898Sroland.mainz@nrubsig.org 					break;
4710898Sroland.mainz@nrubsig.org 			for(n = 0; n < ((p == &_Sfpool) ? p->n_sf : 1); ++n)
4810898Sroland.mainz@nrubsig.org 			{	count += 1;
4910898Sroland.mainz@nrubsig.org 				if(sfclose(p->sf[n]) >= 0)
5010898Sroland.mainz@nrubsig.org 					nclose += 1;
5110898Sroland.mainz@nrubsig.org 			}
5210898Sroland.mainz@nrubsig.org 		}
5310898Sroland.mainz@nrubsig.org 		if(nclose == count)
5410898Sroland.mainz@nrubsig.org 			break;
5510898Sroland.mainz@nrubsig.org 	}
5610898Sroland.mainz@nrubsig.org 	return 0; /* always return 0 per GNU */
5710898Sroland.mainz@nrubsig.org }
58