Skip to content

Commit

Permalink
MinGW64 support for non-Latin characters (madler#62)
Browse files Browse the repository at this point in the history
  • Loading branch information
neurolabusc committed Feb 22, 2020
1 parent ce36332 commit baf468a
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 9 deletions.
16 changes: 14 additions & 2 deletions src/Makefile
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,13 +1,25 @@
CC=gcc
CFLAGS=-O3 -Wall -Wextra -Wno-unknown-pragmas
LDFLAGS=
#LIBS=-lm -lpthread -lz
UNPIGZ=ln -f pigz unpigz
LIBS=-lm -lpthread -I./linux ./linux/libz.a
#LIBS=-lm -lpthread -lz

ifneq ($(OS),Windows_NT)
OS = $(shell uname)
ifeq "$(OS)" "Darwin"
LIBS=-lm -lpthread -I./darwin ./darwin/libz.a
endif
else
ifeq ($(PROCESSOR_ARCHITEW6432),AMD64)
LDFLAGS= -municode
else
ifeq ($(PROCESSOR_ARCHITECTURE),AMD64)
LDFLAGS= -municode
endif
endif
LIBS=-lm -lpthread -lz
UNPIGZ=cp pigz.exe unpigz.exe
endif

ZOPFLI=zopfli/src/zopfli/
Expand All @@ -17,7 +29,7 @@ ZOP=deflate.o blocksplitter.o tree.o lz77.o cache.o hash.o util.o squeeze.o kata

pigz: pigz.o yarn.o try.o $(ZOP)
$(CC) $(LDFLAGS) -o pigz pigz.o yarn.o try.o $(ZOP) $(LIBS)
ln -f pigz unpigz
$(UNPIGZ)

pigz.o: pigz.c yarn.h try.h $(ZOPFLI)deflate.h $(ZOPFLI)util.h

Expand Down
39 changes: 32 additions & 7 deletions src/pigz.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,19 @@ typedef SSIZE_T ssize_t;
#include <sys/types.h> // ssize_t
#include <sys/stat.h> // chmod(), stat(), fstat(), lstat(), struct stat,
// S_IFDIR, S_IFLNK, S_IFMT, S_IFREG
#ifdef __MINGW32__
#include <unistd.h>
#include <windows.h>
#include <tchar.h>
#ifndef _UNICODE
#define _UNICODE
#endif
#ifndef UNICODE
#define UNICODE
#endif
#include <wchar.h>
#endif

#ifndef _MSC_VER
#include <sys/time.h> // utimes(), gettimeofday(), struct timeval
#include <unistd.h> // unlink(), _exit(), read(), write(), close(),
Expand Down Expand Up @@ -397,7 +410,7 @@ typedef SSIZE_T ssize_t;
# define S_IFLNK 0
#endif

#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW64__)

//https://www.nu42.com/2017/02/unicode-windows-command-line.html
//https://raw.githubusercontent.com/gypified/libmp3lame/master/frontend/main.c
Expand Down Expand Up @@ -477,10 +490,18 @@ int unlinkUTF8(const char *path) {
#ifdef __MINGW32__
# define chown(p,o,g) 0
# define utimes(p,t) 0
# define lstat(p,s) stat(p,s)
#if defined(__MINGW64__)
//lstat defined for unicode
#else
# define lstat(p,s) stat(p,s)
#endif
# define _exit(s) exit(s)
#endif





#include "zlib.h" // deflateInit2(), deflateReset(), deflate(),
// deflateEnd(), deflateSetDictionary(), crc32(),
// adler32(), inflateBackInit(), inflateBack(),
Expand Down Expand Up @@ -3726,7 +3747,8 @@ local void touch(char *path, time_t t) {



#ifdef _MSC_VER
//#ifdef
#if defined(_MSC_VER) || defined(MSDOS) || defined(OS2) || defined(WIN32) || defined(__CYGWIN__)
/* http://ab-initio.mit.edu/octave-Faddeeva/gnulib/lib/fsync.c
Emulate fsync on platforms that lack it, primarily Windows and
cross-compilers like MinGW.
Expand Down Expand Up @@ -4469,10 +4491,10 @@ local void cut_yarn(int err) {
#endif

// Process command line arguments.
#ifndef _MSC_VER
int main(int argc, char **argv) {
#else
#if defined(_MSC_VER) || defined(__MINGW64__)
int c_main(int argc, char *argv[]) {
#else
int main(int argc, char **argv) {
#endif
int n; // general index
int nop; // index before which "-" means stdin
Expand Down Expand Up @@ -4614,7 +4636,10 @@ int c_main(int argc, char *argv[]) {
return g.ret;
}

#ifdef _MSC_VER
#if defined(_MSC_VER) || defined(__MINGW64__)
// beware, only some versions of MinGW support wmain and -municode linker flag
// use this version: http://mingw-w64.org/doku.php
// for details: https://sourceforge.net/p/mingw-w64/wiki2/Unicode%20apps/
int wmain(int argc, wchar_t* argv[]) { //convert each argument to UTF8
char **utf8_argv;
int ret;
Expand Down

0 comments on commit baf468a

Please sign in to comment.