Changeset 1001


Ignore:
Timestamp:
Jan 1, 2008, 11:19:57 PM (13 years ago)
Author:
Peter
Message:

reset errno to zero when it is an expected error

Location:
trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/test/fileutil_test.cc

    r1000 r1001  
    140140  }
    141141
     142  // checking permissions on existent file after non-existence file
     143  // has been checked
     144  try {
     145    *error << "FileUtil Test 5" << std::endl;
     146    bool testval=true;
     147     // intermediate dir must be unique!
     148    utility::FileUtil file("./fileio_test.sdf34DSF/file");
     149    if (!(testval=file.exists()))
     150      *error << "\tfile does not exist: " << file.path() << std::endl;
     151    ok&=!testval;
     152    utility::FileUtil file2("fileutil_test.cc");
     153    if (!(testval=!file2.exists()))
     154      *error << "\tfile does exist: " << file2.path() << std::endl;
     155    ok&=!testval;
     156  }
     157  catch (utility::IO_error e) {
     158    ok=false;
     159    *error << e.what() << std::endl;
     160  }
     161
     162 
     163
    142164  *error << (ok ? "OK" : "Failed") << std::endl;
    143165  if (error!=&std::cerr)
  • trunk/yat/utility/FileUtil.cc

    r1000 r1001  
    7676    if ( stat(path_.c_str(),&statt) && (errno!=ENOENT) )
    7777      throw IO_error(std::string("stat(2) call failed with errno: "+errno));
    78     return !errno;  // 0 if file exists, non-zero if file does not exist
     78    if (errno) {
     79      errno = 0; // don't leave errno in state of failure
     80      return false;
     81    }
     82    return true;
    7983  }
    8084
Note: See TracChangeset for help on using the changeset viewer.