大きなアプリを Windows から Linux に移植するには、ワイド文字とマルチバイト文字を変換できる必要があります。これを行うには、次のようなコードがあります。
void IConv(const InType* begin, const InType* end, const char* inCode, OutType* outBegin, OutType*& outEnd, const char* outCode)
{
assert(end >= begin);
assert(outEnd > outBegin);
iconv_t cd = iconv_open(outCode, inCode);
if (cd == reinterpret_cast<iconv_t>(-1))
throw (InvalidLocale ());
/* blah, blah, blah other code we never reach */
}
そのコードは常に例外をスローしています。これをデバッグするために、失敗したコードと同じパラメーターを使用する単純なバージョンを作成しました。これが私のテストコードです
int main( void )
{
const char outCode[] = "";
const char inCode[] = "wchar_t";
//Using wchar_t and "" means that iconv will just use the system locale settings.
iconv_t cd = iconv_open(outCode, inCode);
if (cd == reinterpret_cast<iconv_t>(-1))
{
printf("iconv failed to use outCode %s and inCode %s\n",outCode, inCode);
return 1;
}
iconv_close(cd);
return 0;
}
コードはほとんど同じであることに注意してください。しかし、私のテスト コードでは失敗は見られませんが、IConv 関数は常に失敗します。システムのロケールは、LANG 環境変数を介して設定されます。この場合、この環境変数は常に ISO-8859-1 です。
それで、問題は、単純なケースではなく、大きなアプリで現れる可能性のあるiconvの特定の動作を知っている人はいますか? ありがとうございました