Commit df5e906b authored by SmilingWolf's avatar SmilingWolf Committed by Jean-Baptiste Kempf

Update fopen calls for Windows compatibility

Open files in binary mode, or on Windows fread/fwrite will treat the files as text and mangle the read/written data
parent decd4a95
...@@ -49,7 +49,7 @@ static int ivf_open(IvfInputContext *const c, const char *const file, ...@@ -49,7 +49,7 @@ static int ivf_open(IvfInputContext *const c, const char *const file,
uint8_t hdr[32]; uint8_t hdr[32];
memset(c, 0, sizeof(*c)); memset(c, 0, sizeof(*c));
if (!(c->f = fopen(file, "r"))) { if (!(c->f = fopen(file, "rb"))) {
fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno)); fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
return -1; return -1;
} else if ((res = fread(hdr, 32, 1, c->f)) != 1) { } else if ((res = fread(hdr, 32, 1, c->f)) != 1) {
......
...@@ -76,7 +76,7 @@ static int md5_open(MD5Context *const md5, const char *const file, ...@@ -76,7 +76,7 @@ static int md5_open(MD5Context *const md5, const char *const file,
{ {
if (!strcmp(file, "-")) { if (!strcmp(file, "-")) {
md5->f = stdout; md5->f = stdout;
} else if (!(md5->f = fopen(file, "w"))) { } else if (!(md5->f = fopen(file, "wb"))) {
fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno)); fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
return -1; return -1;
} }
......
...@@ -44,7 +44,7 @@ static int y4m2_open(Y4m2OutputContext *const c, const char *const file, ...@@ -44,7 +44,7 @@ static int y4m2_open(Y4m2OutputContext *const c, const char *const file,
{ {
if (!strcmp(file, "-")) { if (!strcmp(file, "-")) {
c->f = stdout; c->f = stdout;
} else if (!(c->f = fopen(file, "w"))) { } else if (!(c->f = fopen(file, "wb"))) {
fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno)); fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
return -1; return -1;
} }
......
...@@ -45,7 +45,7 @@ static int yuv_open(YuvOutputContext *const c, const char *const file, ...@@ -45,7 +45,7 @@ static int yuv_open(YuvOutputContext *const c, const char *const file,
{ {
if (!strcmp(file, "-")) { if (!strcmp(file, "-")) {
c->f = stdout; c->f = stdout;
} else if (!(c->f = fopen(file, "w"))) { } else if (!(c->f = fopen(file, "wb"))) {
fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno)); fprintf(stderr, "Failed to open %s: %s\n", file, strerror(errno));
return -1; return -1;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment