# This patch adds an output error check when
# the E option is set.
# This patch also modifies the man page to explain why
# the output error checking is not done when E is not set.

--- a/par.1
+++ b/par.1
@@ -1178,14 +1178,18 @@
 error messages begin with \*Qpar\ error:\*U on a line
 by itself.  Error messages concerning command line
 or environment variable syntax are accompanied by
 the same usage message that the help option produces.
 .LP
-Of course, trying to print an error message would be
+Unless the option
+.BI E
+is set, trying to print an error message would be
 futile if an error resulted from an output function, so
 .B par
-doesn't bother doing any error checking on output functions.
+doesn't bother doing any error checking on output functions if
+.BI E
+is 0.
 .SH EXAMPLES
 .de VS
 .RS -.5i
 .LP
 .nf
--- a/par.c
+++ b/par.c
@@ -18,10 +18,11 @@
 #include <locale.h>
 #include <stddef.h>
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #undef NULL
 #define NULL ((void *) 0)
 
 #ifdef DONTFREE
@@ -933,10 +934,15 @@
   if (parinit) free(parinit);
   if (inlines) freelines(inlines);
   if (props) free(props);
   if (outlines) freelines(outlines);
 
+  if (Err == 1) {
+  	if ( fclose(stdout) == EOF )
+	       	sprintf(errmsg,"%.*s\n",errmsg_size,strerror(errno));
+  }
+
   errout = Err ? stderr : stdout;
   if (*errmsg) fprintf(errout, "par error:\n%.*s", errmsg_size, errmsg);
   if (version) fputs("par 1.53.0\n",errout);
   if (help)    fputs(usagemsg,errout);
 
