#459 tellg/seekg bug with DOS text files

None
closed-invalid
nobody
gcc (462)
2013-01-18
2003-11-24
No

Using tellg/seekg to backup by one line in some DOS text
files is going to the wrong location now both with MinGW
GCC 3.2.3 and Cygwin GCC 3.3.1. Using seekg with a
tellg value doesn't return to the correct point in the file.
It works properly with *nix text files (\n line endings).

Other users have tried the example on non-MinGW GCCs
and report that it works correctly for DOS and *nix text
files so I believe this is a bug in the MinGW port.

--
Stuart

// seek.cc
//
// Build with g++ seek.cc -o seek.exe

#include <string>
#include <iostream>
#include <fstream>

int
main()
{
std::ifstream afile( "sample.txt" );
std::string inp_line;
getline( afile, inp_line );
std::cout << inp_line << std::endl;
std::streampos sp = afile.tellg(); // Start of 2nd line
getline( afile, inp_line );
std::cout << inp_line << std::endl;
getline( afile, inp_line );
std::cout << inp_line << std::endl;
afile.seekg( sp ); // Return to start of 2nd line
getline( afile, inp_line );
std::cout << inp_line << std::endl;
afile.close();
return 0;
}

/* sample.txt File (DOS line endings)

first line
second line
third line
fourth line

*/

/* Output generated by MinGW GCC 3.2.3 or Cygwin
GCC 3.3.1

first line
second line
third line
nd line

*/

Additional Information:

Platform: Windows 2000 SP2

g++ -v
Reading specs from E:/mingw/bin/../lib/gcc-
lib/mingw32/3.2.3/specs
Configured with: ../gcc/configure --with-gcc --with-gnu-
ld --with-gnu-as --host=mingw32 --target=mingw32 --
prefix=/mingw --enable-th
reads --disable-nls --enable-languages=c++,f77,objc --
disable-win32-registry --disable-shared --enable-sjlj-
exceptions
Thread model: win32
gcc version 3.2.3 (mingw special 20030504-1)

ld -v
GNU ld version 2.13.90 20030111

MinGW installation from separate components

Tested in Windows console environment

#define __MINGW32_VERSION 3.2

win32api version 2.4

Discussion

  • Danny Smith

    Danny Smith - 2003-11-24
    • assigned_to: dannysmith --> nobody
     
  • Danny Smith

    Danny Smith - 2003-11-24

    Logged In: YES
    user_id=11494

    Not mine. This should be followed up on libstdc++ lists or
    gcc's bugzilla.

    Danny

     
  • Earnie Boyd

    Earnie Boyd - 2012-10-23

    Actually, you cannot reliably use seek/tell on text mode file descriptors. You must set them to binary mode first.

     
  • Earnie Boyd

    Earnie Boyd - 2012-10-23
    • milestone: --> Aged_issue
    • status: open --> closed-invalid
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

JavaScript is required for this form.





No, thanks