[xml] Nano HTTP: Text vs Binary (unportable code)


I'm writting a simple test program that downloads a file using NanoHTTP. 
The first version of this program (about 3 lines) works perfectly on Linux, 
but it's a total mess on Windows.

Rewritting another version, I found out that the problem is that the file is 
saved in text mode. Which of course is totally wrong for a file such as an 
image for example.
The second version correctly works under Linux and Windows.

(see attachment for both versions)

While looking over xmlNanoHTTPFetch() implementation, I noticed that:

1) Unportable UNIX system calls are used for handling files. Why not use FILE* 
which is the portable way to handle files in C?
I suppose that one way or another libxml translates these to the correct 
Windows functions (_open() and _write() instead of open() and write()).

2) As the symptoms suggest, the file is opened in default mode, which is text 
Notice that under Linux there isn't really such a thing as a text mode, 
because it's the same as the binary mode; which is why you can't specify 
O_BINARY in open() under Linux (I don't see it in the man page, but I could 
be wrong).
But under Windows, it's not the same and some characters get modified (ex: 
'\n' becomes LineFeed + CarriageReturn, or something like that).

So, shouldn't files be always saved in binary?

But wouldn't it affect text files then (ex: HTML)? This will be an issue of 
the text mode handling isn't done at a higher level. Otherwise text/binary 
mode has to be selected depending on the content type :-(

AFAIK this limitation affects other functions that xmlNanoHTTPFetch()

Best regards,


Attachment: html.cpp
Description: Text Data

[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]