1
0
mirror of https://github.com/OlafvdSpek/ctemplate.git synced 2025-09-28 19:05:49 +08:00

Make sure we open files for reading or writing in binary mode. That

way, \r isn't silently stripped on windows.

R=jad
This commit is contained in:
csilvers 2011-07-27 01:01:06 +00:00
parent 9475e9fd4a
commit 9ae9c1b2a6

View File

@ -72,7 +72,17 @@ class File {
}
static File* Open(const char* filename, const char* mode) {
FILE* fp = fopen(filename, mode);
char binary_mode[3];
const char* mode_to_use = mode;
if ((mode[0] == 'r' || mode[0] == 'w') && mode[1] == '\0') {
// We add a 'b' to make sure we do the right thing even on
// Windows. On unix, this will be a noop.
binary_mode[0] = mode[0];
binary_mode[1] = 'b';
binary_mode[2] = '\0';
mode_to_use = binary_mode;
}
FILE* fp = fopen(filename, mode_to_use);
if (!fp) return NULL;
return new File(fp);
}