Commit | Line | Data |
---|---|---|
db6d864f KM |
1 | /* Copyright (c) 1979 Regents of the University of California */ |
2 | ||
9ddc2069 | 3 | static char sccsid[] = "@(#)PCLOSE.c 1.3 %G%"; |
db6d864f KM |
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) { | |
8c84eba6 | 18 | if (next->fblk > PREDEF) { |
9ddc2069 | 19 | fflush(next->fbuf); |
8c84eba6 KM |
20 | setbuf(next->fbuf, NULL); |
21 | } | |
db6d864f KM |
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 | } |