9 //-----------------------------------------------------------------------------
10 std::string IconvString(const std::string & src,
11 const std::string & from,
12 const std::string & to)
17 size_t inBytesLeft = src.length() + 1;
18 size_t outBytesLeft = src.length() * 2 + 1;
20 char * inBuf = new char[inBytesLeft];
21 char * outBuf = new char[outBytesLeft];
23 strncpy(inBuf, src.c_str(), src.length());
25 inBuf[src.length()] = 0;
27 #if defined(FREE_BSD) || defined(FREE_BSD5)
28 const char * srcPos = inBuf;
30 char * srcPos = inBuf;
32 char * dstPos = outBuf;
34 iconv_t handle = iconv_open(to.c_str(),
37 if (handle == iconv_t(-1))
41 printfd(__FILE__, "IconvString(): iconv from %s to %s failed\n", from.c_str(), to.c_str());
47 printfd(__FILE__, "IconvString(): iconv_open error\n");
54 size_t res = iconv(handle,
55 &srcPos, &inBytesLeft,
56 &dstPos, &outBytesLeft);
58 if (res == size_t(-1))
60 printfd(__FILE__, "IconvString(): '%s'\n", strerror(errno));
70 std::string dst(outBuf);