diff options
author | Stef Walter <stefw@gnome.org> | 2013-03-03 09:58:49 +0100 |
---|---|---|
committer | Stef Walter <stefw@gnome.org> | 2013-03-03 10:07:14 +0100 |
commit | 61e0cb5dddb89ddab1d68791eb28d892c114622f (patch) | |
tree | 56d6c5d62ad4a9cd4f25693d9412283c5cb2b229 /tools/tests | |
parent | d9076a99c59bb0132b25277a2340f428c9b6c98e (diff) |
Open files in binary mode on windows
So that the Windows' C library doesn't munge line endings
Diffstat (limited to 'tools/tests')
-rw-r--r-- | tools/tests/test.c | 11 |
1 files changed, 5 insertions, 6 deletions
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); |