FreeBSD/contrib/subversion/subversion/libsvn_subr/stream.c
/* Handle flushing and closing the stream */
Handle flushing and closing the stream
Handle flushing and closing the stream
static svn_error_t *
close_handler_gz(void *baton)
{
  struct zbaton *btn = baton;
  int zerr;
  if (btn->in != NULL)
    {
      zerr = inflateEnd(btn->in);
      SVN_ERR(svn_error__wrap_zlib(zerr, "inflateEnd", btn->in->msg));
    }
  if (btn->out != NULL)
    {
      void *buf;
      apr_size_t write_len;
      buf = apr_palloc(btn->pool, ZBUFFER_SIZE);
      while (TRUE)
        {
          btn->out->next_out = buf;
          btn->out->avail_out = ZBUFFER_SIZE;
          zerr = deflate(btn->out, Z_FINISH);
          if (zerr != Z_STREAM_END && zerr != Z_OK)
            return svn_error_trace(svn_error__wrap_zlib(zerr, "deflate",
                                                        btn->out->msg));
          write_len = ZBUFFER_SIZE - btn->out->avail_out;
          if (write_len > 0)
            SVN_ERR(svn_stream_write(btn->substream, buf, &write_len));
          if (zerr == Z_STREAM_END)
            break;
        }
      zerr = deflateEnd(btn->out);
      SVN_ERR(svn_error__wrap_zlib(zerr, "deflateEnd", btn->out->msg));
    }
  return svn_error_trace(svn_stream_close(btn->substream));
}
static svn_error_t * close_handler_gz ( void * baton ) { struct zbaton * btn = baton ; int zerr ; if ( btn -> in != NULL ) { zerr = inflateEnd ( btn -> in ) ; SVN_ERR ( svn_error__wrap_zlib ( zerr , " " , btn -> in -> msg ) ) ; } if ( btn -> out != NULL ) { void * buf ; apr_size_t write_len ; buf = apr_palloc ( btn -> pool , ZBUFFER_SIZE ) ; while ( TRUE ) { btn -> out -> next_out = buf ; btn -> out -> avail_out = ZBUFFER_SIZE ; zerr = deflate ( btn -> out , Z_FINISH ) ; if ( zerr != Z_STREAM_END && zerr != Z_OK ) return svn_error_trace ( svn_error__wrap_zlib ( zerr , " " , btn -> out -> msg ) ) ; write_len = ZBUFFER_SIZE - btn -> out -> avail_out ; if ( write_len > 0 ) SVN_ERR ( svn_stream_write ( btn -> substream , buf , & write_len ) ) ; if ( zerr == Z_STREAM_END ) break ; } zerr = deflateEnd ( btn -> out ) ; SVN_ERR ( svn_error__wrap_zlib ( zerr , " " , btn -> out -> msg ) ) ; } return svn_error_trace ( svn_stream_close ( btn -> substream ) ) ; }
Handle flushing and closing the stream
Handle flushing and closing the stream