src/share/vm/utilities/ostream.cpp

changeset 2515
d8a72fbc4be7
parent 2322
828eafbd85cc
child 2570
5841dc1964f0
     1.1 --- a/src/share/vm/utilities/ostream.cpp	Thu Feb 03 20:30:19 2011 -0800
     1.2 +++ b/src/share/vm/utilities/ostream.cpp	Tue Feb 08 17:20:45 2011 -0500
     1.3 @@ -314,6 +314,11 @@
     1.4    _need_close = true;
     1.5  }
     1.6  
     1.7 +fileStream::fileStream(const char* file_name, const char* opentype) {
     1.8 +  _file = fopen(file_name, opentype);
     1.9 +  _need_close = true;
    1.10 +}
    1.11 +
    1.12  void fileStream::write(const char* s, size_t len) {
    1.13    if (_file != NULL)  {
    1.14      // Make an unused local variable to avoid warning from gcc 4.x compiler.
    1.15 @@ -322,6 +327,25 @@
    1.16    update_position(s, len);
    1.17  }
    1.18  
    1.19 +long fileStream::fileSize() {
    1.20 +  long size = -1;
    1.21 +  if (_file != NULL) {
    1.22 +    long pos  = ::ftell(_file);
    1.23 +    if (::fseek(_file, 0, SEEK_END) == 0) {
    1.24 +      size = ::ftell(_file);
    1.25 +    }
    1.26 +    ::fseek(_file, pos, SEEK_SET);
    1.27 +  }
    1.28 +  return size;
    1.29 +}
    1.30 +
    1.31 +char* fileStream::readln(char *data, int count ) {
    1.32 +  char * ret = ::fgets(data, count, _file);
    1.33 +  //Get rid of annoying \n char
    1.34 +  data[::strlen(data)-1] = '\0';
    1.35 +  return ret;
    1.36 +}
    1.37 +
    1.38  fileStream::~fileStream() {
    1.39    if (_file != NULL) {
    1.40      if (_need_close) fclose(_file);

mercurial