File: catch_output_errors

package info (click to toggle)
par 1.53.0-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 496 kB
  • sloc: ansic: 2,262; makefile: 11; sh: 1
file content (58 lines) | stat: -rw-r--r-- 1,532 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# 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);