On 10/11/2009 22:39, Antonio Diaz Diaz wrote:
Hello,
JonY wrote:
I noticed that lzip isn't particularly friendly to Windows. :)
It depends on how you are trying to compile it.
Wolfgang Buechel reported[1] that lzip can be compiled on windows with
cygwin[2].
[1] http://lists.gnu.org/archive/html/lzip-bug/2009-08/msg00005.html
[2] http://www.cygwin.com/
Make check reports tests completed successfully.
On your system maybe, but your patch breaks compilation on GNU/Linux. I
can't accept a patch that doesn't work perfectly on GNU/Linux.
Hi,
I built lzip as a native application with MinGW. It doesn't work with
MSVC yet, I'll get on it later. MSVC is missing "stdint.h".
The issue is that all files need to be opened in binary mode with
_setmode(), especially when writing to stdout and piping to tar.
Sorry, I didn't know O_BINARY was not available in Linux. Anyway, turns
out it wasn't needed if _setmode() was used.
Tested with Gentoo and MinGW.
Patch OK?
diff --git a/decoder.cc b/decoder.cc
index f5cb101..a417e24 100644
--- a/decoder.cc
+++ b/decoder.cc
@@ -106,7 +106,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 %"LZIPLL"d,
data size is %"LZIPLL"d.\n",
trailer.data_size(), data_position() ); }
else pp( "member trailer is corrupt" );
}
@@ -118,13 +118,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
%"LZIPLL"d, member size is %"LZIPLL"d.\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"LZIPLL"d, member size
%8"LZIPLL"d. ",
(unsigned int)trailer.data_crc(), trailer.data_size(),
trailer.member_size() );
return !error;
diff --git a/lzip.h b/lzip.h
index 0a2293d..c3f9fe8 100644
--- a/lzip.h
+++ b/lzip.h
@@ -15,6 +15,22 @@
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
+#ifdef __MSVCRT__
+/* Using MSVCRT conventions */
+#define LZIPLL "I64"
+#define S_ISSOCK(x) 0
+/* 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
+/* Unimplemented Functions */
+#define fchmod(x,y) 0
+#define fchown(x,y,z) 0
+#else
+#define LZIPLL "ll"
+#endif
+
class State
{
unsigned char st;
diff --git a/lziprecover.cc b/lziprecover.cc
index deed53c..4fb2f25 100644
--- a/lziprecover.cc
+++ b/lziprecover.cc
@@ -279,6 +279,10 @@ int readblock( const int fd, char * buf, const int size )
throw()
{
int rest = size;
errno = 0;
+ #ifdef __MSVCRT__
+ /*set IO to binary mode */
+ int prevmode = _setmode( fd, _O_BINARY);
+ #endif
while( rest > 0 )
{
errno = 0;
@@ -287,6 +291,10 @@ int readblock( const int fd, char * buf, const int size )
throw()
else if( n == 0 ) break;
else if( errno != EINTR && errno != EAGAIN ) break;
}
+ #ifdef __MSVCRT__
+ /*Restore IO to default mode */
+ _setmode( fd, prevmode);
+ #endif
return ( rest > 0 ) ? size - rest : size;
}
@@ -298,6 +306,10 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
{
int rest = size;
errno = 0;
+ #ifdef __MSVCRT__
+ /*set IO to binary mode */
+ int prevmode = _setmode( fd, _O_BINARY);
+ #endif
while( rest > 0 )
{
errno = 0;
@@ -305,6 +317,10 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
if( n > 0 ) rest -= n;
else if( errno && errno != EINTR && errno != EAGAIN ) break;
}
+ #ifdef __MSVCRT__
+ /*Restore IO to default mode */
+ _setmode( fd, prevmode);
+ #endif
return ( rest > 0 ) ? size - rest : size;
}
diff --git a/main.cc b/main.cc
index 41fde78..72d32dd 100644
--- a/main.cc
+++ b/main.cc
@@ -140,7 +140,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, "%"LZIPLL"d %s", num, p );
return buf;
}
@@ -240,7 +240,7 @@ int open_instream( const std::string & name, struct stat *
in_statsp,
}
else
{
- inhandle = open( name.c_str(), O_RDONLY );
+ inhandle = open( name.c_str(), O_RDONLY);
if( inhandle < 0 )
{
if( verbosity >= 0 )
@@ -446,7 +446,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, %"LZIPLL"d in, %"LZIPLL"d
out.\n",
(double)in_size / out_size,
( 8.0 * out_size ) / in_size,
100.0 * ( 1.0 - ( (double)out_size / in_size ) ),
@@ -518,10 +518,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 %"LZIPLL"d\n",
partial_file_pos );
else
- std::fprintf( stderr, "decoder error at pos %lld\n",
+ std::fprintf( stderr, "decoder error at pos %"LZIPLL"d\n",
partial_file_pos );
}
return 2;
@@ -551,7 +551,9 @@ extern "C" void signal_handler( int ) throw()
void set_signals() throw()
{
signal( SIGTERM, signal_handler );
+ #ifndef __MSVCRT__ /* Windows doesn't have SIGHUP */
signal( SIGHUP, signal_handler );
+ #endif
signal( SIGINT, signal_handler );
}
@@ -601,7 +603,6 @@ void internal_error( const char * msg )
std::exit( 3 );
}
-
// Returns the number of bytes really read.
// If (returned value < size) and (errno == 0), means EOF was reached.
//
@@ -609,6 +610,10 @@ int readblock( const int fd, char * buf, const int size )
throw()
{
int rest = size;
errno = 0;
+ #ifdef __MSVCRT__
+ /*set IO to binary mode */
+ int prevmode = _setmode( fd, _O_BINARY);
+ #endif
while( rest > 0 )
{
errno = 0;
@@ -617,6 +622,10 @@ int readblock( const int fd, char * buf, const int size )
throw()
else if( n == 0 ) break;
else if( errno != EINTR && errno != EAGAIN ) break;
}
+ #ifdef __MSVCRT__
+ /*Restore IO to default mode */
+ _setmode( fd, prevmode);
+ #endif
return ( rest > 0 ) ? size - rest : size;
}
@@ -628,6 +637,10 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
{
int rest = size;
errno = 0;
+ #ifdef __MSVCRT__
+ /*set IO to binary mode */
+ int prevmode = _setmode( fd, _O_BINARY);
+ #endif
while( rest > 0 )
{
errno = 0;
@@ -635,6 +648,10 @@ int writeblock( const int fd, const char * buf, const int
size ) throw()
if( n > 0 ) rest -= n;
else if( errno && errno != EINTR && errno != EAGAIN ) break;
}
+ #ifdef __MSVCRT__
+ /*Restore IO to default mode */
+ _setmode( fd, prevmode);
+ #endif
return ( rest > 0 ) ? size - rest : size;
}
_______________________________________________
Lzip-bug mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/lzip-bug