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