diff -uNr unzip-5.52/convfn.c unzip-mod/convfn.c --- unzip-5.52/convfn.c 1970-01-01 09:00:00.000000000 +0900 +++ unzip-mod/convfn.c 2006-10-08 14:14:49.000000000 +0900 @@ -0,0 +1,52 @@ +#ifdef _USE_ICONV +#include +#include +#include +#include +#define ICONV_BUFSIZE 260 +char* getLegacyCharset() { + char *lang = getenv("LANG"); + if(!lang) return "ISO8859-1"; + if(!strncmp(lang, "ko", 2)) return "UHC"; + if(!strncmp(lang, "zh_TW", 5)) return "BIG5"; + if(!strncmp(lang, "zh_GB", 5)) return "GB2312"; + if(!strncmp(lang, "ja", 2)) return "EUC-JP"; + if(!strncmp(lang, "ru", 2)) return "CP1251"; + if(!strncmp(lang, "uk", 2)) return "KOI8-U"; + if(!strncmp(lang, "th", 2)) return "TIS-620"; + if(!strncmp(lang, "vi", 2)) return "TCVN"; + return "ISO8859-1"; + +} + + +char* convertfn(char *filename) { + size_t ileft, oleft; + iconv_t cd; + size_t iconv_result; + size_t size; + char inbuf[ICONV_BUFSIZE]; + char outbuf[ICONV_BUFSIZE]; + char *inptr = inbuf; + char *outptr = outbuf; + + size = strlen(filename)+1; + strncpy(inbuf, filename, size); + ileft = size; + oleft = sizeof(outbuf); + + cd = iconv_open(nl_langinfo(CODESET), getLegacyCharset()); + + iconv_result = iconv(cd, &inptr, &ileft, &outptr, &oleft); + + outbuf[ICONV_BUFSIZE - oleft] = 0; + if(iconv_result != -1) strcpy(filename, outbuf); + + iconv_close(cd); + return filename; +} +#else +char* convertfn(char *filename) { + return filename; +} +#endif diff -uNr unzip-5.52/convfn.h unzip-mod/convfn.h --- unzip-5.52/convfn.h 1970-01-01 09:00:00.000000000 +0900 +++ unzip-mod/convfn.h 2006-10-08 14:14:49.000000000 +0900 @@ -0,0 +1,5 @@ +#ifndef _CONVERT_FILE_NAME_H +#define _CONVERT_FILE_NAME_H +char* convertfn(char *filename); +#endif + diff -uNr unzip-5.52/extract.c unzip-mod/extract.c --- unzip-5.52/extract.c 2005-02-26 13:47:30.000000000 +0900 +++ unzip-mod/extract.c 2006-10-08 14:14:49.000000000 +0900 @@ -2344,6 +2344,11 @@ return (char *)space; #else /* NATIVE: EBCDIC or whatever */ +#if 1 +#include "convfn.h" + raw = convertfn(raw); +#endif + return (char *)raw; #endif diff -uNr unzip-5.52/fileio.c unzip-mod/fileio.c --- unzip-5.52/fileio.c 2005-02-27 11:10:12.000000000 +0900 +++ unzip-mod/fileio.c 2006-10-08 14:14:49.000000000 +0900 @@ -2139,10 +2139,15 @@ return PK_EOF; G.filename[length] = '\0'; /* terminate w/zero: ASCIIZ */ +#if 0 /* translate the Zip entry filename coded in host-dependent "extended ASCII" into the compiler's (system's) internal text code page */ Ext_ASCII_TO_Native(G.filename, G.pInfo->hostnum, G.pInfo->hostver, G.pInfo->HasUxAtt, (option == DS_FN_L)); +#else +#include "convfn.h" + convertfn(G.filename); +#endif if (G.pInfo->lcflag) /* replace with lowercase filename */ STRLOWER(G.filename, G.filename); diff -uNr unzip-5.52/funzip.c unzip-mod/funzip.c --- unzip-5.52/funzip.c 2002-03-24 00:56:16.000000000 +0900 +++ unzip-mod/funzip.c 2006-10-08 14:14:49.000000000 +0900 @@ -303,6 +303,7 @@ uch h[LOCHDR]; /* first local header (GZPHDR < LOCHDR) */ int g = 0; /* true if gzip format */ unsigned method = 0; /* initialized here to shut up gcc warning */ + SETLOCALE(LC_ALL, ""); #if CRYPT char *s = " [-password]"; char *p; /* password */ diff -uNr unzip-5.52/unix/Makefile unzip-mod/unix/Makefile --- unzip-5.52/unix/Makefile 2006-10-08 14:08:31.000000000 +0900 +++ unzip-mod/unix/Makefile 2006-10-08 14:14:10.000000000 +0900 @@ -81,16 +81,16 @@ OSDEP_H = # object files -OBJS1 = unzip$O $(CRC32)$O crctab$O crypt$O envargs$O explode$O +OBJS1 = unzip$O $(CRC32)$O crctab$O crypt$O envargs$O explode$O convfn$O OBJS2 = extract$O fileio$O globals$O inflate$O list$O match$O OBJS3 = process$O ttyio$O unreduce$O unshrink$O zipinfo$O OBJS = $(OBJS1) $(OBJS2) $(OBJS3) $M$O LOBJS = $(OBJS) OBJSDLL = $(OBJS:.o=.pic.o) api.pic.o OBJX = unzipsfx$O $(CRC32)$O crctab_$O crypt_$O extract_$O fileio_$O \ - globals_$O inflate_$O match_$O process_$O ttyio_$O $M_$O + globals_$O inflate_$O match_$O process_$O ttyio_$O convfn$O $M_$O LOBJX = $(OBJX) -OBJF = funzip$O $(CRC32)$O cryptf$O globalsf$O inflatef$O ttyiof$O +OBJF = funzip$O $(CRC32)$O cryptf$O globalsf$O inflatef$O ttyiof$O convfn$O #OBJS_OS2 = $(OBJS1:.o=.obj) $(OBJS2:.o=.obj) os2.obj #OBJF_OS2 = $(OBJF:.o=.obj) UNZIP_H = unzip.h unzpriv.h globals.h $(OSDEP_H) @@ -728,8 +728,8 @@ freebsd: unix_make @echo 'NOTE: use bsd target for non-Intel FreeBSD compiles (if any).' $(MAKE) unzips CC=gcc LD=gcc AS=gcc\ - CF="-O3 -Wall -I. -DASM_CRC -DUNIX -DBSD $(LOC)"\ - AF="-Di386 $(AF)" CRC32=crc_gcc + CF="-O3 -Wall -I. -DASM_CRC -DUNIX -DBSD -D_USE_ICONV $(LOC)"\ + AF="-Di386 $(AF)" CRC32=crc_gcc LF2="-liconv $(LF2)" # Generic BSDish Unix gcc. ``The $(CFLAGS) only works with later versions of gcc; # you may have to use -O2 or $(CFLAGS) for earlier versions. I have no idea why @@ -773,17 +773,17 @@ linux: unix_make @echo 'NOTE: use linux_noasm target for non-Intel Linux compiles.' $(MAKE) unzips CC=gcc LD=gcc AS=gcc\ - CF="-O3 -Wall -I. -DASM_CRC $(LOC)"\ + CF="-O3 -Wall -I. -DASM_CRC -D_USE_ICONV $(LOC)"\ AF="-Di386 $(AF)" CRC32=crc_gcc # GRR: this echo is pointless; if user gets this far, no difference to install # @echo 'Be sure to use the install_asm target rather than the install target' linux_asm: linux # Linux (Posix, approximately SysV): virtually any version since before 0.96, # for any platform. Change "-O" to "-O3" or whatever, as desired... linux_noasm: unix_make - $(MAKE) unzips CC=gcc LD=gcc CF="-O -Wall -I. $(LOC)" + $(MAKE) unzips CC=gcc LD=gcc CF="-O -Wall -I. -D_USE_ICONV $(LOC)" # Linux with lcc compiler: __inline__ (stat.h) not recognized, and must edit # /usr/include/gnu/types.h to get rid of "long long" if __LCC__ defined. -O3 diff -uNr unzip-5.52/unzip.c unzip-mod/unzip.c --- unzip-5.52/unzip.c 2005-02-27 13:37:14.000000000 +0900 +++ unzip-mod/unzip.c 2006-10-08 14:14:49.000000000 +0900 @@ -666,7 +666,7 @@ #endif #endif /* NO_EXCEPT_SIGNALS */ - SETLOCALE(LC_CTYPE,""); + SETLOCALE(LC_ALL ,""); #if (defined(__IBMC__) && defined(__DEBUG_ALLOC__)) extern void DebugMalloc(void); diff -uNr unzip-5.52/unzpriv.h unzip-mod/unzpriv.h --- unzip-5.52/unzpriv.h 2005-02-04 08:26:42.000000000 +0900 +++ unzip-mod/unzpriv.h 2006-10-08 14:14:49.000000000 +0900 @@ -1195,6 +1195,11 @@ # define MBSRCHR(str, c) strrchr(str, c) # define SETLOCALE(category, locale) #endif /* ?_MBCS */ +#ifdef _USE_ICONV +# include +# undef SETLOCALE +# define SETLOCALE(category, locale) setlocale(category, locale) +#endif /* ?_USE_ICONV */ #define INCSTR(ptr) PREINCSTR(ptr)