]> cygwin.com Git - cygwin-apps/setup.git/blobdiff - compress_xz.cc
Regenerate resources with updated translation
[cygwin-apps/setup.git] / compress_xz.cc
index 1480c6ce9fa72a63190d91d74c23de87d805bc17..b91c8a44ab9721e819f511e3943ea83823d961ce 100644 (file)
@@ -21,7 +21,7 @@
 #include "LogSingleton.h"
 
 #include <stdexcept>
-using namespace std;
+
 #include <errno.h>
 #include <memory.h>
 #include <malloc.h>
@@ -51,9 +51,6 @@ compress_xz::compress_xz (io_stream * parent)
   lasterr(0),
   compression_type (COMPRESSION_UNKNOWN)
 {
-  unsigned char * out_block = NULL;
-  unsigned char * in_block = NULL;
-
   /* read only */
   if (!parent || parent->error())
     {
@@ -62,6 +59,16 @@ compress_xz::compress_xz (io_stream * parent)
     }
   original = parent;
 
+  create ();
+  init_decoder ();
+}
+
+void
+compress_xz::create ()
+{
+  unsigned char * out_block = NULL;
+  unsigned char * in_block = NULL;
+
   state = (struct private_data *)calloc(sizeof(*state), 1);
   out_block = (unsigned char *)malloc(out_block_size);
   in_block = (unsigned char *)malloc(in_block_size);
@@ -79,12 +86,10 @@ compress_xz::compress_xz (io_stream * parent)
   state->out_block = out_block;
   state->in_block_size = in_block_size;
   state->in_block = in_block;
-  state->out_p = out_block;
+  state->out_p = state->out_block;
   state->stream.avail_in = 0;
   state->stream.next_out = state->out_block;
   state->stream.avail_out = state->out_block_size;
-
-  init_decoder ();
 }
 
 ssize_t
@@ -150,6 +155,9 @@ compress_xz::read (void *buffer, size_t len)
         {
          /* no compressed data ready; read some more */
           state->in_size = (size_t) this->original->read(state->in_block, state->in_block_size);
+         /* We don't care for error vs EOF */
+         if (state->in_size < 0)
+           state->in_size = 0;
           state->in_pos = 0;
         }
 
@@ -227,7 +235,7 @@ compress_xz::read (void *buffer, size_t len)
 ssize_t
 compress_xz::write (const void *buffer, size_t len)
 {
-  throw new logic_error("compress_xz::write is not implemented");
+  throw new std::logic_error("compress_xz::write is not implemented");
 }
 
 ssize_t
@@ -258,16 +266,27 @@ compress_xz::peek (void *buffer, size_t len)
   return 0;
 }
 
-long
+off_t
 compress_xz::tell ()
 {
-  throw new logic_error("compress_xz::tell is not implemented");
+  throw new std::logic_error("compress_xz::tell is not implemented");
 }
 
-int
-compress_xz::seek (long where, io_stream_seek_t whence)
+off_t
+compress_xz::seek (off_t where, io_stream_seek_t whence)
 {
-  throw new logic_error("compress_xz::seek is not implemented");
+  if ((whence == IO_SEEK_SET) && (where == 0))
+    {
+      off_t result = original->seek(where, whence);
+      destroy ();
+      peeklen = 0;
+      lasterr = 0;
+      create ();
+      init_decoder ();
+      return result;
+    }
+
+  throw new std::logic_error("compress_xz::seek is not implemented");
 }
 
 int
@@ -334,14 +353,14 @@ compress_xz::destroy ()
 
       compression_type = COMPRESSION_UNKNOWN;
     }
-
-  if (original && owns_original)
-    delete original;
 }
 
 compress_xz::~compress_xz ()
 {
   destroy ();
+
+  if (original && owns_original)
+    delete original;
 }
 
 /* ===========================================================================
@@ -508,7 +527,9 @@ compress_xz::bid_xz (void * buffer, size_t len)
     return 0;
   bits_checked += 8;
 
+#ifdef DEBUG
   LogBabblePrintf ("compress_xz::bid_xz: success: %d\n", bits_checked);
+#endif
   return (bits_checked);
 }
 
@@ -616,8 +637,8 @@ compress_xz::bid_lzma (void * buffer, size_t len)
 
   /* TODO: The above test is still very weak.  It would be
    * good to do better. */
+#ifdef DEBUG
   LogBabblePrintf ("compress_xz::bid_lzma: success: %d\n", bits_checked);
+#endif
   return (bits_checked);
 }
-
-
This page took 0.029539 seconds and 5 git commands to generate.