***************
*** 1,4
! /* Copyright (C) 1989, 2000 Aladdin Enterprises.  All rights reserved.
    
    This file is part of AFPL Ghostscript.
    
--- 1,4 -----
! /* Copyright (C) 1989, 2000, 2001 Aladdin Enterprises.  All rights reserved.
    
    This file is part of AFPL Ghostscript.
    
***************
*** 472,483 ****
  zflush(i_ctx_t *i_ctx_p)
  {
      stream *s;
      int code = zget_stdout(i_ctx_p, &s);
  
      if (code < 0)
  	return code;
!     sflush(s);
!     return 0;
  }
  
  /* <file> flushfile - */
--- 472,493 ----
  zflush(i_ctx_t *i_ctx_p)
  {
      stream *s;
+     int status;
+     ref rstdout;
      int code = zget_stdout(i_ctx_p, &s);
  
      if (code < 0)
  	return code;
! 
!     make_stream_file(&rstdout, s, "w");
!     status = sflush(s);
!     if (status == 0 || status == EOFC) {
! 	return 0;
!     }
!     return
! 	(s_is_writing(s) ?
! 	 handle_write_status(i_ctx_p, status, &rstdout, NULL, zflush) :
! 	 handle_read_status(i_ctx_p, status, &rstdout, NULL, zflush));
  }
  
  /* <file> flushfile - */
***************
*** 688,694 ****
  	    s_process_read_buf(s);
  	    continue;
  	default:
! 	    return handle_read_status(i_ctx_p, status, op - 1, &rlen,
  				      zpeekstring);
  	}
  	break;
--- 698,704 ----
  	    s_process_read_buf(s);
  	    continue;
  	default:
! 	    return handle_read_status(i_ctx_p, status, op - 1, NULL,
  				      zpeekstring);
  	}
  	break;
