summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorrubidium <rubidium@openttd.org>2008-09-02 20:24:55 +0000
committerrubidium <rubidium@openttd.org>2008-09-02 20:24:55 +0000
commita482f0053d4920359b7a010fbc47fcb3c5b0f13b (patch)
tree1fb979ccb1e0288d4011e9a4e0efb0d117a539f4
parent3ce1a5672ed004b2d9c96887bcb9011c396debaa (diff)
downloadopenttd-a482f0053d4920359b7a010fbc47fcb3c5b0f13b.tar.xz
(svn r14231) -Fix: Windows binaries not able to read non-windows newlines ini files. For more detail read the 'attached' diff.
-rw-r--r--src/ini.cpp14
1 files changed, 13 insertions, 1 deletions
diff --git a/src/ini.cpp b/src/ini.cpp
index defc913c9..61ac06289 100644
--- a/src/ini.cpp
+++ b/src/ini.cpp
@@ -146,7 +146,19 @@ void IniFile::LoadFromDisk(const char *filename)
uint comment_alloc = 0;
size_t end;
- FILE *in = FioFOpenFile(filename, "r", DATA_DIR, &end);
+ /*
+ * Now we are going to open a file that contains no more than simple
+ * plain text. That would raise the question: "why open the file as
+ * if it is a binary file?". That's simple... Microsoft, in all
+ * their greatness and wisdom decided it would be useful if ftell
+ * is aware of '\r\n' and "sees" that as a single character. The
+ * easiest way to test for that situation is by searching for '\n'
+ * and decrease the value every time you encounter a '\n'. This will
+ * thus also make ftell "see" the '\r' when it is not there, so the
+ * result of ftell will be highly unreliable. So to work around this
+ * marvel of wisdom we have to open in as a binary file.
+ */
+ FILE *in = FioFOpenFile(filename, "rb", DATA_DIR, &end);
if (in == NULL) return;
end += ftell(in);