Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Make plzip compilable on MSYS2+MinGW-w64
Make plzip compilable on MSYS2+MinGW-w64.
It's Hannes Domani's plzip.patch taken from:
http://download.savannah.gnu.org/releases/lzip/plzip/plzip-1.1-w.zip
that was applied against plzip 1.7:
http://download.savannah.gnu.org/releases/lzip/plzip/plzip-1.7.tar.gz
changed to not artificially limit number of threads (the limit was 32),
and finally diff has been regenerated using output with unified context.
--- a/decompress.cc 2018-02-07 20:17:00.000000000 +0100
+++ b/decompress.cc 2018-02-23 23:14:21.644369300 +0100
@@ -37,6 +37,61 @@
#include "file_index.h"
+#ifdef _WIN32
+#include <windows.h>
+
+ssize_t pread(int fd, void *buf, size_t count, long long offset)
+{
+ OVERLAPPED o = {0,0,0,0,0};
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+ uint64_t off = offset;
+ DWORD bytes;
+ BOOL ret;
+
+ if (fh == INVALID_HANDLE_VALUE) {
+ errno = EBADF;
+ return -1;
+ }
+
+ o.Offset = off & 0xffffffff;
+ o.OffsetHigh = (off >> 32) & 0xffffffff;
+
+ ret = ReadFile(fh, buf, (DWORD)count, &bytes, &o);
+ if (!ret) {
+ errno = EIO;
+ return -1;
+ }
+
+ return (ssize_t)bytes;
+}
+
+ssize_t pwrite(int fd, const void *buf, size_t count, long long offset)
+{
+ OVERLAPPED o = {0,0,0,0,0};
+ HANDLE fh = (HANDLE)_get_osfhandle(fd);
+ uint64_t off = offset;
+ DWORD bytes;
+ BOOL ret;
+
+ if (fh == INVALID_HANDLE_VALUE) {
+ errno = EBADF;
+ return -1;
+ }
+
+ o.Offset = off & 0xffffffff;
+ o.OffsetHigh = (off >> 32) & 0xffffffff;
+
+ ret = WriteFile(fh, buf, (DWORD)count, &bytes, &o);
+ if (!ret) {
+ errno = EIO;
+ return -1;
+ }
+
+ return (ssize_t)bytes;
+}
+#endif
+
+
// Returns the number of bytes really read.
// If (returned value < size) and (errno == 0), means EOF was reached.
//
--- a/main.cc 2018-02-07 20:17:00.000000000 +0100
+++ b/main.cc 2018-02-23 23:14:27.592984400 +0100
@@ -69,6 +69,31 @@
int verbosity = 0;
+#ifdef _WIN32
+#include <windows.h>
+
+#define _SC_NPROCESSORS_ONLN 1
+#define _SC_THREAD_THREADS_MAX 2
+long sysconf( int flag )
+{
+ switch( flag )
+ {
+ case _SC_NPROCESSORS_ONLN:
+ {
+ SYSTEM_INFO si;
+ GetSystemInfo( &si );
+ return si.dwNumberOfProcessors;
+ }
+
+ case _SC_THREAD_THREADS_MAX:
+ return -1;
+ }
+
+ return 0;
+}
+#endif
+
+
namespace {
const char * const Program_name = "Plzip";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment