1 /* Copyright (c) 1982 Regents of the University of California */ 2 3 static char sccsid[] = "@(#)PFCLOSE.c 1.2 (Berkeley) 08/29/82"; 4 5 /* 6 * Close a Pascal file deallocating resources as appropriate. 7 */ 8 9 #include "h00vars.h" 10 #include "libpc.h" 11 12 struct iorec * 13 PFCLOSE(filep) 14 register struct iorec *filep; 15 { 16 if ((filep->funit & FDEF) == 0 && filep->fbuf != NULL) { 17 /* 18 * Have a previous buffer, close associated file. 19 */ 20 if (filep->fblk > PREDEF) { 21 fflush(filep->fbuf); 22 setbuf(filep->fbuf, NULL); 23 } 24 fclose(filep->fbuf); 25 if (ferror(filep->fbuf)) { 26 ERROR("%s: Close failed\n", filep->pfname); 27 return; 28 } 29 /* 30 * Temporary files are discarded. 31 */ 32 if ((filep->funit & TEMP) != 0 && unlink(filep->pfname)) { 33 PERROR("Could not remove ", filep->pfname); 34 return; 35 } 36 } 37 _actfile[filep->fblk] = FILNIL; 38 return (filep->fchain); 39 } 40