Update of patch #2843 (project freeciv):

         Planned Release:                         => 2.3.1,2.4.0            
                 Summary: Make secfile reading cope with \r\n and \n\r line
endings on all platforms => Make secfile reading cope with rn and nr line
endings on all platforms


Follow-up Comment #1:

After some experimentation, I believe the principle behind this patch is safe
for Windows.

Compiling and running the attached test program for Windows (with MinGW,
which I believe will use MSVCRT for the standard library) suggests the
following facts about fgets() on Windows:
* When reading a DOS file (0D 0A) in text mode, it treats 0D 0A as the line
ending character, and 0A is what ends up at the end of the fetched string (all
as expected/standard)
* When reading a DOS file in _binary_ mode, it treats _0A_ as the line ending
character, so the strings returned by fgets() are XX XX... 0D 0A
* When reading a Unix file (0A), it breaks lines at 0A; what you see doesn't
depend on whether it was opened in binary mode, of course. (So Windows fgets()
has no trouble reading Unix files; I don't know why Notepad can't cope,
grumble grumble.)
* fgets() doesn't treat 0A 0D as a valid line ending; the 0Ds leak into the
string even in text mode. (I've no reason to believe such files are common,
I'm just handling them for completeness.)
* fgets() entirely fails to spot old-Mac line endings (0D), treating the file
as one long line. (But we established in bug #18396 that that's irrelevant
these days.)

So, I believe that Windows and Unix builds with this patch will be able to
cope with each of Windows and Unix files, regardless of whether the file is
opened in text or binary mode. (This may enable more files to be
gzipped/bzipped/etc, as I suspect that any compressed file read is effectively
in binary mode.)

Separately, testing an S2_3 Windows build from cazfi with this patch, the
resulting freeciv-gtk2 coped with helpdata.txt regardless of whether it had
Windows or Unix line endings, with localisation working correctly in both
cases. Other secfile reading such as rulesets seemed to work too (these files
would have had Unix line endings). I don't actually know whether the files
were being opened in binary or text mode, but from the above, it doesn't

(file #13697)

Additional Item Attachment:

File name: fgets.c                        Size:0 KB


Reply to this item at:


  Message sent via/by Gna!

Freeciv-dev mailing list

Reply via email to