Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Make pigz.c compilable on MSYS2+MinGW-w64
Make pigz.c (2.3.3) compilable on MSYS2+MinGW-w64.
Based on AiZ's reverse patch posted on:
http://encode.ru/threads/1689-Google-Compress-Data-More-Densely-with-Zopfli?p=32684#post32684
--- pigz.c.bak 2016-02-03 23:33:58.896985400 +0100
+++ pigz.c 2016-02-04 00:21:44.597383100 +0100
@@ -331,6 +331,7 @@
#include <sys/stat.h> /* chmod(), stat(), fstat(), lstat(), struct stat, */
/* S_IFDIR, S_IFLNK, S_IFMT, S_IFREG */
#include <sys/time.h> /* utimes(), gettimeofday(), struct timeval */
+#include <utime.h>
#include <unistd.h> /* unlink(), _exit(), read(), write(), close(), */
/* lseek(), isatty(), chown() */
#include <fcntl.h> /* open(), O_CREAT, O_EXCL, O_RDONLY, O_TRUNC, */
@@ -3386,7 +3387,7 @@
local void copymeta(char *from, char *to)
{
struct stat st;
- struct timeval times[2];
+ struct utimbuf times;
/* get all of from's Unix meta data, return if not a regular file */
if (stat(from, &st) != 0 || (st.st_mode & S_IFMT) != S_IFREG)
@@ -3396,26 +3397,24 @@
(void)chmod(to, st.st_mode & 07777);
/* copy owner's user and group, ignore errors */
+#if 0
(void)chown(to, st.st_uid, st.st_gid);
+#endif
/* copy access and modify times, ignore errors */
- times[0].tv_sec = st.st_atime;
- times[0].tv_usec = 0;
- times[1].tv_sec = st.st_mtime;
- times[1].tv_usec = 0;
- (void)utimes(to, times);
+ times.actime = st.st_atime;
+ times.modtime = st.st_mtime;
+ (void)utime(to, &times);
}
/* set the access and modify times of fd to t */
local void touch(char *path, time_t t)
{
- struct timeval times[2];
+ struct utimbuf times;
- times[0].tv_sec = t;
- times[0].tv_usec = 0;
- times[1].tv_sec = t;
- times[1].tv_usec = 0;
- (void)utimes(path, times);
+ times.actime = t;
+ times.modtime = t;
+ (void)utime(path, &times);
}
/* process provided input file, or stdin if path is NULL -- process() can
@@ -3447,7 +3446,7 @@
/* try to stat input file -- if not there and decoding, look for that
name with compressed suffixes */
- if (lstat(g.inf, &st)) {
+ if (stat(g.inf, &st)) {
if (errno == ENOENT && (g.list || g.decode)) {
char **sufx = sufs;
do {
@@ -3455,7 +3454,7 @@
break;
vstrcpy(&g.inf, &g.inz, len, *sufx++);
errno = 0;
- } while (lstat(g.inf, &st) && errno == ENOENT);
+ } while (stat(g.inf, &st) && errno == ENOENT);
}
#ifdef EOVERFLOW
if (errno == EOVERFLOW || errno == EFBIG)
@@ -3473,15 +3472,19 @@
/* only process regular files, but allow symbolic links if -f,
recurse into directory if -r */
if ((st.st_mode & S_IFMT) != S_IFREG &&
+#if 0
(st.st_mode & S_IFMT) != S_IFLNK &&
+#endif
(st.st_mode & S_IFMT) != S_IFDIR) {
complain("skipping: %s is a special file or device", g.inf);
return;
}
+#if 0
if ((st.st_mode & S_IFMT) == S_IFLNK && !g.force && !g.pipeout) {
complain("skipping: %s is a symbolic link", g.inf);
return;
}
+#endif
if ((st.st_mode & S_IFMT) == S_IFDIR && !g.recurse) {
complain("skipping: %s is a directory", g.inf);
return;

patroza 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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment