std::shared_ptr<XStream> XFileManager::OpenFileStream(const XPath& branchAbsPath, const XString& leaf) { XPath fileAbsPath(branchAbsPath); fileAbsPath.AppendXStr(leaf); std::shared_ptr<XFileStream> streamp = XPool<XFileStream>::NewObject(); XFileStream& stream = *streamp; if (!stream.Open(fileAbsPath)) return std::shared_ptr<XFileStream>(); return streamp; }
/* Tests if file readable and may change name to add compression extension. Here to get ZLIB etc in one place stdin goes by unmolested by all the fussing with file names. We shouldn't close it, either. */ bool fileCoinReadable(std::string & fileName, const std::string &dfltPrefix) { if (fileName != "stdin") { const char dirsep = CoinFindDirSeparator(); std::string directory ; if (dfltPrefix == "") { directory = (dirsep == '/' ? "./" : ".\\") ; } else { directory = dfltPrefix ; if (directory[directory.length()-1] != dirsep) { directory += dirsep ; } } bool absolutePath = fileAbsPath(fileName) ; std::string field = fileName; if (absolutePath) { // nothing to do } else if (field[0]=='~') { char * home_dir = getenv("HOME"); if (home_dir) { std::string home(home_dir); field=field.erase(0,1); fileName = home+field; } else { fileName=field; } } else { fileName = directory+field; } } // I am opening it to make sure not odd FILE *fp; if (strcmp(fileName.c_str(),"stdin")) { fp = fopen ( fileName.c_str(), "r" ); } else { fp = stdin; } #ifdef COIN_HAS_ZLIB if (!fp) { std::string fname = fileName; fname += ".gz"; fp = fopen ( fname.c_str(), "r" ); if (fp) fileName=fname; } #endif #ifdef COIN_HAS_BZLIB if (!fp) { std::string fname = fileName; fname += ".bz2"; fp = fopen ( fname.c_str(), "r" ); if (fp) fileName=fname; } #endif if (!fp) { return false; } else { if (fp != stdin) { fclose(fp); } return true; } }