On 10/13/2009 22:06, Antonio Diaz Diaz wrote:
JonY wrote:
Have you considered the possibility of maintaining a port? Ports for
systems very different from the original help to maintain the upstream
source clean and simple.
Do you mean maintaining local patches? If so, that is a possibility,
but I would like to push changes upstream if possible.
I would very much prefer to keep upstream code clean. Also, as I do not
use windows, it will become a burden for me to guarantee that win32
compilation is tested on all future code changes once it is officially
included in the main lzip distribution.
If you or someone else writes and maintains a separate port, I will be
happy to link it from the lzip home page.
Hi,
I understand your decision. Attached are the proper patches for Win32
builds.
First patch fixes binary read()/write(), the second fixes "%lld" vs
"%I64d" warnings. Tested on Gentoo and MinGW.
I'll try to maintain and submit patches against future released versions
to this list.
In the mean time, you can point anybody wanting a native win32 build to
the 2 attached patches via the mailing list archive.
Thanks.
diff --git a/Makefile.in b/Makefile.in
index 3062c4e..9a38209 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -30,7 +30,7 @@ main.o : main.cc
lziprecover.o : lziprecover.cc
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -DPROGVERSION=\"$(progversion)\" -c -o
$@ $<
-%.o : %.cc
+%.o : %.cc lzip_compat.h
$(CXX) $(CPPFLAGS) $(CXXFLAGS) -c -o $@ $<
$(objs) : Makefile
diff --git a/lzip_compat.h b/lzip_compat.h
new file mode 100644
index 0000000..534f4f2
--- /dev/null
+++ b/lzip_compat.h
@@ -0,0 +1,41 @@
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
+#ifdef __MSVCRT__ /* Using Windows MSVCRT.DLL */
+/* 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
diff --git a/lziprecover.cc b/lziprecover.cc
index deed53c..e8803d7 100644
--- a/lziprecover.cc
+++ b/lziprecover.cc
@@ -36,7 +36,7 @@
#include "arg_parser.h"
#include "lzip.h"
-
+#include "lzip_compat.h"
namespace {
@@ -282,7 +282,7 @@ int readblock( const int fd, char * buf, const int size )
throw()
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;
@@ -301,7 +301,7 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
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;
}
diff --git a/main.cc b/main.cc
index 41fde78..6304ee0 100644
--- a/main.cc
+++ b/main.cc
@@ -43,6 +43,7 @@
#include "lzip.h"
#include "decoder.h"
#include "encoder.h"
+#include "lzip_compat.h"
#ifndef LLONG_MAX
#define LLONG_MAX 0x7FFFFFFFFFFFFFFFLL
@@ -612,7 +613,7 @@ int readblock( const int fd, char * buf, const int size )
throw()
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;
@@ -631,7 +632,7 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
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;
}
--
1.6.4.13.ge6580.dirty
diff --git a/decoder.cc b/decoder.cc
index f5cb101..da25d5f 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -16,6 +16,7 @@
*/
#define _FILE_OFFSET_BITS 64
+#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cerrno>
@@ -24,7 +25,7 @@
#include <cstring>
#include <string>
#include <vector>
-#include <stdint.h>
+#include <inttypes.h>
#include "lzip.h"
#include "decoder.h"
@@ -106,7 +107,7 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp )
const
{
if( trailer.data_size() >= 0 )
{ pp();
- std::fprintf( stderr, "data size mismatch; trailer says %lld, data
size is %lld.\n",
+ std::fprintf( stderr, "data size mismatch; trailer says %"PRId64",
data size is %"PRId64".\n",
trailer.data_size(), data_position() ); }
else pp( "member trailer is corrupt" );
}
@@ -118,13 +119,13 @@ bool LZ_decoder::verify_trailer( const Pretty_print & pp
) const
{
if( trailer.member_size() >= 0 )
{ pp();
- std::fprintf( stderr, "member size mismatch; trailer says %lld,
member size is %lld.\n",
+ std::fprintf( stderr, "member size mismatch; trailer says %"PRId64",
member size is %"PRId64".\n",
trailer.member_size(), member_position() ); }
else pp( "member trailer is corrupt" );
}
}
if( !error && verbosity >= 3 )
- std::fprintf( stderr, "data crc %08X, data size %8lld, member size %8lld.
",
+ std::fprintf( stderr, "data crc %08X, data size %8"PRId64", member size
%8"PRId64". ",
(unsigned int)trailer.data_crc(), trailer.data_size(),
trailer.member_size() );
return !error;
diff --git a/lziprecover.cc b/lziprecover.cc
index e8803d7..ce85e0b 100644
--- a/lziprecover.cc
+++ b/lziprecover.cc
@@ -22,6 +22,7 @@
*/
#define _FILE_OFFSET_BITS 64
+#define __STDC_FORMAT_MACROS
#include <cerrno>
#include <cstdio>
diff --git a/main.cc b/main.cc
index 6304ee0..11c0c00 100644
--- a/main.cc
+++ b/main.cc
@@ -22,6 +22,7 @@
*/
#define _FILE_OFFSET_BITS 64
+#define __STDC_FORMAT_MACROS
#include <algorithm>
#include <cerrno>
@@ -33,7 +34,7 @@
#include <string>
#include <vector>
#include <fcntl.h>
-#include <stdint.h>
+#include <inttypes.h>
#include <unistd.h>
#include <utime.h>
#include <sys/stat.h>
@@ -141,7 +142,7 @@ const char * format_num( long long num, long long limit =
9999,
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;
}
@@ -447,7 +448,7 @@ int compress( const long long member_size, const long long
volume_size,
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 ) ),
@@ -519,10 +520,10 @@ int decompress( const int inhandle, const Pretty_print &
pp,
{
pp();
if( result == 2 )
- std::fprintf( stderr, "file ends unexpectedly at pos %lld\n",
+ std::fprintf( stderr, "file ends unexpectedly at pos %"PRId64"\n",
partial_file_pos );
else
- std::fprintf( stderr, "decoder error at pos %lld\n",
+ std::fprintf( stderr, "decoder error at pos %"PRId64"\n",
partial_file_pos );
}
return 2;
--
1.6.4.13.ge6580.dirty
_______________________________________________
Lzip-bug mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lzip-bug