From 61e0cb5dddb89ddab1d68791eb28d892c114622f Mon Sep 17 00:00:00 2001 From: Stef Walter Date: Sun, 3 Mar 2013 09:58:49 +0100 Subject: Open files in binary mode on windows So that the Windows' C library doesn't munge line endings --- tools/tests/test.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'tools/tests') diff --git a/tools/tests/test.c b/tools/tests/test.c index c445099..61fda83 100644 --- a/tools/tests/test.c +++ b/tools/tests/test.c @@ -54,20 +54,19 @@ read_file (CuTest *tc, const char *filename, long *len) { + struct stat sb; FILE *f = NULL; char *data; - f = fopen (filename, "r"); + f = fopen (filename, "rb"); if (f == NULL) CuFail_Line (tc, file, line, "Couldn't open file", filename); /* Figure out size */ - if (fseek (f, 0, SEEK_END) == -1 || - (*len = ftell (f)) == -1 || - fseek (f, 0, SEEK_SET) == -1) { - CuFail_Line (tc, file, line, "Couldn't get file length", filename); - } + if (stat (filename, &sb) < 0) + CuFail_Line (tc, file, line, "Couldn't stat file", filename); + *len = sb.st_size; data = malloc (*len ? *len : 1); assert (data != NULL); -- cgit v1.1