On 10/17/2009 11:27, JonY wrote:
Hi,

This patch makes lzlib 0.6 build on MSYS/MinGW.

There is also a dll called "liblz.so.6" created similar with Linux
builds, dll names do not cause any issues. In any case, linking directly
to liblz.so.6 and skipping the import lib works too.

To make it named ".dll", just use:
c++ -shared -o liblz-6.dll sh_decoder.o sh_encoder.o sh_lzlib.o
-Wl,-out-implib,libz.dll.a

Unfortunately I was unable to get the lzcheck test to pass, it
mysteriously segfaults right after entering main(). It happens with
mingw, mingw-w64, and msvc2008.

Patch tested with Gentoo and MinGW.

btw, I noticed that main() has const parameters, is it intentional?
"make distclean" also does not clean up lzcheck.o.

Hi,

I forgot to patch Makefile.in, new patch attached.
diff -ur lzlib-0.6.ori/Makefile.in lzlib-0.6.new/Makefile.in
--- lzlib-0.6.ori/Makefile.in   2009-09-02 18:37:33.000000000 +0800
+++ lzlib-0.6.new/Makefile.in   2009-10-17 11:30:56.000000000 +0800
@@ -61,7 +61,7 @@
 sh_encoder.o   : encoder.h
 sh_lzlib.o     : decoder.h encoder.h
 arg_parser.o   : Makefile arg_parser.h
-main.o         : Makefile arg_parser.h lzlib.h $(libname).a
+main.o         : Makefile arg_parser.h lzlib.h lzip_compat.h $(libname).a
 
 
 doc : info man
diff -ur lzlib-0.6.ori/main.cc lzlib-0.6.new/main.cc
--- lzlib-0.6.ori/main.cc       2009-09-02 17:12:21.000000000 +0800
+++ lzlib-0.6.new/main.cc       2009-10-17 10:46:36.000000000 +0800
@@ -1,5 +1,6 @@
 /*  Minilzip - A test program for the lzlib library
     Copyright (C) 2009 Antonio Diaz Diaz.
+    Patched for MinGW by Jonatan Yong <jon_y [a] users.sourceforge.net>.
 
     This program is free software: you can redistribute it and/or modify
     it under the terms of the GNU General Public License as published by
@@ -22,6 +23,7 @@
 */
 
 #define _FILE_OFFSET_BITS 64
+#define __STDC_FORMAT_MACROS
 
 #include <algorithm>
 #include <cerrno>
@@ -33,7 +35,7 @@
 #include <string>
 #include <vector>
 #include <fcntl.h>
-#include <stdint.h>
+#include <inttypes.h>
 #include <unistd.h>
 #include <utime.h>
 #include <sys/stat.h>
@@ -41,6 +43,7 @@
 
 #include "arg_parser.h"
 #include "lzlib.h"
+#include "lzip_compat.h"
 
 #ifndef LLONG_MAX
 #define LLONG_MAX  0x7FFFFFFFFFFFFFFFLL
@@ -178,7 +181,7 @@
   for( int i = 0; i < 8 && ( llabs( num ) > limit ||
        ( llabs( num ) >= factor && num % factor == 0 ) ); ++i )
     { num /= factor; p = prefix[i]; }
-  snprintf( buf, sizeof buf, "%lld %s", num, p );
+  snprintf( buf, sizeof buf, "%"PRId64" %s", num, p );
   return buf;
   }
 
@@ -507,7 +510,7 @@
       std::fprintf( stderr, "no data compressed.\n" );
     else
       std::fprintf( stderr, "%6.3f:1, %6.3f bits/byte, "
-                            "%5.2f%% saved, %lld in, %lld out.\n",
+                            "%5.2f%% saved, %"PRId64" in, %"PRId64" out.\n",
                     (double)in_size / out_size,
                     ( 8.0 * out_size ) / in_size,
                     100.0 * ( 1.0 - ( (double)out_size / in_size ) ),
@@ -574,7 +577,7 @@
         {
         if( verbosity >= 0 )
           { pp();
-            std::fprintf( stderr, "file ends unexpectedly at pos %lld\n",
+            std::fprintf( stderr, "file ends unexpectedly at pos %"PRId64"\n",
                           LZ_decompress_total_in_size( decoder ) ); }
         return 2;
         }
@@ -666,7 +669,7 @@
   while( rest > 0 )
     {
     errno = 0;
-    const int n = read( fd, buf + size - rest, rest );
+    const int n = compat_wrap(read( fd, buf + size - rest, rest ));
     if( n > 0 ) rest -= n;
     else if( n == 0 ) break;
     else if( errno != EINTR && errno != EAGAIN ) break;
@@ -685,7 +688,7 @@
   while( rest > 0 )
     {
     errno = 0;
-    const int n = write( fd, buf + size - rest, rest );
+    const int n = compat_wrap(write( fd, buf + size - rest, rest ));
     if( n > 0 ) rest -= n;
     else if( errno && errno != EINTR && errno != EAGAIN ) break;
     }
--- /dev/null   2009-10-17 11:33:08.000000000 +0800
+++ lzlib-0.6.new/lzip_compat.h 2009-10-17 11:32:04.000000000 +0800
@@ -0,0 +1,60 @@
+/*  lzip_compat.h - Systems compatibility header
+    Copyright (C) 2009 Jonathan Yong.
+    
+    This program is free software: you can redistribute it and/or modify
+    it under the terms of the GNU General Public License as published by
+    the Free Software Foundation, either version 3 of the License, or
+    (at your option) any later version.
+
+    This program is distributed in the hope that it will be useful,
+    but WITHOUT ANY WARRANTY; without even the implied warranty of
+    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+    GNU General Public License for more details.
+
+    You should have received a copy of the GNU General Public License
+    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
+#ifdef __MSVCRT__ /* Using Windows MSVCRT.DLL */
+#include <fcntl.h>
+#include <stdio.h>
+#include <io.h>
+/* We don't care about permissions */
+#define S_IRGRP _S_IREAD
+#define S_IROTH _S_IREAD
+#define S_IRGRP _S_IREAD
+#define S_IROTH _S_IREAD
+
+/* Windows doesn't have sighup, neither is it needed. */
+#define SIGHUP SIGBREAK
+
+/* Unimplemented Functions */
+#define fchmod(x,y) 0
+#define fchown(x,y,z) 0
+#define S_ISSOCK(x) 0
+
+/* Inline compat wrappers */
+#define compat_wrap(x) compat_msvcrt_##x
+#else
+#define compat_wrap(x) x
+#endif
+
+#ifdef __MSVCRT__
+/* These will only be used for MSVCR based runtime */
+static inline int compat_msvcrt_read( int fildes, void *buf, size_t nbyte )
+{
+  /*Set IO mode to Binary */
+  _setmode(  fildes, _O_BINARY );
+  return read( fildes, buf, nbyte );
+}
+
+static inline int compat_msvcrt_write( int fildes, const void *buf, size_t 
nbyte )
+{
+  /*Set IO mode to Binary */
+  _setmode(  fildes, _O_BINARY );
+  return write( fildes, buf, nbyte );
+}
+#endif
_______________________________________________
Lzip-bug mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lzip-bug

Reply via email to