curl-library
binary mode on Win32 but LF becomes CRLF
Date: Mon, 7 Jun 2004 16:26:04 -0500
I have been having a problem with a binary mode transfer on Win32.
I have a cgi program which will retrieve a file with http and write it
to stdout.
I have set the mode of stdout to binary.
All LFs are being converted to CRLF pairs.
I have found that by setting the CURLOPT_WRITEFUNCTION to fwrite with
CURLOPT_WRITEDATA set to stdout the problem goes away. (See code
fragment below.)
I have thought of 3 possible explanations:
1: libcurl is working properly but I don't understand how it is supposed
to work
2: Something went wrong when I built libcurl (i.e. it is just me)
3: This is a bug
Any insight as to why this is happening would be greatly appreciated. It
would be nice to hear whether or not it should work without these
options.
Setting CURLOPT_TRANSFERTEXT and CURLOPT_CRLF has had no effect.
This occurs with 7.11.2 and 7.12.0.
As an aside I needed to add
/def:".\libcurl.def"
to "project settings\link\project options" in VC6 to build 7.12.0.
Code fragment follows:
if ( _setmode( _fileno( stdout ), _O_BINARY ) == -1 )
ErrorPage("<B>Couldn't set stdout to binary.</B>\n");
else
{
CURL *curl;
CURLcode res;
res = curl_global_init(CURL_GLOBAL_ALL);
curl = curl_easy_init();
if( res != CURLE_OK || curl == NULL )
ErrorPage("<B>Couldn't initialize cURL.</B>\n");
else
{
curl_easy_setopt(curl, CURLOPT_HEADER, TRUE);
curl_easy_setopt(curl, CURLOPT_URL, pszURL);
//without the next two lines LFs become CRLFs
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, fwrite);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, (void
*)stdout);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
curl_global_cleanup();
fflush(stdout);
}
}
Received on 2004-06-07