curl-library
Re: UNICODE with libcurl on Win2K?
Date: Fri, 16 May 2003 12:36:12 -0700
On Fri, May 16, 2003 at 12:57:32PM -0400, Gerard Cheng wrote:
> Hi,
>
> I was wondering how to deal with UNICODE when using libcurl
> on Win2K. Perhaps an example will best describe the kinds
> of problems I am expecting.
>
> Here is a code fragment to call CWD over ftp to check if the
> remote directory exists:
>
> CURL *m_curlHandle;
> CURLcode m_curlReturn;
> struct curl_slist *CWDHeaderList = NULL;
> basic_string<TCHAR> sCWDCmd, sFTPDir;
>
> ...
>
> // Test if the directory exists by trying to CWD to it
> sCWDCmd = _T("CWD ") + sFTPDir;
> CWDHeaderList = curl_slist_append(CWDHeaderList, sCWDCmd.c_str());
>
> (void)curl_easy_setopt(m_curlHandle, CURLOPT_QUOTE, CWDHeaderList);
> m_curlReturn = curl_easy_perform(m_curlHandle);
>
> Under Win2K, when I compile with the pre-processor definitions
> "UNICODE" and "_UNICODE", TCHAR's become a wchar_t and the _T()
> macro is defined as "L".
>
> My problem is: to call curl_slist_append() above, the second
> parameter will need to be converted to a const char*. As written,
> there would be a compile error. However, if sFTPDir is a path that
> include non-ASCII characters (eg, the path is in Japanese), I can't
> use a const char*. How do I handle this?
It depends on how the format of the directory name as expected by the remote
FTP server. Chances are, the server will expect a name in UTF-8 format in
which case you need to convert your UTF-16 name as wchar_t to a UTF-8
name as char *. If the server expects something other than UTF-8, then
you'll have to find out what it expects and convert to that instead. Windows
has a WideCharToMultiByte call that can probably be used for the conversion,
or there's the ANSI function wcstombs.
>>> Dan
-- http://www.MoveAnnouncer.com The web change of address service Let webmasters know that your web site has moved ------------------------------------------------------- Enterprise Linux Forum Conference & Expo, June 4-6, 2003, Santa Clara The only event dedicated to issues related to Linux enterprise solutions www.enterpriselinuxforum.comReceived on 2003-05-16