octave-bug-tracker
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Octave-bug-tracker] [bug #58055] ftell() incorrect on MS Windows platfo


From: Markus Mützel
Subject: [Octave-bug-tracker] [bug #58055] ftell() incorrect on MS Windows platforms if file is not encoded with CRLF line endings
Date: Sat, 11 Apr 2020 13:14:09 -0400 (EDT)
User-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:76.0) Gecko/20100101 Firefox/76.0

Follow-up Comment #18, bug #58055 (project octave):

I see the same results that jwe describes when using _fseeki64 and _ftelli64.
However, when using fseeko64 and ftello64 (like in the pasted code), the
results are as expected. Also fseeko and ftello works:

initial pos: 0
char: 102, pos: 1
char: 10, pos: 3
char: 111, pos: 4
char: 10, pos: 6
found beginning of third line (idx = 6)
char: 111, pos: 7
char: 10, pos: 9
char: 98, pos: 10
char: 10, pos: 12
char: 97, pos: 13
char: 10, pos: 15
char: 114, pos: 16
char: 10, pos: 18
reading again from beginning of third line (idx = 6)
char: 111, pos: 7
char: 10, pos: 9
char: 98, pos: 10
char: 10, pos: 12
char: 97, pos: 13
char: 10, pos: 15
char: 114, pos: 16
char: 10, pos: 18

I tried by compiling jwe's code with gcc in the msys2 environment (mingw64)
that comes with MXE Octave and replaced the defines with the respective
functions for the tests.

Looking at the gnulib sources, I don't know how we could end up calling
_fseeki64 and _ftelli64 (on mingw64).
If I correctly understand, we should be ending up calling fseeko and ftello
more or less directly.

If I change "foobar.txt" to have LF line endings, I see the following (for
ftello, fseeko):

initial pos: 0
char: 102, pos: -5
char: 10, pos: -3
char: 111, pos: -2
char: 10, pos: 0
found beginning of third line (idx = 0)
char: 111, pos: 1
char: 10, pos: 3
char: 98, pos: 4
char: 10, pos: 6
char: 97, pos: 7
char: 10, pos: 9
char: 114, pos: 10
char: 10, pos: 12
reading again from beginning of third line (idx = 0)
char: 102, pos: -5
char: 10, pos: -3
char: 111, pos: -2
char: 10, pos: 0
char: 111, pos: 1
char: 10, pos: 3
char: 98, pos: 4
char: 10, pos: 6
char: 97, pos: 7
char: 10, pos: 9
char: 114, pos: 10
char: 10, pos: 12


This seems to be a known issue:
https://developercommunity.visualstudio.com/content/problem/425878/fseek-ftell-fail-in-text-mode-for-unix-style-text.html

> As a workaround, you can disable stdio buffering by calling setvbuf() with
the _IONBF option, though this will decrease performance for programs that do
many small reads.

That workaround seems to work for me (see attachment).

So one solution would be to implement the workaround (with the potential
performance impact). 
Or we could better document that files not using CRLF line endings should be
opened in binary mode if the user wants to use ftell on Windows.

(file #48815)
    _______________________________________________________

Additional Item Attachment:

File name: fseek_example_2.c              Size:1 KB
    <https://savannah.gnu.org/file/fseek_example_2.c?file_id=48815>



    _______________________________________________________

Reply to this item at:

  <https://savannah.gnu.org/bugs/?58055>

_______________________________________________
  Message sent via Savannah
  https://savannah.gnu.org/




reply via email to

[Prev in Thread] Current Thread [Next in Thread]