From c7ae92621c43ae0e04a51d38b88f5f74f2861633 Mon Sep 17 00:00:00 2001 From: Jesse Date: Tue, 16 Sep 2014 14:15:33 +0800 Subject: [PATCH] On Windows, read CRLF ending file exist some problem that tested by MinGW and VS2008. 1)open CRLF ending file in text mode 2) fseek(f, 0, SEEK_END); long pos = ftell(f); // return the file total byte fseek(f, 0, SEEK_SET); 3) int nread = fread(buf, pos, 1, f); // always return 0 to nread int nread = fread(buf, 1, pos, f); // return readed byte with CRLF converted to LF. it means pos - nread = CRLF's count. --- src/jconf.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/jconf.c b/src/jconf.c index 91f08a07..bbfed55c 100644 --- a/src/jconf.c +++ b/src/jconf.c @@ -102,7 +102,7 @@ jconf_t *read_jconf(const char* file) char *buf; json_value *obj; - FILE *f = fopen(file, "r"); + FILE *f = fopen(file, "rb"); if (f == NULL) FATAL("Invalid config path."); fseek(f, 0, SEEK_END);