[PATCH] file.c: open a file in binary mode in readfile()
Lubomir I. Ivanov
neolit123 at gmail.com
Fri Aug 24 15:39:00 PDT 2012
From: "Lubomir I. Ivanov" <neolit123 at gmail.com>
O_TEXT is the default mode for fctrl's open() and on windows created
files, line endings are counted by fstat() as CR+LF adding an extra
byte for each line. the result from this is that, while the file still
can be read into a buffer, the read() return (ret) has a different
size compared to the previously allocated buffer, breaking at:
if (ret == mem->size)
a solution is to open() the file in O_BINARY mode, which should
technically suppress the EOL translation.
Signed-off-by: Lubomir I. Ivanov <neolit123 at gmail.com>
---
file.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/file.c b/file.c
index e016390..9483f54 100644
--- a/file.c
+++ b/file.c
@@ -17,7 +17,7 @@ static int readfile(const char *filename, struct memblock *mem)
mem->buffer = NULL;
mem->size = 0;
- fd = open(filename, O_RDONLY);
+ fd = open(filename, O_RDONLY | O_BINARY);
if (fd < 0)
return fd;
ret = fstat(fd, &st);
--
1.7.11.msysgit.0
More information about the subsurface
mailing list