|
在windows上压缩的文件,是以系统默认编码中文来压缩文件。由于zip文件中没有声明其编码,所以linux上的unzip一般以默认编码解压,中文文件名会出现乱码。
使用源码安装unzip,解决中文乱码问题
1. 下载unzip-5.52:
wget http://rays.openrays.org/RAYSLX/pool/main/u/unzip/unzip_5.52.orig.tar.gz
2. 卸载linux系统自带的unzip:
#rpm -e unzip (可以用yum -remove干净卸载)
3. 解压文件:
#tar zxvf unzip_5.52.orig.tar.gz
4. **unzip目录
#cd unzip-5.52
5. 找到文件 unzpriv.h (使用ll显示所有文件。修改内容在文件最后末尾一个判断语句),修改以下内容:
/* Convert filename (and file comment string) into "internal" charset.
* This macro assumes that Zip entry filenames are coded in OEM (IBM DOS)
* codepage when made on
* -> DOS (this includes 16-bit Windows 3.1) (FS_FAT_)
* -> OS/2 (FS_HPFS_)
* -> Win95/WinNT with Nico Mak's WinZip (FS_NTFS_ && hostver == "5.0")
* EXCEPTIONS:
* PKZIP for Windows 2.5 and 2.6 flag their entries as "FS_FAT_", but the
* filename stored in the local header is coded in Windows ANSI (ISO 8859-1).
* Likewise, PKZIP for UNIX 2.51 flags its entries as "FS_FAT_", but the
* filenames stored in BOTH the local and the central header are coded
* in the local system's codepage (usually ANSI codings like ISO 8859-1).
*
* All other ports are assumed to code zip entry filenames in ISO 8859-1.
*/
#ifndef Ext_ASCII_TO_Native
# define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
if (((hostnum) == FS_FAT_ && \
!(((islochdr) || (isuxatt)) && \
(hostver) >= 25 && (hostver) <= 26)) || \
(hostnum) == FS_HPFS_ || \
((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
_OEM_INTERN((string)); \
} else { \
_ISO_INTERN((string)); \
}
#endif
注释其他语句,只留_ISO_INTERN((string)),修改如下(就是取掉它这个判断语句):
#ifndef Ext_ASCII_TO_Native
# define Ext_ASCII_TO_Native(string, hostnum, hostver, isuxatt, islochdr) \
/* if (((hostnum) == FS_FAT_ && \
* !(((islochdr) || (isuxatt)) && \
* (hostver) >= 25 && (hostver) <= 26)) || \
* (hostnum) == FS_HPFS_ || \
* ((hostnum) == FS_NTFS_ && (hostver) == 50)) { \
* _OEM_INTERN((string)); \
* } else { \ */
_ISO_INTERN((string)); \
/* } */
#endif
6. 复制unix编译文件到当前目录下
#cp /root/unzip-5.52/unix/Makefile /root/unzip-5.52/ (要使用绝对路径).
7. 安装
#make prefix=/usr linux
#make prefix=/usr install |
|