~ubuntu-branches/ubuntu/vivid/bc/vivid-proposed

« back to all changes in this revision

Viewing changes to lib/number.c

  • Committer: Bazaar Package Importer
  • Author(s): Ian Jackson
  • Date: 2006-04-04 17:21:02 UTC
  • Revision ID: james.westby@ubuntu.com-20060404172102-64vnydii80rn39jt
Tags: 1.06-19ubuntu1
Make dc notice read and write errors on its input and output.
I grepped for mentions of the strings `putc', `print', `getc', `FILE',
`stdin', `stdout' and `stderr' and added calls to new error-checking
functions unless it was clear from the immediately-surrounding code
that the program was exiting nonzero, or would exit nonzero if the
call failed.  I ignored hits in lib/getopt*, which seems to
pervasively ignore write errors when printing usage messages, in the
hope that these were correct.  I _think_ I got them all.  -iwj.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1767
1767
out_char (int c)
1768
1768
{
1769
1769
  putchar(c);
 
1770
  checkferror_output(stdout);
1770
1771
}
1771
1772
 
1772
1773
 
1776
1777
{
1777
1778
  bc_out_num (num, 10, out_char, 0);
1778
1779
  out_char ('\n');
 
1780
  checkferror_output(stdout);
1779
1781
}
1780
1782
 
1781
1783
 
1790
1792
  printf ("%s=", name);
1791
1793
  for (i=0; i<len; i++) printf ("%c",BCD_CHAR(num[i]));
1792
1794
  printf ("\n");
 
1795
  checkferror_output(stdout);
 
1796
}
 
1797
 
 
1798
 
 
1799
/* check ferror() status and if so die */
 
1800
void
 
1801
checkferror_input (fp)
 
1802
        FILE *fp;
 
1803
{
 
1804
        if (ferror(fp)) {
 
1805
                perror("dc: could not read input file");
 
1806
                exit(EXIT_FAILURE);
 
1807
        }
 
1808
}
 
1809
 
 
1810
void
 
1811
checkferror_output (fp)
 
1812
        FILE *fp;
 
1813
{
 
1814
        if (ferror(fp)) {
 
1815
                perror("dc: could not write output file");
 
1816
                exit(EXIT_FAILURE);
 
1817
        }
1793
1818
}