Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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));
@przemoc

This comment has been minimized.

@patroza

This comment has been minimized.

Copy link

commented Oct 26, 2017

@przemoc thanks a lot! However it seems the program is not compiled with utf-8 arguments support, would this be possible?
e.g Описание.pdf returns: pigz.exe: skipping: ????????.pdf does not exist

@przemoc

This comment has been minimized.

Copy link
Owner Author

commented Feb 17, 2018

commit 454c707ca233ee6ed64e51428be4ba6ea4296539
Author: Przemyslaw Pawelczyk <przemoc@gmail.com>
Date:   2018-02-17 13:26:30 +0100

    Create new patch for building pigz 2.4 on MSYS2+MinGW-w64.
@przemoc

This comment has been minimized.

Copy link
Owner Author

commented Feb 17, 2018

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.