~ubuntu-branches/ubuntu/utopic/bc/utopic-proposed

« back to all changes in this revision

Viewing changes to debian/patches/05_notice_read_write_errors.diff

  • Committer: Package Import Robot
  • Author(s): Ryan Kavanagh
  • Date: 2013-05-24 07:26:52 UTC
  • Revision ID: package-import@ubuntu.com-20130524072652-i626j061imwvt3ep
Tags: 1.06.95-7
* New maintainer (Closes: #705771)
* Switch to Debian source format 3.0 (quilt)
* Updated copyright file with missing licenses and holders. Now in DEP-5
  format.
* Bump standards version to 3.9.4
* Bump debhelper Build-Dependency to >= 9 and switch from old-style rules
  with manual calls to dh_* to modern style dh rules
* Bump compat level to 9
* Drop libreadline5-dev from Build-Depends, it no longer exists in unstable
* Add a doc-base file for bc
* Fix a typo in bc, 01_typo_in_bc.diff
* Fix hyphens used as minus signs in manpages,
  02_hyphens_as_minus_in_man.diff
* Fix array initialization bug, 03_array_initialize.diff (Closes: #671513,
  #586969)
* Revert all inline patches and introduce them as logical quilt patches
  + Set the info dircategory to Math, 04_info_dircategory.diff
  + Notice read/write errors on input and output,
    05_notice_read_write_errors.diff
* clean target now conforms to Debian Policy §4.9, "must undo any effects
  that the build target may have had [...]"
* Added Vcs-Git/Vcs-Browser entries to debian/control
* Reintroduce the missing 1.06.94-3.1 changelog entry
* Get rid of postinst/postrm files, they were unneeded

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
Description: notice read and write errors on input and output
 
2
 Quoting from the bug report:
 
3
    +bc (1.06-19ubuntu1) dapper; urgency=low
 
4
    +
 
5
    +  * Make dc notice read and write errors on its input and output.
 
6
    +    I grepped for mentions of the strings `putc', `print', `getc', `FILE',
 
7
    +    `stdin', `stdout' and `stderr' and added calls to new error-checking
 
8
    +    functions unless it was clear from the immediately-surrounding code
 
9
    +    that the program was exiting nonzero, or would exit nonzero if the
 
10
    +    call failed.  I ignored hits in lib/getopt*, which seems to
 
11
    +    pervasively ignore write errors when printing usage messages, in the
 
12
    +    hope that these were correct.  I _think_ I got them all.  -iwj.
 
13
    +
 
14
    + -- Ian Jackson <iwj@ubuntu.com>  Tue,  4 Apr 2006 17:21:02 +0100
 
15
Author: Ian Jackson <iwj@ubuntu.com>
 
16
Origin: other
 
17
Bug-Debian: http://bugs.debian.org/488735
 
18
---
 
19
This patch header follows DEP-3: http://dep.debian.net/deps/dep3/
 
20
diff --git a/bc/execute.c b/bc/execute.c
 
21
index e4e8ef7..8787048 100644
 
22
--- a/bc/execute.c
 
23
+++ b/bc/execute.c
 
24
@@ -108,6 +108,7 @@ execute ()
 
25
              }
 
26
            out_char ('\n');
 
27
          }
 
28
+       checkferror_output(stdout);
 
29
       }
 
30
 #endif
 
31
 
 
32
@@ -222,6 +223,7 @@ execute ()
 
33
                }
 
34
            }
 
35
        fflush (stdout);
 
36
+       checkferror_output(stdout);
 
37
        break;
 
38
 
 
39
       case 'R' : /* Return from function */
 
40
@@ -257,6 +259,7 @@ execute ()
 
41
        if (inst == 'W') out_char ('\n');
 
42
        store_var (4);  /* Special variable "last". */
 
43
        fflush (stdout);
 
44
+       checkferror_output(stdout);
 
45
        pop ();
 
46
        break;
 
47
 
 
48
@@ -338,6 +341,7 @@ execute ()
 
49
       case 'w' : /* Write a string to the output. */
 
50
        while ((ch = byte(&pc)) != '"') out_schar (ch);
 
51
        fflush (stdout);
 
52
+       checkferror_output(stdout);
 
53
        break;
 
54
                   
 
55
       case 'x' : /* Exchange Top of Stack with the one under the tos. */
 
56
@@ -545,7 +549,10 @@ execute ()
 
57
     {
 
58
       signal (SIGINT, use_quit);
 
59
       if (had_sigint)
 
60
-       printf ("\ninterrupted execution.\n");
 
61
+       {
 
62
+         printf ("\ninterrupted execution.\n");
 
63
+         checkferror_output(stdout);
 
64
+       }
 
65
     }
 
66
 }
 
67
 
 
68
@@ -580,6 +587,7 @@ input_char ()
 
69
          out_col = 0;  /* Saw a new line */
 
70
        }
 
71
     }
 
72
+  checkferror_input(stdin);
 
73
 
 
74
   /* Classify and preprocess the input character. */
 
75
   if (isdigit(in_ch))
 
76
diff --git a/bc/load.c b/bc/load.c
 
77
index 1035198..4039e86 100644
 
78
--- a/bc/load.c
 
79
+++ b/bc/load.c
 
80
@@ -217,6 +217,7 @@ load_code (code)
 
81
                if (label_no > 65535L)
 
82
                  {  /* Better message? */
 
83
                    fprintf (stderr,"Program too big.\n");
 
84
+                   checkferror_output(stderr);
 
85
                    exit(1);
 
86
                  }
 
87
                addbyte ( (char) (label_no & 0xFF));
 
88
diff --git a/bc/main.c b/bc/main.c
 
89
index 9a2461e..3ae427d 100644
 
90
--- a/bc/main.c
 
91
+++ b/bc/main.c
 
92
@@ -358,6 +358,9 @@ use_quit (sig)
 
93
   errno = save;
 
94
 #else
 
95
   write (1, "\n(interrupt) Exiting bc.\n", 26);
 
96
+#ifdef READLINE
 
97
+  rl_initialize (); /* Clear readline buffer */
 
98
+#endif
 
99
 #if defined(LIBEDIT)
 
100
   if (edit != NULL)
 
101
     el_end(edit);
 
102
diff --git a/bc/sbc.y b/bc/sbc.y
 
103
index 0ded29e..6fcc1fa 100644
 
104
--- a/bc/sbc.y
 
105
+++ b/bc/sbc.y
 
106
@@ -86,7 +86,9 @@ program                       : /* empty */
 
107
                              if (interactive && !quiet)
 
108
                                {
 
109
                                  show_bc_version ();
 
110
+                                 checkferror_output(stdout);
 
111
                                  welcome ();
 
112
+                                 checkferror_output(stdout);
 
113
                                }
 
114
                            }
 
115
                        | program input_item
 
116
diff --git a/bc/scan.c b/bc/scan.c
 
117
index 1f78ec2..2b5eeb4 100644
 
118
--- a/bc/scan.c
 
119
+++ b/bc/scan.c
 
120
@@ -799,6 +799,7 @@ bcel_input (buf, result, max)
 
121
       if (bcel_len != 0)
 
122
        history (hist, &histev, H_ENTER, bcel_line); 
 
123
       fflush (stdout);
 
124
+      checkferror_output(stdout);
 
125
     }
 
126
 
 
127
   if (bcel_len <= max)
 
128
@@ -874,6 +875,7 @@ rl_input (buf, result, max)
 
129
        add_history (rl_line); 
 
130
       rl_line[rl_len-1] = '\n';
 
131
       fflush (stdout);
 
132
+      checkferror_output(stdout);
 
133
     }
 
134
 
 
135
   if (rl_len <= max)
 
136
diff --git a/bc/scan.l b/bc/scan.l
 
137
index 841c3df..16cd62e 100644
 
138
--- a/bc/scan.l
 
139
+++ b/bc/scan.l
 
140
@@ -111,6 +111,7 @@ bcel_input (buf, result, max)
 
141
       if (bcel_len != 0)
 
142
        history (hist, &histev, H_ENTER, bcel_line); 
 
143
       fflush (stdout);
 
144
+      checkferror_output(stdout);
 
145
     }
 
146
 
 
147
   if (bcel_len <= max)
 
148
@@ -186,6 +187,7 @@ rl_input (buf, result, max)
 
149
        add_history (rl_line); 
 
150
       rl_line[rl_len-1] = '\n';
 
151
       fflush (stdout);
 
152
+      checkferror_output(stdout);
 
153
     }
 
154
 
 
155
   if (rl_len <= max)
 
156
@@ -310,6 +312,7 @@ limits return(Limits);
 
157
            if (c == EOF)
 
158
              {
 
159
                fprintf (stderr,"EOF encountered in a comment.\n");
 
160
+                checkferror_output(stderr);
 
161
                break;
 
162
              }
 
163
          }
 
164
diff --git a/bc/storage.c b/bc/storage.c
 
165
index 699729a..37b4c6c 100644
 
166
--- a/bc/storage.c
 
167
+++ b/bc/storage.c
 
168
@@ -99,6 +99,7 @@ more_functions (VOID)
 
169
     {
 
170
       f = &functions[indx];
 
171
       f->f_defined = FALSE;
 
172
+      f->f_void = FALSE;
 
173
       f->f_body = (char *) bc_malloc (BC_START_SIZE);
 
174
       f->f_body_size = BC_START_SIZE;
 
175
       f->f_code_size = 0;
 
176
diff --git a/bc/util.c b/bc/util.c
 
177
index 30beaf9..669235f 100644
 
178
--- a/bc/util.c
 
179
+++ b/bc/util.c
 
180
@@ -260,9 +260,10 @@ init_gen ()
 
181
   continue_label = 0;
 
182
   next_label  = 1;
 
183
   out_count = 2;
 
184
-  if (compile_only) 
 
185
+  if (compile_only) {
 
186
     printf ("@i");
 
187
-  else
 
188
+    checkferror_output(stdout);
 
189
+  } else
 
190
     init_load ();
 
191
   had_error = FALSE;
 
192
   did_gen = FALSE;
 
193
@@ -286,6 +287,7 @@ generate (str)
 
194
          printf ("\n");
 
195
          out_count = 0;
 
196
        }
 
197
+      checkferror_output(stdout);
 
198
     }
 
199
   else
 
200
     load_code (str);
 
201
@@ -303,6 +305,7 @@ run_code()
 
202
       if (compile_only)
 
203
        {
 
204
          printf ("@r\n"); 
 
205
+         checkferror_output(stdout);
 
206
          out_count = 0;
 
207
        }
 
208
       else
 
209
@@ -341,6 +344,7 @@ out_char (ch)
 
210
        }
 
211
       putchar (ch);
 
212
     }
 
213
+  checkferror_output(stdout);
 
214
 }
 
215
 
 
216
 /* Output routines: Write a character CH to the standard output.
 
217
@@ -371,6 +375,7 @@ out_schar (ch)
 
218
        }
 
219
       putchar (ch);
 
220
     }
 
221
+  checkferror_output(stdout);
 
222
 }
 
223
 
 
224
 
 
225
@@ -657,6 +662,7 @@ limits()
 
226
 #ifdef OLD_EQ_OP
 
227
   printf ("Old assignment operatiors are valid. (=-, =+, ...)\n");
 
228
 #endif 
 
229
+  checkferror_output(stdout);
 
230
 }
 
231
 
 
232
 /* bc_malloc will check the return value so all other places do not
 
233
@@ -721,6 +727,7 @@ yyerror (str, va_alist)
 
234
   fprintf (stderr,"%s %d: ",name,line_no);
 
235
   vfprintf (stderr, str, args);
 
236
   fprintf (stderr, "\n");
 
237
+  checkferror_output(stderr);
 
238
   had_error = TRUE;
 
239
   va_end (args);
 
240
 }
 
241
@@ -761,6 +768,7 @@ warn (mesg, va_alist)
 
242
       fprintf (stderr,"%s %d: Error: ",name,line_no);
 
243
       vfprintf (stderr, mesg, args);
 
244
       fprintf (stderr, "\n");
 
245
+      checkferror_output(stderr);
 
246
       had_error = TRUE;
 
247
     }
 
248
   else
 
249
@@ -773,6 +781,7 @@ warn (mesg, va_alist)
 
250
        fprintf (stderr,"%s %d: (Warning) ",name,line_no);
 
251
        vfprintf (stderr, mesg, args);
 
252
        fprintf (stderr, "\n");
 
253
+       checkferror_output(stderr);
 
254
       }
 
255
   va_end (args);
 
256
 }
 
257
@@ -807,6 +816,7 @@ rt_error (mesg, va_alist)
 
258
   va_end (args);
 
259
   
 
260
   fprintf (stderr, "\n");
 
261
+  checkferror_output(stderr);
 
262
   runtime_error = TRUE;
 
263
 }
 
264
 
 
265
@@ -843,4 +853,5 @@ rt_warn (mesg, va_alist)
 
266
   va_end (args);
 
267
 
 
268
   fprintf (stderr, "\n");
 
269
+  checkferror_output(stderr);
 
270
 }
 
271
diff --git a/dc/dc.c b/dc/dc.c
 
272
index e03f094..0faf03a 100644
 
273
--- a/dc/dc.c
 
274
+++ b/dc/dc.c
 
275
@@ -61,6 +61,7 @@ static void
 
276
 bug_report_info DC_DECLVOID()
 
277
 {
 
278
        printf("Email bug reports to:  bug-dc@gnu.org .\n");
 
279
+       checkferror_output(stdout);
 
280
 }
 
281
 
 
282
 static void
 
283
@@ -71,6 +72,7 @@ show_version DC_DECLVOID()
 
284
 This is free software; see the source for copying conditions.  There is NO\n\
 
285
 warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE,\n\
 
286
 to the extent permitted by law.\n", DC_COPYRIGHT);
 
287
+       checkferror_output(stdout);
 
288
 }
 
289
 
 
290
 /* your generic usage function */
 
291
@@ -87,6 +89,7 @@ Usage: %s [OPTION] [file ...]\n\
 
292
 \n\
 
293
 ", progname);
 
294
        bug_report_info();
 
295
+       checkferror_output(f);
 
296
 }
 
297
 
 
298
 /* returns a pointer to one past the last occurance of c in s,
 
299
diff --git a/dc/eval.c b/dc/eval.c
 
300
index 4af7200..153d331 100644
 
301
--- a/dc/eval.c
 
302
+++ b/dc/eval.c
 
303
@@ -94,12 +94,15 @@ static int input_pushback;
 
304
 static int
 
305
 input_fil DC_DECLVOID()
 
306
 {
 
307
+        int c;
 
308
        if (input_pushback != EOF){
 
309
-               int c = input_pushback;
 
310
+               c = input_pushback;
 
311
                input_pushback = EOF;
 
312
                return c;
 
313
        }
 
314
-       return getc(input_fil_fp);
 
315
+       c = getc(input_fil_fp);
 
316
+       checkferror_input(input_fil_fp);
 
317
+       return c;
 
318
 }
 
319
 
 
320
 /* passed as an argument to dc_getnum */
 
321
@@ -298,11 +301,13 @@ dc_func DC_DECLARG((c, peekc, negcmp))
 
322
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
 
323
                        if (2 <= tmpint  &&  tmpint <= DC_IBASE_MAX)
 
324
                                dc_ibase = tmpint;
 
325
-                       else
 
326
+                       else {
 
327
                                fprintf(stderr,
 
328
                                                "%s: input base must be a number \
 
329
 between 2 and %d (inclusive)\n",
 
330
                                                progname, DC_IBASE_MAX);
 
331
+                               checkferror_output(stderr);
 
332
+                       }
 
333
                }
 
334
                break;
 
335
        case 'k':       /* set scale to value on top of stack */
 
336
@@ -310,11 +315,12 @@ between 2 and %d (inclusive)\n",
 
337
                        tmpint = -1;
 
338
                        if (datum.dc_type == DC_NUMBER)
 
339
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
 
340
-                       if ( ! (tmpint >= 0) )
 
341
+                       if ( ! (tmpint >= 0) ) {
 
342
                                fprintf(stderr,
 
343
                                                "%s: scale must be a nonnegative number\n",
 
344
                                                progname);
 
345
-                       else
 
346
+                               checkferror_output(stderr);
 
347
+                       } else
 
348
                                dc_scale = tmpint;
 
349
                }
 
350
                break;
 
351
@@ -338,11 +344,12 @@ between 2 and %d (inclusive)\n",
 
352
                        tmpint = 0;
 
353
                        if (datum.dc_type == DC_NUMBER)
 
354
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
 
355
-                       if ( ! (tmpint > 1) )
 
356
+                       if ( ! (tmpint > 1) ) {
 
357
                                fprintf(stderr,
 
358
                                                "%s: output base must be a number greater than 1\n",
 
359
                                                progname);
 
360
-                       else
 
361
+                               checkferror_output(stderr);
 
362
+                       } else
 
363
                                dc_obase = tmpint;
 
364
                }
 
365
                break;
 
366
@@ -383,6 +390,7 @@ between 2 and %d (inclusive)\n",
 
367
                                fprintf(stderr,
 
368
                                                "%s: square root of nonnumeric attempted\n",
 
369
                                                progname);
 
370
+                               checkferror_output(stderr);
 
371
                        }else if (dc_sqrt(datum.v.number, dc_scale, &tmpnum) == DC_SUCCESS){
 
372
                                dc_free_num(&datum.v.number);
 
373
                                datum.v.number = tmpnum;
 
374
@@ -444,6 +452,7 @@ between 2 and %d (inclusive)\n",
 
375
                        fprintf(stderr,
 
376
                                        "%s: Q command requires a number >= 1\n",
 
377
                                        progname);
 
378
+                       checkferror_output(stderr);
 
379
                }
 
380
                break;
 
381
 #if 0
 
382
@@ -489,11 +498,12 @@ between 2 and %d (inclusive)\n",
 
383
                        if (datum.dc_type == DC_NUMBER)
 
384
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
 
385
                        if (dc_pop(&datum) == DC_SUCCESS){
 
386
-                               if (tmpint < 0)
 
387
+                               if (tmpint < 0) {
 
388
                                        fprintf(stderr,
 
389
                                                        "%s: array index must be a nonnegative integer\n",
 
390
                                                        progname);
 
391
-                               else
 
392
+                                       checkferror_output(stderr);
 
393
+                               } else
 
394
                                        dc_array_set(peekc, tmpint, datum);
 
395
                        }
 
396
                }
 
397
@@ -505,17 +515,19 @@ between 2 and %d (inclusive)\n",
 
398
                        tmpint = -1;
 
399
                        if (datum.dc_type == DC_NUMBER)
 
400
                                tmpint = dc_num2int(datum.v.number, DC_TOSS);
 
401
-                       if (tmpint < 0)
 
402
+                       if (tmpint < 0) {
 
403
                                fprintf(stderr,
 
404
                                                "%s: array index must be a nonnegative integer\n",
 
405
                                                progname);
 
406
-                       else
 
407
+                               checkferror_output(stderr);
 
408
+                       } else
 
409
                                dc_push(dc_array_get(peekc, tmpint));
 
410
                }
 
411
                return DC_EATONE;
 
412
 
 
413
        default:        /* What did that user mean? */
 
414
                fprintf(stderr, "%s: ", progname);
 
415
+               checkferror_output(stderr);
 
416
                dc_show_id(stdout, c, " unimplemented\n");
 
417
                break;
 
418
        }
 
419
@@ -544,6 +556,7 @@ dc_evalstr DC_DECLARG((string))
 
420
                fprintf(stderr,
 
421
                                "%s: eval called with non-string argument\n",
 
422
                                progname);
 
423
+               checkferror_output(stderr);
 
424
                return DC_OKAY;
 
425
        }
 
426
        interrupt_seen = 0;
 
427
@@ -640,6 +653,7 @@ dc_evalstr DC_DECLARG((string))
 
428
                                return DC_FAIL;
 
429
                        }
 
430
                        fprintf(stderr, "%s: unexpected EOS\n", progname);
 
431
+                       checkferror_output(stderr);
 
432
                        return DC_OKAY;
 
433
                }
 
434
        }
 
435
@@ -665,6 +679,7 @@ dc_evalfile DC_DECLARG((fp))
 
436
        stdin_lookahead = EOF;
 
437
        for (c=getc(fp); c!=EOF; c=peekc){
 
438
                peekc = getc(fp);
 
439
+               checkferror_input(stdin);
 
440
                /*
 
441
                 * The following if() is the only place where ``stdin_lookahead''
 
442
                 * might be set to other than EOF:
 
443
@@ -716,6 +731,7 @@ dc_evalfile DC_DECLARG((fp))
 
444
                                                        return DC_SUCCESS;
 
445
                                                fprintf(stderr, "%s: Q command argument exceeded \
 
446
 string execution depth\n", progname);
 
447
+                                               checkferror_output(stderr);
 
448
                                        }
 
449
                                }else{
 
450
                                        dc_garbage("at top of stack", -1);
 
451
@@ -728,8 +744,11 @@ string execution depth\n", progname);
 
452
                        fprintf(stderr,
 
453
                                        "%s: Q command argument exceeded string execution depth\n",
 
454
                                        progname);
 
455
-                       if (stdin_lookahead != peekc  &&  fp == stdin)
 
456
+                       checkferror_output(stderr);
 
457
+                       if (stdin_lookahead != peekc  &&  fp == stdin) {
 
458
                                peekc = getc(fp);
 
459
+                               checkferror_input(stdin);
 
460
+                       }
 
461
                        break;
 
462
 
 
463
                case DC_INT:
 
464
@@ -771,6 +790,7 @@ string execution depth\n", progname);
 
465
                        if (ferror(fp))
 
466
                                goto error_fail;
 
467
                        fprintf(stderr, "%s: unexpected EOF\n", progname);
 
468
+                       checkferror_output(stderr);
 
469
                        return DC_FAIL;
 
470
                }
 
471
        }
 
472
diff --git a/dc/misc.c b/dc/misc.c
 
473
index f2388b0..1be56fe 100644
 
474
--- a/dc/misc.c
 
475
+++ b/dc/misc.c
 
476
@@ -91,6 +91,7 @@ dc_show_id DC_DECLARG((fp, id, suffix))
 
477
                fprintf(fp, "'%c' (%#o)%s", (unsigned int) id, id, suffix);
 
478
        else
 
479
                fprintf(fp, "%#o%s", (unsigned int) id, suffix);
 
480
+       checkferror_output(fp);
 
481
 }
 
482
 
 
483
 
 
484
diff --git a/dc/numeric.c b/dc/numeric.c
 
485
index 8e5e70f..c875eba 100644
 
486
--- a/dc/numeric.c
 
487
+++ b/dc/numeric.c
 
488
@@ -134,6 +134,7 @@ dc_div DC_DECLARG((a, b, kscale, result))
 
489
        bc_init_num(CastNumPtr(result));
 
490
        if (bc_divide(CastNum(a), CastNum(b), CastNumPtr(result), kscale)){
 
491
                fprintf(stderr, "%s: divide by zero\n", progname);
 
492
+               checkferror_output(stderr);
 
493
                return DC_DOMAIN_ERROR;
 
494
        }
 
495
        return DC_SUCCESS;
 
496
@@ -156,6 +157,7 @@ dc_divrem DC_DECLARG((a, b, kscale, quotient, remainder))
 
497
        if (bc_divmod(CastNum(a), CastNum(b),
 
498
                                                CastNumPtr(quotient), CastNumPtr(remainder), kscale)){
 
499
                fprintf(stderr, "%s: divide by zero\n", progname);
 
500
+               checkferror_output(stderr);
 
501
                return DC_DOMAIN_ERROR;
 
502
        }
 
503
        return DC_SUCCESS;
 
504
@@ -174,6 +176,7 @@ dc_rem DC_DECLARG((a, b, kscale, result))
 
505
        bc_init_num(CastNumPtr(result));
 
506
        if (bc_modulo(CastNum(a), CastNum(b), CastNumPtr(result), kscale)){
 
507
                fprintf(stderr, "%s: remainder by zero\n", progname);
 
508
+               checkferror_output(stderr);
 
509
                return DC_DOMAIN_ERROR;
 
510
        }
 
511
        return DC_SUCCESS;
 
512
@@ -226,6 +229,7 @@ dc_sqrt DC_DECLARG((value, kscale, result))
 
513
        tmp = bc_copy_num(CastNum(value));
 
514
        if (!bc_sqrt(&tmp, kscale)){
 
515
                fprintf(stderr, "%s: square root of negative number\n", progname);
 
516
+               checkferror_output(stderr);
 
517
                bc_free_num(&tmp);
 
518
                return DC_DOMAIN_ERROR;
 
519
        }
 
520
@@ -429,8 +433,10 @@ dc_out_num DC_DECLARG((value, obase, newline_p, discard_p))
 
521
 {
 
522
        out_char('\0'); /* clear the column counter */
 
523
        bc_out_num(CastNum(value), obase, out_char, 0);
 
524
-       if (newline_p == DC_WITHNL)
 
525
+       if (newline_p == DC_WITHNL) {
 
526
                putchar ('\n');
 
527
+               checkferror_output(stdout);
 
528
+       }
 
529
        if (discard_p == DC_TOSS)
 
530
                dc_free_num(&value);
 
531
 }
 
532
@@ -475,6 +481,7 @@ dc_dump_num DC_DECLARG((dcvalue, discard_p))
 
533
 
 
534
        for (cur=top_of_stack; cur; cur=next) {
 
535
                putchar(cur->digit);
 
536
+               checkferror_output(stdout);
 
537
                next = cur->link;
 
538
                free(cur);
 
539
        }
 
540
@@ -592,6 +599,7 @@ out_char (ch)
 
541
                        out_col = 1;
 
542
                }
 
543
                putchar(ch);
 
544
+               checkferror_output(stderr);
 
545
        }
 
546
 }
 
547
 
 
548
@@ -631,6 +639,7 @@ rt_error (mesg, va_alist)
 
549
        vfprintf (stderr, mesg, args);
 
550
        va_end (args);
 
551
        fprintf (stderr, "\n");
 
552
+       checkferror_output(stderr);
 
553
 }
 
554
 
 
555
 
 
556
@@ -664,6 +673,7 @@ rt_warn (mesg, va_alist)
 
557
        vfprintf (stderr, mesg, args);
 
558
        va_end (args);
 
559
        fprintf (stderr, "\n");
 
560
+       checkferror_output(stderr);
 
561
 }
 
562
 
 
563
 
 
564
diff --git a/dc/stack.c b/dc/stack.c
 
565
index 0730e9c..5db3975 100644
 
566
--- a/dc/stack.c
 
567
+++ b/dc/stack.c
 
568
@@ -38,7 +38,10 @@
 
569
 #include "dc-regdef.h"
 
570
 
 
571
 /* an oft-used error message: */
 
572
-#define Empty_Stack    fprintf(stderr, "%s: stack empty\n", progname)
 
573
+#define Empty_Stack do{                                        \
 
574
+    fprintf(stderr, "%s: stack empty\n", progname);    \
 
575
+    checkferror_output(stderr);                                \
 
576
+  }while(0)
 
577
 
 
578
 
 
579
 /* simple linked-list implementation suffices: */
 
580
@@ -94,6 +97,7 @@ dc_binop DC_DECLARG((op, kscale))
 
581
        if (dc_stack->value.dc_type!=DC_NUMBER
 
582
                        || dc_stack->link->value.dc_type!=DC_NUMBER){
 
583
                fprintf(stderr, "%s: non-numeric value\n", progname);
 
584
+               checkferror_output(stderr);
 
585
                return;
 
586
        }
 
587
        (void)dc_pop(&b);
 
588
@@ -134,6 +138,7 @@ dc_binop2 DC_DECLARG((op, kscale))
 
589
        if (dc_stack->value.dc_type!=DC_NUMBER
 
590
                        || dc_stack->link->value.dc_type!=DC_NUMBER){
 
591
                fprintf(stderr, "%s: non-numeric value\n", progname);
 
592
+               checkferror_output(stderr);
 
593
                return;
 
594
        }
 
595
        (void)dc_pop(&b);
 
596
@@ -172,6 +177,7 @@ dc_cmpop DC_DECLVOID()
 
597
        if (dc_stack->value.dc_type!=DC_NUMBER
 
598
                        || dc_stack->link->value.dc_type!=DC_NUMBER){
 
599
                fprintf(stderr, "%s: non-numeric value\n", progname);
 
600
+               checkferror_output(stderr);
 
601
                return 0;
 
602
        }
 
603
        (void)dc_pop(&b);
 
604
@@ -209,6 +215,7 @@ dc_triop DC_DECLARG((op, kscale))
 
605
                        || dc_stack->link->value.dc_type!=DC_NUMBER
 
606
                        || dc_stack->link->link->value.dc_type!=DC_NUMBER){
 
607
                fprintf(stderr, "%s: non-numeric value\n", progname);
 
608
+               checkferror_output(stderr);
 
609
                return;
 
610
        }
 
611
        (void)dc_pop(&c);
 
612
@@ -327,6 +334,7 @@ dc_register_get DC_DECLARG((regid, result))
 
613
        r = dc_register[regid];
 
614
        if (r==NULL || r->value.dc_type==DC_UNINITIALIZED){
 
615
                fprintf(stderr, "%s: register ", progname);
 
616
+               checkferror_output(stderr);
 
617
                dc_show_id(stderr, regid, " is empty\n");
 
618
                return DC_FAIL;
 
619
        }
 
620
@@ -401,6 +409,7 @@ dc_register_pop DC_DECLARG((stackid, result))
 
621
        r = dc_register[stackid];
 
622
        if (r == NULL){
 
623
                fprintf(stderr, "%s: stack register ", progname);
 
624
+               checkferror_output(stderr);
 
625
                dc_show_id(stderr, stackid, " is empty\n");
 
626
                return DC_FAIL;
 
627
        }
 
628
diff --git a/dc/string.c b/dc/string.c
 
629
index ff1e7f1..e24092d 100644
 
630
--- a/dc/string.c
 
631
+++ b/dc/string.c
 
632
@@ -101,6 +101,7 @@ dc_out_str DC_DECLARG((value, newline, discard_flag))
 
633
        fwrite(value->s_ptr, value->s_len, sizeof *value->s_ptr, stdout);
 
634
        if (newline == DC_WITHNL)
 
635
                putchar('\n');
 
636
+       checkferror_output(stdout);
 
637
        if (discard_flag == DC_TOSS)
 
638
                dc_free_str(&value);
 
639
 }
 
640
@@ -176,6 +177,7 @@ dc_readstring DC_DECLARG((fp, ldelim, rdelim))
 
641
                }
 
642
                *p++ = c;
 
643
        }
 
644
+       checkferror_input(fp);
 
645
        return dc_makestring(line_buf, (size_t)(p-line_buf));
 
646
 }
 
647
 
 
648
diff --git a/h/number.h b/h/number.h
 
649
index 9b034b6..3a00a92 100644
 
650
--- a/h/number.h
 
651
+++ b/h/number.h
 
652
@@ -150,4 +150,7 @@ _PROTOTYPE(int bc_sqrt, (bc_num *num, int scale));
 
653
 _PROTOTYPE(void bc_out_num, (bc_num num, int o_base, void (* out_char)(int),
 
654
                             int leading_zero));
 
655
 
 
656
+_PROTOTYPE(void checkferror_input, (FILE*));
 
657
+_PROTOTYPE(void checkferror_output, (FILE*));
 
658
+
 
659
 #endif
 
660
diff --git a/lib/number.c b/lib/number.c
 
661
index e211840..4d3ce46 100644
 
662
--- a/lib/number.c
 
663
+++ b/lib/number.c
 
664
@@ -1776,6 +1776,7 @@ static void
 
665
 out_char (int c)
 
666
 {
 
667
   putchar(c);
 
668
+  checkferror_output(stdout);
 
669
 }
 
670
 
 
671
 
 
672
@@ -1785,6 +1786,7 @@ pn (num)
 
673
 {
 
674
   bc_out_num (num, 10, out_char, 0);
 
675
   out_char ('\n');
 
676
+  checkferror_output(stdout);
 
677
 }
 
678
 
 
679
 
 
680
@@ -1799,6 +1801,28 @@ pv (name, num, len)
 
681
   printf ("%s=", name);
 
682
   for (i=0; i<len; i++) printf ("%c",BCD_CHAR(num[i]));
 
683
   printf ("\n");
 
684
+  checkferror_output(stdout);
 
685
 }
 
686
 
 
687
 #endif
 
688
+
 
689
+/* check ferror() status and if so die */
 
690
+void
 
691
+checkferror_input (fp)
 
692
+       FILE *fp;
 
693
+{
 
694
+       if (ferror(fp)) {
 
695
+               perror("dc: could not read input file");
 
696
+               exit(EXIT_FAILURE);
 
697
+       }
 
698
+}
 
699
+
 
700
+void
 
701
+checkferror_output (fp)
 
702
+       FILE *fp;
 
703
+{
 
704
+       if (ferror(fp)) {
 
705
+               perror("dc: could not write output file");
 
706
+               exit(EXIT_FAILURE);
 
707
+       }
 
708
+}