服务器维护,服务器代维,安全设置,漏洞扫描,入侵检测服务

运维之家

 找回密码
 注册
搜索
查看: 6719|回复: 0

解决unzip中文乱码问题

[复制链接]
dirtysea 发表于 2010-3-31 21:02:39 | 显示全部楼层 |阅读模式
在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
您需要登录后才可以回帖 登录 | 注册

本版积分规则

QQ|小黑屋|手机版|Archiver|运维之家

GMT+8, 2024-4-28 15:57 , Processed in 3.473424 second(s), 14 queries .

Powered by Dirtysea

© 2008-2020 Dirtysea.com.

快速回复 返回顶部 返回列表