flush and release buffers before closing files
authorKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Sun, 11 Jan 1981 09:21:14 +0000 (01:21 -0800)
committerKirk McKusick <mckusic@ucbvax.Berkeley.EDU>
Sun, 11 Jan 1981 09:21:14 +0000 (01:21 -0800)
SCCS-vsn: usr.bin/pascal/libpc/GETNAME.c 1.2
SCCS-vsn: usr.bin/pascal/libpc/PCLOSE.c 1.2

usr/src/usr.bin/pascal/libpc/GETNAME.c
usr/src/usr.bin/pascal/libpc/PCLOSE.c

index 7b6af55..eef3b64 100644 (file)
@@ -77,6 +77,10 @@ GETNAME(filep, name, maxnamlen, datasize)
                        /*
                         * have a previous buffer, close associated file
                         */
+                       if (filep->fblk > PREDEF) {
+                               fflush(filep->fbuf);
+                               setbuf(filep->fbuf, NULL);
+                       }
                        fclose(filep->fbuf);
                        if (ferror(filep->fbuf)) {
                                ERROR(ECLOSE, filep->pfname);
index 3bb4198..aa1c5aa 100644 (file)
@@ -15,6 +15,10 @@ PCLOSE(level)
        while(next != FILNIL && next->flev <= level) {
                if (next->fbuf != 0) {
                        if ((next->funit & FDEF) == 0) {
+                               if (next->fblk > PREDEF) {
+                                       fflush(next->fblk);
+                                       setbuf(next->fbuf, NULL);
+                               }
                                fclose(next->fbuf);
                                if (ferror(next->fbuf)) {
                                        ERROR(ECLOSE, next->pfname);