1*1672Smckusick /* Copyright (c) 1979 Regents of the University of California */
2*1672Smckusick 
3*1672Smckusick static char sccsid[] = "@(#)PCLOSE.c 1.1 10/30/80";
4*1672Smckusick 
5*1672Smckusick #include "h00vars.h"
6*1672Smckusick #include "h01errs.h"
7*1672Smckusick 
8*1672Smckusick PCLOSE(level)
9*1672Smckusick 
10*1672Smckusick 	struct iorec		*level;
11*1672Smckusick {
12*1672Smckusick 	register struct iorec	*next;
13*1672Smckusick 
14*1672Smckusick 	next = _fchain.fchain;
15*1672Smckusick 	while(next != FILNIL && next->flev <= level) {
16*1672Smckusick 		if (next->fbuf != 0) {
17*1672Smckusick 			if ((next->funit & FDEF) == 0) {
18*1672Smckusick 				fclose(next->fbuf);
19*1672Smckusick 				if (ferror(next->fbuf)) {
20*1672Smckusick 					ERROR(ECLOSE, next->pfname);
21*1672Smckusick 					return;
22*1672Smckusick 				}
23*1672Smckusick 			}
24*1672Smckusick 			if ((next->funit & TEMP) != 0 &&
25*1672Smckusick 			    unlink(next->pfname)) {
26*1672Smckusick 				ERROR(EREMOVE, next->pfname);
27*1672Smckusick 				return;
28*1672Smckusick 			}
29*1672Smckusick 		}
30*1672Smckusick 		_actfile[next->fblk] = FILNIL;
31*1672Smckusick 		next = next->fchain;
32*1672Smckusick 	}
33*1672Smckusick 	_fchain.fchain = next;
34*1672Smckusick }
35