M
Morten Rodal
#include <iostream>
#include <fstream>
using namespace std;
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
int main(int argc, char **argv) {
int length, chunksize, offset = 0;
char *buf = new char[BUFSIZ];
ifstream is;
is.open(argv[1], ios::binary);
if (!is)
return 1;
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(offset, ios::beg);
while (offset < length) {
#if THIS_WORKS
is.read(buf, BUFSIZ);
offset += chunksize = is.gcount();
#else
offset += chunksize = is.readsome(buf, BUFSIZ);
#endif
cout << "CHUNKSIZE:" << chunksize <<
", OFFSET:" << offset << ", LENGTH:" << length << endl;
}
return 0;
}
With g++ 3.3.3 on Freebsd and Linux or 3.2.2 on SGI Irix read files
properly. On Linux (Gentoo distribution) the chunksize is always zero,
but on FreeBSD it is able to read some bytes but suddenly stops.
Compiling the same program with Intel's C++ compiler (icpc) on FreeBSD or
Linux makes the program work just fine. Using SGI's MIPSpro compiler also
works.
Any ideas where to look?
#include <fstream>
using namespace std;
#ifndef BUFSIZ
#define BUFSIZ 1024
#endif
int main(int argc, char **argv) {
int length, chunksize, offset = 0;
char *buf = new char[BUFSIZ];
ifstream is;
is.open(argv[1], ios::binary);
if (!is)
return 1;
is.seekg(0, ios::end);
length = is.tellg();
is.seekg(offset, ios::beg);
while (offset < length) {
#if THIS_WORKS
is.read(buf, BUFSIZ);
offset += chunksize = is.gcount();
#else
offset += chunksize = is.readsome(buf, BUFSIZ);
#endif
cout << "CHUNKSIZE:" << chunksize <<
", OFFSET:" << offset << ", LENGTH:" << length << endl;
}
return 0;
}
With g++ 3.3.3 on Freebsd and Linux or 3.2.2 on SGI Irix read files
properly. On Linux (Gentoo distribution) the chunksize is always zero,
but on FreeBSD it is able to read some bytes but suddenly stops.
Compiling the same program with Intel's C++ compiler (icpc) on FreeBSD or
Linux makes the program work just fine. Using SGI's MIPSpro compiler also
works.
Any ideas where to look?