From: Danny S. <dan...@cl...> - 2006-01-12 22:45:29
|
----- Original Message ----- From: "Earnie Boyd" Sent: Friday, 13 January 2006 11:26 > Quoting Ronald Lamprecht <R.Lamprecht@T-Online.de>: > > > Hi, > > > > Using the current mingw3.4.2 the following simple example used with a > > Windows CR+LF lineterminated testfile of more than 512 bytes results in > > wrong gcount() and eof(): > > > > std::ifstream ifs("my_cr_lf_file.txt"); > > std::vector<char> dest; > > int blocksize = 512; > > size_t len = 0; > > int nread=0; > > do { > > dest.resize(dest.size() + blocksize); > > is.read (&dest[len], blocksize); > > nread = is.gcount(); > > len += nread; > > } while (nread == blocksize); > > > > If the testfile consists of 17 lines within the first 512 bytes > > gcount() will return 495 and eof() will be true after the first read() > > call. Looks like a problem with CR+LF to LF convertion in read(). > > > > I found the following hint in this mailing list that was missing details > > and code examples: > > > > Microsoft when creating MSDOS introduced your problem. If the i/o > channel is in ``text mode'' the read will return a count of one less > than actually read if the lines of the file end with \r\n. Set your > file descriptor to ``binary mode'' to correct the issue or use the > dos2unix utility to change the file to \n line endings instead of \r\n. > Actually, fstream should still work correctly in text mode. This was PR libstdc++/20806. It is fixed in gcc-3.4.5. No need to use binary mode. Danny > Earnie Boyd > > ---------------------------------------------------------------- > This message was sent using IMP, the Internet Messaging Program. > > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ > MinGW-users mailing list > Min...@li... > > You may change your MinGW Account Options or unsubscribe at: > https://lists.sourceforge.net/lists/listinfo/mingw-users |