rem: if (ostream != stdout && (ferror (ostream) || fclose (ostream) == EOF)) error (EXIT_FAILURE, errno, _("error writing %s"), outfile);
add: if (ostream != stdout) { if (ferror (ostream)) error (EXIT_FAILURE, 0, _("error writing %s"), outfile); if (ostream != stdout && fclose (ostream) != 0) error (EXIT_FAILURE, errno, _("error writing %s"), outfile); }
context: check_file (const char *infile, const char *outfile){  FILE *istream;  FILE *ostream;  struct linebuffer lb1, lb2;  struct linebuffer *thisline, *prevline;  if (STREQ (infile, "-"))    istream = stdin;  else    istream = fopen (infile, "r");  if (istream == NULL)    error (EXIT_FAILURE, errno, "%s", infile);  if (STREQ (outfile, "-"))    ostream = stdout;  else    ostream = fopen (outfile, "w");  if (ostream == NULL)    error (EXIT_FAILURE, errno, "%s", outfile);  thisline = &lb1;  prevline = &lb2;  initbuffer (thisline);  initbuffer (prevline);  /* The duplication in the following `if' and `else' blocks is an     optimization to distinguish the common case (in which none of     the following options has been specified: --count, -repeated,     --all-repeated, --unique) from the others.  In the common case,     this optimization lets uniq output each different line right away,     without waiting to see if the next one is different.  */  if (mode == output_all && countmode == count_none)    {      char *prevfield IF_LINT (= NULL);      size_t prevlen IF_LINT (= 0);      while (!feof (istream))	{	  char *thisfield;	  size_t thislen;	  if (readline (thisline, istream) == 0)	    break;	  thisfield = find_field (thisline);	  thislen = thisline->length - 1 - (thisfield - thisline->buffer);	  if (prevline->length == 0	      || different (thisfield, prevfield, thislen, prevlen))	    {	      fwrite (thisline->buffer, sizeof (char),		      thisline->length, ostream);	      SWAP_LINES (prevline, thisline);	      prevfield = thisfield;	      prevlen = thislen;	    }	}    }  else    {      char *prevfield;      size_t prevlen;      int match_count = 0;      int first_delimiter = 1;      if (readline (prevline, istream) == 0)	goto closefiles;      prevfield = find_field (prevline);      prevlen = prevline->length - 1 - (prevfield - prevline->buffer);      while (!feof (istream))	{	  int match;	  char *thisfield;	  size_t thislen;	  if (readline (thisline, istream) == 0)	    break;	  thisfield = find_field (thisline);	  thislen = thisline->length - 1 - (thisfield - thisline->buffer);	  match = !different (thisfield, prevfield, thislen, prevlen);	  if (match)	    ++match_count;          if (mode == output_all_repeated && delimit_groups != DM_NONE)	    {	      if (!match)		{		  if (match_count) /* a previous match */		    first_delimiter = 0; /* Only used when DM_SEPARATE */		}	      else if (match_count == 1)		{		  if ((delimit_groups == DM_PREPEND)		      || (delimit_groups == DM_SEPARATE			  && !first_delimiter))		    putc ('\n', ostream);		}	    }	  if (!match || mode == output_all_repeated)	    {	      writeline (prevline, ostream, match_count);	      SWAP_LINES (prevline, thisline);	      prevfield = thisfield;	      prevlen = thislen;	      if (!match)		match_count = 0;	    }	}      writeline (prevline, ostream, match_count);    } closefiles:  if (ferror (istream) || fclose (istream) == EOF)    error (EXIT_FAILURE, errno, _("error reading %s"), infile);  /* Close ostream only if it's not stdout -- the latter is closed     via the atexit-invoked close_stdout.  */  if (ostream != stdout && (ferror (ostream) || fclose (ostream) == EOF))    error (EXIT_FAILURE, errno, _("error writing %s"), outfile);  free (lb1.buffer);  free (lb2.buffer);}