[comp.sources.bugs] small addition to mg2a BSD fileio.c

paul@dulcimer.cis.ohio-state.edu (Paul Placeway) (06/19/88)

At Ohio State, we run a lot of Suns out here, and soft mount most of
the file systems.  When a server goes down, the only way the programs
can tell is by the return values on the system calls and libraries.

Mg 1b didn't check the return values enough, so I ruggedized mg2a when
I installed it; the only change is to ffclose() of fileio.c.  If a
small (< BUFSIZ) file is written, write errors will only be discovered
by ffwopen() and ffclose().  ffwopen() already checked things enough,
but ffclose() didn't.  Also, some routines ignoreed the return value
of ffclose when they should't have.  The diffs follow...

		- Paul Placeway
		  paul@tut.cis.ohio-state.edu
		  ...!osu-cis!cis.ohio-state.edu!paul

=======================CUT HERE==================
Index: extend.c
*** extend.c.2a	Sat Jun 18 11:45:41 1988
--- extend.c	Sat Jun 18 13:19:37 1988
***************
*** 529,534
  load(fname) char *fname; {
  	int	s = TRUE;
  	int	nbytes;
  	char	excbuf[128];
  
  	if ((fname = adjustname(fname)) == NULL)

--- 529,535 -----
  load(fname) char *fname; {
  	int	s = TRUE;
  	int	nbytes;
+ 	int	z;
  	char	excbuf[128];
  
  	if ((fname = adjustname(fname)) == NULL)
***************
*** 543,549
  			break;
  		}
  	}
! 	(VOID) ffclose();
  	excbuf[nbytes] = '\0';
  	if(s!=FIOEOF || (nbytes && excline(excbuf)!=TRUE))
  		return FALSE;

--- 544,550 -----
  			break;
  		}
  	}
! 	z = ffclose();		/* save the return value, test in a bit */
  	excbuf[nbytes] = '\0';
  	if(s!=FIOEOF || (nbytes && excline(excbuf)!=TRUE) || (z != FIOSUC))
  		return FALSE;
***************
*** 545,551
  	}
  	(VOID) ffclose();
  	excbuf[nbytes] = '\0';
! 	if(s!=FIOEOF || (nbytes && excline(excbuf)!=TRUE))
  		return FALSE;
  	return TRUE;
  }

--- 546,552 -----
  	}
  	z = ffclose();		/* save the return value, test in a bit */
  	excbuf[nbytes] = '\0';
! 	if(s!=FIOEOF || (nbytes && excline(excbuf)!=TRUE) || (z != FIOSUC))
  		return FALSE;
  	return TRUE;
  }
Index: file.c
*** file.c.2a	Sat Jun 18 13:23:54 1988
--- file.c	Sat Jun 18 13:24:31 1988
***************
*** 249,255
  	    }
  	}
  endoffile:
! 	(VOID) ffclose();			/* Ignore errors.	*/
  	if (s==FIOEOF) {			/* Don't zap an error.	*/
  		if (nline == 1) ewprintf("(Read 1 line)");
  		else		ewprintf("(Read %d lines)", nline);

--- 249,256 -----
  	    }
  	}
  endoffile:
! 	if (ffclose() != FIOSUC)		/* PWP: DON'T Ignore errors. */
! 	    s = FIOERR;
  	if (s==FIOEOF) {			/* Don't zap an error.	*/
  		if (nline == 1) ewprintf("(Read 1 line)");
  		else		ewprintf("(Read %d lines)", nline);
Index: sys/bsd/fileio.c
*** sys/bsd/fileio.c.2a	Sat Jun 18 12:50:33 1988
--- sys/bsd/fileio.c	Sat Jun 18 13:16:37 1988
***************
*** 31,37
  
  /*
   * Close a file.
!  * Should look at the status.
   */
  ffclose() {
  	(VOID) fclose(ffp);

--- 31,37 -----
  
  /*
   * Close a file.
!  * Should look at the status.  PWP: it does now.
   */
  ffclose() {
  	if (fclose(ffp) != 0) {
***************
*** 34,40
   * Should look at the status.
   */
  ffclose() {
! 	(VOID) fclose(ffp);
  	return (FIOSUC);
  }
  

--- 34,43 -----
   * Should look at the status.  PWP: it does now.
   */
  ffclose() {
! 	if (fclose(ffp) != 0) {
! 		ewprintf("Error closing file");
! 		return (FIOERR);
! 	}
  	return (FIOSUC);
  }