mirror of
https://github.com/subsurface/subsurface.git
synced 2024-11-30 22:20:21 +00:00
file.c: open a file in binary mode in readfile()
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@gmail.com> [ Fixed to work under real operating systems that don't need this crap. "Here's a nickel, kid, go and buy a real OS". - Linus ] Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
This commit is contained in:
parent
415383d65e
commit
642c83f532
1 changed files with 6 additions and 1 deletions
7
file.c
7
file.c
|
@ -8,6 +8,11 @@
|
|||
#include "dive.h"
|
||||
#include "file.h"
|
||||
|
||||
/* Crazy windows sh*t */
|
||||
#ifndef O_BINARY
|
||||
#define O_BINARY 0
|
||||
#endif
|
||||
|
||||
static int readfile(const char *filename, struct memblock *mem)
|
||||
{
|
||||
int ret, fd;
|
||||
|
@ -17,7 +22,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);
|
||||
|
|
Loading…
Reference in a new issue