|
From: Ronald L. <R.L...@T-...> - 2006-01-12 19:14:39
|
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:
> From: John Gaughan <john@...>
> Subject: Re: [mingw - C/C++] why always read() file error?
> Newsgroups: gmane.comp.gnu.mingw.user
> Date: 2004-05-27 18:32:02 GMT (1 year, 32 weeks, 5 days, 15 hours and 11 minutes ago)
>
> SourceForge.net said:
>> I compile a program to read a file, but the return of read() function
>> always
>> less than my willing, how to deal with it?
>
> Could you show us what your code looks like and what the problem is?
>
> ifstream.read() should return the number of bytes read, if my [failing]
> memory serves me correctly.
>
> --
> John Gaughan
|