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:
parent
9475e9fd4a
commit
9ae9c1b2a6
|
@ -72,7 +72,17 @@ class File {
|
||||||
}
|
}
|
||||||
|
|
||||||
static File* Open(const char* filename, const char* mode) {
|
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;
|
if (!fp) return NULL;
|
||||||
return new File(fp);
|
return new File(fp);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user