This is the mail archive of the cygwin@sourceware.cygnus.com mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

problem w/ mingw32/egcs/msvcrt and file reads


I'm trying to write a program that includes a simple routine to read a
text file line by line. The following code works fine using the latest
mingw32/egcs, without the msvcrt40-runtime stuff installed, but when I use
the msvcrt40 stuff, I get a general protection fault at the first call to
getline (in the while loop). I also notice that in an objdump -p of the
resulting executable (with msvcrt-runtime installed), crtdll.dll is still
being linked in. I thought that's what the msvcrt-runtime was trying to
avoid?
  Any ideas why this is happening? I imagine I'm just doing something
dumb, but I've been staring at this for hours and can't figure it out.
  Thanks!

#include <iostream>
#include <fstream>

int PDBFile::readFile(const string &fileName) {

  ifstream in(fileName.data(),ios::in|ios::nocreate);
  if (!in || !in.is_open()) {
    cerr << "Couldn't open file " << fileName << '\n';
    return PROBLEM;
  } else
    cout << "Reading " << fileName << '\n';

  char line[MaxLineLen];
  while (in.getline(line,MaxLineLen) && !(in.eof() || in.fail())) {
    ;  // do stuff w/ lines here
  }
  if (!in.eof()) {
    cerr << "Problem reading " << fileName << ", possibly a line too
long\n";
    return PROBLEM;
  }

  return OKAY;
}


 - Paul

-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-
  Paul A.   |      paul@grserv.med.jhmi.edu      |  Johns Hopkins
 Thiessen   |  http://grserv.med.jhmi.edu/~paul  |   University
-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-


--
Want to unsubscribe from this list?
Send a message to cygwin-unsubscribe@sourceware.cygnus.com


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]