diff --git a/Makefile.in b/Makefile.in
index 3d51c30..c2240af 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -61,7 +61,7 @@ sh_decoder.o : decoder.h
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 --git a/lzip_compat.h b/lzip_compat.h
new file mode 100644
index 0000000..62678cf
--- /dev/null
+++ b/lzip_compat.h
@@ -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 .
+*/
+#ifndef _FILE_OFFSET_BITS
+#define _FILE_OFFSET_BITS 64
+#endif
+
+#ifdef __MSVCRT__ /* Using Windows MSVCRT.DLL */
+#include
+#include
+#include
+/* 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/main.cc b/main.cc
index 7a415a9..ca6a099 100644
--- a/main.cc
+++ b/main.cc
@@ -1,5 +1,6 @@
/* Minilzip - A test program for the lzlib library
Copyright (C) 2009 Antonio Diaz Diaz.
+ Patched for MinGW by Jonatan 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
@@ -22,6 +23,7 @@
*/
#define _FILE_OFFSET_BITS 64
+#define __STDC_FORMAT_MACROS
#include
#include
@@ -33,7 +35,7 @@
#include
#include
#include
-#include
+#include
#include
#include
#include
@@ -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 @@ 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;
}
@@ -505,7 +508,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 ) ),
@@ -572,7 +575,7 @@ int decompress( const int inhandle, const Pretty_print & pp,
{
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;
}
@@ -664,7 +667,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;
@@ -683,7 +686,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