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