--- /dev/null 2009-10-19 21:11:03.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 . +*/ +#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 -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-19 21:08:11.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 @@ -143,7 +143,7 @@ lzip -v -9 $(DISTNAME).tar clean : - -rm -f $(progname) $(progname)_profiled $(objs) $(lib_objs) *.a + -rm -f $(progname) $(progname)_profiled $(objs) $(lib_objs) lzcheck.o *.a -rm -f $(progname)_shared $(sh_lib_objs) *.so.$(pkgversion) distclean : clean diff -ur lzlib-0.6.ori/lzcheck.cc lzlib-0.6.new/lzcheck.cc --- lzlib-0.6.ori/lzcheck.cc 2009-09-02 19:08:15.000000000 +0800 +++ lzlib-0.6.new/lzcheck.cc 2009-10-19 20:58:58.000000000 +0800 @@ -29,6 +29,12 @@ #define ULLONG_MAX 0xFFFFFFFFFFFFFFFFULL #endif +const int in_buffer_size = 1 << 20; +const int mid_buffer_size = 65536; +const int out_buffer_size = in_buffer_size; +uint8_t in_buffer[in_buffer_size]; +uint8_t mid_buffer[mid_buffer_size]; +uint8_t out_buffer[out_buffer_size]; int main( const int argc, const char * argv[] ) { @@ -45,12 +51,6 @@ return 1; } - const int in_buffer_size = 1 << 20; - const int mid_buffer_size = 65536; - const int out_buffer_size = in_buffer_size; - uint8_t in_buffer[in_buffer_size]; - uint8_t mid_buffer[mid_buffer_size]; - uint8_t out_buffer[out_buffer_size]; const int in_size = std::fread( in_buffer, 1, in_buffer_size, f ); if( in_size >= in_buffer_size ) { 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 . 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 @@ 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; }