Last active
March 27, 2024 09:35
-
-
Save przemoc/bd6c342ff7f31a0c4ec2 to your computer and use it in GitHub Desktop.
Make pigz.c compilable on MSYS2+MinGW-w64
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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)); |
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 ifdef clauses one could use wmain with MINGW32. If you implement this, I would like to know about it. My ultimate goal is a pull request to the main pigs repository that would provide robust support for Windows, and supporting both MINGW32 and MSVC would be fantastic.
Is it impossible to get this to work with the cygwin api's in mingw? Rather than introducing direct Windows API calls?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@przemoc and @patroza - I have created a fork that I think handles non-Latin filenames like
Описание.pdf. I do not typically use Windows, and only use Latin characters in my own work, so I would be grateful for any advice.