Commit 10554b9
committed
Eof: Don't check ftell() in text-mode
ftell() and ftello64() cannot safely be used on text-mode streams in the
way Eof() was using it: It assumed the returned value was a valid file
offset corresponding to the current position, but ftell() isn't guaranteed
to actually return that. It's only guaranteed to return something that can
be used with fseek().
I ran into this issue on Windows when reading a file with LF line endings
(instead of CRLF) in text mode. The ftell() value was different from the
real file offset (probably due to the internal LF => CRLF conversions?),
causing Eof() to return TRUE too early. I've added the test case - it
failed for me on Windows.
It seems that whether ftell() gives a useful result also depends on file
size and the buffer size set with setvbuf(... _IOFBF ...) (FB uses that
too). The point is that ftell() isn't guaranteed to give valid file offsets
in text-mode.
Instead, this patch changes Eof() to peek ahead via getc()/ungetc(), and
check for EOF this way.1 parent 344389a commit 10554b9
File tree
5 files changed
+3409
-14
lines changed- src/rtlib
- tests/file
5 files changed
+3409
-14
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
18 | 18 | | |
19 | 19 | | |
20 | 20 | | |
| 21 | + | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
4 | 4 | | |
5 | 5 | | |
6 | 6 | | |
7 | | - | |
8 | 7 | | |
9 | 8 | | |
10 | 9 | | |
| |||
16 | 15 | | |
17 | 16 | | |
18 | 17 | | |
19 | | - | |
20 | | - | |
| 18 | + | |
21 | 19 | | |
22 | 20 | | |
23 | 21 | | |
24 | 22 | | |
25 | 23 | | |
26 | | - | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
27 | 27 | | |
28 | 28 | | |
29 | 29 | | |
30 | 30 | | |
31 | | - | |
32 | | - | |
33 | | - | |
34 | | - | |
35 | | - | |
36 | | - | |
37 | | - | |
38 | | - | |
39 | | - | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
40 | 42 | | |
41 | 43 | | |
42 | 44 | | |
43 | 45 | | |
44 | 46 | | |
45 | 47 | | |
46 | | - | |
| 48 | + | |
47 | 49 | | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
0 commit comments