Make pigz.c compilable on MSYS2+MinGW-w64
Make pigz.c (2.4) compilable on MSYS2+MinGW-w64. | |
diff --git a/pigz.c b/pigz.c | |
index bbbfd2cd19a1..85a61eeca674 100644 | |
--- a/pigz.c | |
+++ b/pigz.c | |
@@ -324,6 +324,11 @@ | |
// Use large file functions if available. | |
#define _FILE_OFFSET_BITS 64 | |
+#ifdef __MINGW32__ | |
+/* Support 'j' length modifier (intmax_t) in printf(). */ | |
+#define __USE_MINGW_ANSI_STDIO 1 | |
+#endif | |
+ | |
// Included headers and what is expected from each. | |
#include <stdio.h> // fflush(), fprintf(), fputs(), getchar(), putc(), | |
// puts(), printf(), vasprintf(), stderr, EOF, NULL, | |
@@ -385,6 +390,15 @@ | |
# define utimes(p,t) 0 | |
# define lstat(p,s) stat(p,s) | |
# define _exit(s) exit(s) | |
+ | |
+#define WINAPI __stdcall | |
+#define INVALID_HANDLE_VALUE ((HANDLE)-1) | |
+ | |
+typedef void *HANDLE; | |
+typedef int BOOL; | |
+ | |
+BOOL WINAPI FlushFileBuffers(HANDLE hFile); | |
+ | |
#endif | |
#include "zlib.h" // deflateInit2(), deflateReset(), deflate(), | |
@@ -3640,10 +3654,22 @@ local void touch(char *path, time_t t) { | |
local void out_push(void) { | |
if (g.outd == -1) | |
return; | |
+#ifdef __MINGW32__ | |
+ int ret = -1; | |
+ HANDLE h = (HANDLE)_get_osfhandle(g.outd); | |
+ if (h == INVALID_HANDLE_VALUE) | |
+ errno = EBADF; | |
+ else { | |
+ ret = -!FlushFileBuffers(h); | |
+ if (ret == -1) | |
+ errno = EINVAL; | |
+ } | |
+#else | |
#ifdef F_FULLSYNC | |
int ret = fcntl(g.outd, F_FULLSYNC); | |
#else | |
int ret = fsync(g.outd); | |
+#endif | |
#endif | |
if (ret == -1) | |
throw(errno, "sync error on %s (%s)", g.outf, strerror(errno)); |
This comment has been minimized.
This comment has been minimized.
@przemoc thanks a lot! However it seems the program is not compiled with utf-8 arguments support, would this be possible? |
This comment has been minimized.
This comment has been minimized.
|
This comment has been minimized.
This comment has been minimized.
@patroza Yeah, it is possible, but would require a bit more intrusive changes in the source code that I am willing to do right now. |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
By the way, I made my changes to for MSVC, and I do not have any experience with MINGW32. It is possible that a few changes of the |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This comment has been minimized.
Post on forum Encode.ru:
http://encode.ru/threads/1689-Google-Compress-Data-More-Densely-with-Zopfli?p=46476&viewfull=1#post46476
I additionally put binaries in FTP:
http://ftp.przemoc.net/pub/binaries/comp/pigz/