cURL / Mailing Lists / curl-users / Single Mail

curl-users

textmode/binmode and the test script

From: Roth, Kevin P. <KPRoth_at_MarathonOil.com>
Date: Wed, 10 Oct 2001 13:51:04 -0400

Hi there. While attempting to run the test scripts under Cygwin 1.3.3 on
a windows-2000 workstation, I ran across a textmode vs binmode issue.

The issue stems from the fact that cygwin allows you to choose the
default End-Of-Line behavior as either "DOS" or "Unix", which translates
to mounting disk partitions into the Cygwin filesystem in "textmode" or
"binmode" (binary). In my current installation, I have chosen DOS
end-of-lines. The result was that most of the tests were failing. I dug
into a bit, and found that they were failing because of strange
end-of-line issues.

The first one I tackled was with httpserver.pl's printing of the input
data to server.input. Those end-of-lines ended up looking like "\r\r\n",
which means cygwin caught the "\n" in the normal "\r\n" HTTP end-of-line
(turning \r\n into \r\r\n)... I was able to fix that by adding the line:
  binmode(INPUT,":raw");
right after open(INPUT, ">>log/server.input").

That fixed most of the problems, up until test9 and test15. I'll address
test9 below. But test15 (saving curl.exe's stdout into a file via shell
redirection) had similar issues, that couldn't be resolved with this
fix. I tried a couple other binmode() lines and some s/\r\r/\r/g's, and
couldn't clean it up easily (for the most part, it seemed things were
getting written to disk through cygwin's unix<->dos filter, but were
getting read directly; I could be wrong). So I removed the binmode line
mentioned in the previous paragraph, and resorted to a different "fix".

In getpart.pm:compareparts(), I changed it as follows:

>>>>>>>>>>>
 for(1 .. $sizefirst) {
     my $index = $_ - 1;
     if($firstref->[$index] ne $secondref->[$index]) {
         return 1+$index;
     }
 }
----- becomes -----
 for(1 .. $sizefirst) {
     my $index = $_ - 1;
     if($firstref->[$index] ne $secondref->[$index]) {
         (my $aa = $firstref->[$index]) =~ s/\r+\n$/\n/;
         (my $bb = $secondref->[$index]) =~ s/\r+\n$/\n/;
         if($aa ne $bb) {
             return 1+$index;
         }
     }
 }
<<<<<<<<<<<

This removes ALL extraneous \r characters from the end-of-lines and
retries the line comparison without them, to effectively ignore any
differences in end-of-line characters.

This fixed all tests up until test9, which generates a temp file out of
the test9 data file, and then tells curl to upload the file. The problem
was that it was getting the Content-Length wrong, by 3 characters (one
for each end-of-line). I was able to fix this by changing
getpart.pm:writearray(), as follows:

>>>>>>>>>>>>>
    open(TEMP, ">$filename");
    for(@$arrayref) {
        print TEMP $_;
    }
----- becomes -----
    open(TEMP, ">$filename");
    binmode(TEMP,":raw");
    for(@$arrayref) {
        print TEMP $_;
    }
<<<<<<<<<<<<

If these changes seem to make sense, it would probably be nice to add
them. Otherwise, it would be best to document that cygwin with DOS EOF's
isn't capable of passing the tests.

I may eventually switch my cygwin installation to binary mode and see if
that helps any...

--Kevin
Received on 2001-10-10