[comp.soft-sys.andrew] Eatmail patch

nsb@THUMPER.BELLCORE.COM (Nathaniel Borenstein) (08/01/90)

Craig Everhart kindly & correctly pointed out that the code in eatmail
was copied from cvtold.c BEFORE the recent discovery of the bug in that
code where it wasn't checking the results of writeall().  So here's a
patch for eatmail.c, already.  In eatmail.c, lines 273-285 currently
look like this:

	if (AMS_DemandSeparatingCharacter) {
	    if ((buffer[0] == AMS_SeparatingCharacter) && (AnyWrittenToThisOne
!= 0)) {
		ReadyToStartAgain = 1;
	    } else {
		writeall(wfd, buffer, strlen(buffer));
		AnyWrittenToThisOne = 1;
		ReadyToStartAgain = 0;
	    }
	} else {
	    ReadyToStartAgain = (buffer[0] == '\n') ? 1 : 0;
	    writeall(wfd, buffer, strlen(buffer));
	    AnyWrittenToThisOne = 1;
	}
    }

Replace them with the following, somewhat safer code, which is identical
but checks the return from writeall():

	if (AMS_DemandSeparatingCharacter) {
	    if ((buffer[0] == AMS_SeparatingCharacter) && (AnyWrittenToThisOne
!= 0)) {
		ReadyToStartAgain = 1;
	    } else {
		if (writeall(wfd, buffer, strlen(buffer)) != strlen(buffer)) {
		    errsave = errno;
		    close(wfd);
		    fclose(fp);
		    AMS_RETURN_ERRCODE(errno, EIN_WRITE, EVIA_CONVERTINCOMING);
		}
		AnyWrittenToThisOne = 1;
		ReadyToStartAgain = 0;
	    }
	} else {
	    ReadyToStartAgain = (buffer[0] == '\n') ? 1 : 0;
	    if (writeall(wfd, buffer, strlen(buffer)) != strlen(buffer)) {
		errsave = errno;
		close(wfd);
		fclose(fp);
		AMS_RETURN_ERRCODE(errno, EIN_WRITE, EVIA_CONVERTINCOMING);
	    }
	    AnyWrittenToThisOne = 1;
	}

Sorry for the mistake, which just goes to prove that the comment at the
top of the file is correct -- it really should be modularized to use the
same code that cvtold uses!  -- Nathaniel