Skip to content

Instantly share code, notes, and snippets.

@upsuper
Last active August 15, 2023 13:24
Show Gist options
  • Save upsuper/4974433 to your computer and use it in GitHub Desktop.
Save upsuper/4974433 to your computer and use it in GitHub Desktop.
diff -ur a/CPP/7zip/Archive/Zip/ZipItem.cpp b/CPP/7zip/Archive/Zip/ZipItem.cpp
--- a/CPP/7zip/Archive/Zip/ZipItem.cpp 2016-02-02 03:50:10.000000000 +1100
+++ b/CPP/7zip/Archive/Zip/ZipItem.cpp 2023-08-15 23:19:44.862769098 +1000
@@ -1,6 +1,7 @@
// Archive/ZipItem.cpp
#include "StdAfx.h"
+#include <iconv.h>
#include "../../../../C/CpuArch.h"
#include "../../../../C/7zCrc.h"
@@ -249,7 +250,20 @@
if (ConvertUTF8ToUnicode(s, res) || ignore_Utf8_Errors)
return;
- MultiByteToUnicodeString2(res, s, useSpecifiedCodePage ? codePage : GetCodePage());
+ if (GetHostOS() == NFileHeader::NHostOS::kUnix) {
+ MultiByteToUnicodeString2(res, s, useSpecifiedCodePage ? codePage : GetCodePage());
+ } else {
+ AString utf;
+ size_t size1 = s.Len(), size2 = (s.Len() + 1) / 2 * 3;
+ char *p1 = (char*)s.Ptr();
+ char *p2 = utf.GetBuf(size2);
+ char *p2o = p2;
+ iconv_t cd = iconv_open("utf8", "gb18030");
+ iconv(cd, &p1, &size1, &p2, &size2);
+ iconv_close(cd);
+ utf.ReleaseBuf_SetEnd(p2 - p2o);
+ ConvertUTF8ToUnicode(utf, res);
+ }
}
}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment