From 8c84eba6067d4defd16036df19edb798921513aa Mon Sep 17 00:00:00 2001 From: Kirk McKusick Date: Sun, 11 Jan 1981 01:21:14 -0800 Subject: [PATCH] flush and release buffers before closing files 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 | 4 ++++ usr/src/usr.bin/pascal/libpc/PCLOSE.c | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/usr/src/usr.bin/pascal/libpc/GETNAME.c b/usr/src/usr.bin/pascal/libpc/GETNAME.c index 7b6af555cb..eef3b6450f 100644 --- a/usr/src/usr.bin/pascal/libpc/GETNAME.c +++ b/usr/src/usr.bin/pascal/libpc/GETNAME.c @@ -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); diff --git a/usr/src/usr.bin/pascal/libpc/PCLOSE.c b/usr/src/usr.bin/pascal/libpc/PCLOSE.c index 3bb4198f42..aa1c5aa651 100644 --- a/usr/src/usr.bin/pascal/libpc/PCLOSE.c +++ b/usr/src/usr.bin/pascal/libpc/PCLOSE.c @@ -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); -- 2.20.1