std::string sys::OSUnix::getCurrentExecutable( const std::string& argvPathname) const { std::vector<std::string> possibleSymlinks; // Linux possibleSymlinks.push_back(sys::Path::joinPaths( sys::Path::delimiter()[0] + std::string("proc"), sys::Path::joinPaths("self", "exe"))); // Solaris possibleSymlinks.push_back(sys::Path::joinPaths( sys::Path::delimiter()[0] + std::string("proc"), sys::Path::joinPaths("self", sys::Path::joinPaths("path", "a.out")))); for (size_t ii = 0; ii < possibleSymlinks.size(); ++ii) { const std::string pathname = possibleSymlinks[ii]; if (!isFile(pathname)) { continue; } const std::string executableName = readLink(pathname); if (isFile(executableName)) { return executableName; } } return AbstractOS::getCurrentExecutable(argvPathname); }
void DLGFile::readLinks(const GFFList &list, std::vector<Link> &links) { for (GFFList::const_iterator l = list.begin(); l != list.end(); ++l) { links.push_back(Link()); readLink(**l, links.back()); } }
bool VoxMain::setToDaemon() { if(m_debug) return true; char buf[1024] = {0, }; ssize_t len = (-1); std::string pathout = std::string("/proc/self/fd/1"); std::string patherr = std::string("/proc/self/fd/2"); std::string redirectout = readLink(pathout); std::string redirecterr = readLink(patherr); struct stat fsout; struct stat fserr; memset(&fsout, 0, sizeof(fsout)); memset(&fserr, 0, sizeof(fserr)); freopen("/dev/null", "r", stdin); if(lstat(redirectout.c_str(), &fsout) == 0) { if(!S_ISREG(fsout.st_mode)) redirectout.clear(); } if(lstat(redirecterr.c_str(), &fserr) == 0) { if(!S_ISREG(fserr.st_mode)) redirecterr.clear(); } if(fork() != 0) exit(0); setsid(); setlinebuf(stdout); if(redirectout.empty()) freopen("/dev/null", "a+", stdout); if(redirecterr.empty()) freopen("/dev/null", "a+", stderr); return true; }
bool UltMtgReader::readData(QList<MtgEntity>& entityList, QList<QPair<int,int> >& edgeList) { if(!_unserializer->checkJavaSerialisationV05()) return false; if(!readMtgDataHeader()) return false; unsigned int entityNumber; if(!_unserializer->readInt(entityNumber)) return false; qDebug("[+] nbr entity : %d ",entityNumber); //Entities for(unsigned int i(0); i<entityNumber; ++i) { MtgEntity mtgEntity; mtgEntity._id = i; if(!readEntity(mtgEntity)) { qCritical("[X]readEntity failed : %d",i); return false; } entityList.append(mtgEntity); } //Links unsigned int linksNumber; if(!_unserializer->readInt(linksNumber)) return false; qDebug("[+] nbr edge : %d", linksNumber); for(unsigned int i(0); i<linksNumber; ++i) { QPair<int,int> edge; if(!readLink(edge)) { qCritical("[X] readLink failed : %d",i); return false; } edgeList.append(edge); } return true; }
void readSoftwareRadio(Element &headElem, RadioRepresentation& theRadio) { //Check for illegal nodes here Iterator< Node > c; for ( c = c.begin(&headElem); c != c.end(); c++ ) { if(c->Type() == TiXmlNode::ELEMENT) { string s = c->Value(); if(s != "controller" && s != "engine" && s!= "link") { LOG(LFATAL) << "Illegal element in xml file: " << s; throw XmlParsingException("Illegal element in xml file: " + s); } } } //Parse all the controllers Iterator< Element > child("controller"); for ( child = child.begin(&headElem); child != child.end(); child++ ) { ControllerDescription con = readController(*child); theRadio.addControllerDescription(con); } //Parse all the engines Iterator< Element > child1("engine"); for ( child1 = child1.begin(&headElem); child1 != child1.end(); child1++ ) { EngineDescription eng = readEngine(*child1); theRadio.addEngineDescription(eng); } //Parse all the links Iterator< Element > child2("link"); for ( child2 = child2.begin(&headElem); child2 != child2.end(); child2++ ) { LinkDescription link = readLink(*child2); theRadio.addLinkDescription(link); } }
bool resolveLink(const bfs::path& path, bfs::path& target) { bool rval = false; int cfd = -1; bfs::path linkVal = readLink(path); try { if (!linkVal.empty()) { bfs::path parent = path.parent_path(); if (!parent.empty()) { cfd = ::open(".", O_RDONLY, 0); if (cfd < 0) { throw string("unable to open ."); } if (::chdir(parent.c_str()) < 0) { throw string("unable to chdir to ") + parent.c_str(); } } char buf[PATH_MAX+1]; if (::realpath(path.c_str(), buf) == NULL) { throw string("realpath failed"); } target = buf; rval = pathExists(target); } } catch (const string&) { rval = false; } if (!rval) { target.clear(); } if (cfd >= 0) { ::fchdir(cfd); ::close(cfd); } return rval; }
void Fidelity::Engine::SimulationXmlReader::readSetup() { while(!atEnd()) { readNext(); // Stop here if setup tag completed if(isEndElement() && name() == "setup") { break; } // Evaluate child tags if (isStartElement()) { // We expect link tags only if (name() == "link") { readLink(); } else { unknownElement(); } } } }
int parseLine(int sect, char *line) // // Input: sect = current section of input file // *line = line of text read from input file // Output: returns error code or 0 if no error found // Purpose: parses contents of a tokenized line of text read from input file. // { int j, err; switch (sect) { case s_TITLE: return readTitle(line); case s_RAINGAGE: j = Mobjects[GAGE]; err = gage_readParams(j, Tok, Ntokens); Mobjects[GAGE]++; return err; case s_TEMP: return climate_readParams(Tok, Ntokens); case s_EVAP: return climate_readEvapParams(Tok, Ntokens); case s_ADJUST: //(5.1.007) return climate_readAdjustments(Tok, Ntokens); //(5.1.007) case s_SUBCATCH: j = Mobjects[SUBCATCH]; err = subcatch_readParams(j, Tok, Ntokens); Mobjects[SUBCATCH]++; return err; case s_SUBAREA: return subcatch_readSubareaParams(Tok, Ntokens); case s_INFIL: return infil_readParams(InfilModel, Tok, Ntokens); case s_AQUIFER: j = Mobjects[AQUIFER]; err = gwater_readAquiferParams(j, Tok, Ntokens); Mobjects[AQUIFER]++; return err; case s_GROUNDWATER: return gwater_readGroundwaterParams(Tok, Ntokens); case s_GWF: return gwater_readFlowExpression(Tok, Ntokens); case s_SNOWMELT: return snow_readMeltParams(Tok, Ntokens); case s_JUNCTION: return readNode(JUNCTION); case s_OUTFALL: return readNode(OUTFALL); case s_STORAGE: return readNode(STORAGE); case s_DIVIDER: return readNode(DIVIDER); case s_CONDUIT: return readLink(CONDUIT); case s_PUMP: return readLink(PUMP); case s_ORIFICE: return readLink(ORIFICE); case s_WEIR: return readLink(WEIR); case s_OUTLET: return readLink(OUTLET); case s_XSECTION: return link_readXsectParams(Tok, Ntokens); case s_TRANSECT: return transect_readParams(&Mobjects[TRANSECT], Tok, Ntokens); case s_LOSSES: return link_readLossParams(Tok, Ntokens); case s_POLLUTANT: j = Mobjects[POLLUT]; err = landuse_readPollutParams(j, Tok, Ntokens); Mobjects[POLLUT]++; return err; case s_LANDUSE: j = Mobjects[LANDUSE]; err = landuse_readParams(j, Tok, Ntokens); Mobjects[LANDUSE]++; return err; case s_BUILDUP: return landuse_readBuildupParams(Tok, Ntokens); case s_WASHOFF: return landuse_readWashoffParams(Tok, Ntokens); case s_COVERAGE: return subcatch_readLanduseParams(Tok, Ntokens); case s_INFLOW: return inflow_readExtInflow(Tok, Ntokens); case s_DWF: return inflow_readDwfInflow(Tok, Ntokens); case s_PATTERN: return inflow_readDwfPattern(Tok, Ntokens); case s_RDII: return rdii_readRdiiInflow(Tok, Ntokens); case s_UNITHYD: return rdii_readUnitHydParams(Tok, Ntokens); case s_LOADING: return subcatch_readInitBuildup(Tok, Ntokens); case s_TREATMENT: return treatmnt_readExpression(Tok, Ntokens); case s_CURVE: return table_readCurve(Tok, Ntokens); case s_TIMESERIES: return table_readTimeseries(Tok, Ntokens); case s_CONTROL: return readControl(Tok, Ntokens); case s_REPORT: return report_readOptions(Tok, Ntokens); case s_FILE: return iface_readFileParams(Tok, Ntokens); case s_LID_CONTROL: return lid_readProcParams(Tok, Ntokens); case s_LID_USAGE: return lid_readGroupParams(Tok, Ntokens); default: return 0; } }