bool ESDLcompiler::locateIncludedFile(StringBuffer& filepath, const char* prot, const char* srcDir, const char* fname, const char* ext) { StringBuffer alternateExtFilename; alternateExtFilename.setf("%s%s%s", (prot && *prot) ? prot : "", srcDir, fname); const char* alt_ext; if (stricmp(ext, LEGACY_FILE_EXTENSION)==0) alt_ext = ESDL_FILE_EXTENSION; else alt_ext = LEGACY_FILE_EXTENSION; alternateExtFilename.append(alt_ext); OwnedIFile fileInSrcDir = createIFile(alternateExtFilename.str()); if (fileInSrcDir->exists()) { filepath.set(alternateExtFilename.str()); return true; } ForEachItemIn(x, includeDirs) { const char* dir = includeDirs.item(x); if (dir && *dir) { StringBuffer pathInInclude(dir); pathInInclude.trim(); if (pathInInclude.charAt(pathInInclude.length() - 1) != PATHSEPCHAR) pathInInclude.append(PATHSEPCHAR); pathInInclude.append(fname); VStringBuffer pathInIncludeFull("%s%s", pathInInclude.str(), ext); OwnedIFile fileInInclude = createIFile(pathInIncludeFull.str()); if (fileInInclude->exists()) { filepath.set(pathInIncludeFull.str()); return true; } pathInIncludeFull.setf("%s%s", pathInInclude.str(), alt_ext); OwnedIFile altFileInInclude = createIFile(pathInIncludeFull.str()); if (altFileInInclude->exists()) { filepath.set(pathInIncludeFull.str()); return true; } } } filepath.clear(); return false; }
StringBuffer& CLocalDataLogger::writeData(const StringBuffer& dataToCache,const StringBuffer& tokenName,StringBuffer& returnPath) { DBGLOG("CLocalDataLogger::writeData"); StringBuffer tmpFile; getFilePath(tokenName.str(),tmpFile); Owned<IFile> file = createIFile(tmpFile.str()); for (int i = 0; i < RETRIES; ++i) { try{ Owned<IFileIO> io = file->open(IFOwrite); size32_t filesize = dataToCache.length(); void* filedata = (void*)dataToCache.str(); io->write(0,filesize ,filedata ); if(m_UrlRoot.length()==0) returnPath.appendf("/Cache?Name=%s.HTML",tokenName.str()); else returnPath.appendf("/%s/Cache?Name=%s.HTML",m_UrlRoot.str(),tokenName.str()); break; } catch(IOSException *ose) { //The web site could be serving up the page as we try to update it... ose->Release(); Sleep(10); } catch(...) { DBGLOG("Unknown exception thrown while reading local data logger file"); } } return returnPath; }
bool CTransformerBase::setPartition(RemoteFilename & remoteInputName, offset_t _startOffset, offset_t _length) { inputFile.setown(createIFile(remoteInputName)); startOffset = _startOffset; maxOffset = _startOffset + _length; return true; }
int main(int argc, char* argv[]) { InitModuleObjects(); EnableSEHtoExceptionMapping(); if (argc<6) { usage(); return 0; } try { const char *filename = argv[1]; Owned<IDaliCapabilityCreator> cc = createDaliCapabilityCreator(); cc->setSystemID(argv[2]); cc->setServerPassword(argv[3]); for (unsigned i=4;i<argc;i++) { const char *cmd = argv[i++]; if (i==argc) break; const char *param = argv[i]; if (stricmp(cmd,"THORWIDTH")==0) { cc->setLimit(DCR_ThorSlave,atoi(param)); } else if (stricmp(cmd,"DALINODE")==0) { StringBuffer mac; if (strchr(param,'.')) { // must be ip IpAddress ip; ip.set(param); if (!getMAC(ip,mac)) { printf("ERROR: could mot get MAC address for %s\n",param); return 1; } } else mac.append(param); cc->addCapability(DCR_DaliServer,mac.str()); } else { printf("ERROR: unknown command %s\n",cmd); return 1; } } StringBuffer results; cc->save(results); Owned<IFile> ifile = createIFile(filename); Owned<IFileIO> ifileio = ifile->open(IFOcreate); ifileio->write(0,results.length(),results.str()); printf("Dali Capabilities sucessfully exported to %s\n", filename); } catch (IException *e) { EXCLOG(e); e->Release(); } releaseAtoms(); return 0; }
void printKeywordsToXml() { StringBuffer buffer; unsigned int nGroups = sizeof(keywordList)/sizeof(keywordList[0]); buffer.append("<xml>\n"); for (unsigned i = 0; i < nGroups; ++i) { buffer.append(" <cat group=\"").append(keywordList[i].group).append("\">\n"); unsigned int j = 0; while(keywordList[i].keywords[j]) { buffer.append(" <keyword name=\"").append(keywordList[i].keywords[j]).append("\"/>\n"); ++j; } buffer.append(" </cat>\n"); } buffer.append("</xml>\n"); Owned<IFile> treeFile = createIFile("ECLKeywords.xml"); assertex(treeFile); Owned<IFileIO> io = treeFile->open(IFOcreaterw); assertex(io); Owned<IIOStream> out = createIOStream(io); assertex(out); out->write(buffer.length(), buffer.str()); }
void SafePluginMap::loadFromList(const char * pluginsList) { const char *pluginDir = pluginsList; for (;*pluginDir;) { StringBuffer thisPlugin; while (*pluginDir && *pluginDir != ENVSEPCHAR) thisPlugin.append(*pluginDir++); if(*pluginDir) pluginDir++; if(!thisPlugin.length()) continue; Owned<IFile> file = createIFile(thisPlugin.str()); if (file->isDirectory() == foundYes) loadFromDirectory(thisPlugin); else { StringBuffer tail; splitFilename(thisPlugin, NULL, NULL, &tail, &tail); addPlugin(thisPlugin, tail.str()); } } }
void CConfigGenEngine::createFakePlugins(StringBuffer& destFilePath) const { String destFilePathStr(destFilePath); String* tmpstr = destFilePathStr.toLowerCase(); if (!tmpstr->endsWith("plugins.xml")) { int index = tmpstr->indexOf("plugins.xml"); destFilePath.remove(index + 11, destFilePath.length() - (index + 11)); } delete tmpstr; StringBuffer tmpoutbuf("<?xml version=\"1.0\" encoding=\"UTF-8\"?><Plugins/>"); if (m_instances.ordinality() > 1 && strcmp(m_process.queryName(), XML_TAG_ESPPROCESS)) destFilePath.replaceString("@temp"PATHSEPSTR, m_cachePath); else { char tempPath[_MAX_PATH]; getTempPath(tempPath, sizeof(tempPath), m_name); ensurePath(tempPath); destFilePath.replaceString("@temp"PATHSEPSTR, tempPath); } Owned<IFile> pTargetFile = createIFile(destFilePath.str()); if (pTargetFile->exists() && pTargetFile->isReadOnly()) pTargetFile->setReadOnly(false); Owned<IFileIO> pTargetFileIO = pTargetFile->open(IFOcreate); pTargetFileIO->write( 0, tmpoutbuf.length(), tmpoutbuf.str()); m_envDepEngine.addTempFile(destFilePath.str()); }
void CLogSerializer::Open(const char*Directory,const char* NewFileName,const char* Prefix) { m_FilePath.clear(); m_FilePath.append(Directory); if (!EnsureDirectory(m_FilePath)) throw MakeStringException(-1,"Unable to create directory at %s.",m_FilePath.str()); m_FilePath.append("/"); m_FileName.clear(); m_FileName.append(Prefix); m_FileName.append("_"); m_FileName.append(NewFileName); m_FilePath.append(m_FileName); DBGLOG("Creating tank file %s", m_FilePath.str()); m_file = createIFile(m_FilePath.str()); m_fileio = m_file->open(IFOcreate); if (m_fileio == 0) throw MakeStringException(-1, "Unable to open logging file %s",m_FilePath.str()); else DBGLOG("Tank file %s successfully created", m_FilePath.str()); }
//cloned from hthor - a candidate for commoning up. static IKeyIndex *openKeyFile(IDistributedFilePart *keyFile) { unsigned numCopies = keyFile->numCopies(); assertex(numCopies); for (unsigned copy=0; copy < numCopies; copy++) { RemoteFilename rfn; try { OwnedIFile ifile = createIFile(keyFile->getFilename(rfn,copy)); unsigned __int64 thissize = ifile->size(); if (thissize != -1) { StringBuffer remotePath; rfn.getRemotePath(remotePath); unsigned crc = 0; keyFile->getCrc(crc); return createKeyIndex(remotePath.str(), crc, false, false); } } catch (IException *E) { EXCLOG(E, "While opening index file"); E->Release(); } } RemoteFilename rfn; StringBuffer url; keyFile->getFilename(rfn).getRemotePath(url); throw MakeStringException(1001, "Could not open key file at %s%s", url.str(), (numCopies > 1) ? " or any alternate location." : "."); }
void Do(unsigned i) { CriticalBlock block(crit); if (parent->stopped) return; CFileCrcItem &item = parent->list.item(i); RemoteFilename &rfn = item.filename; Owned<IFile> partfile; StringBuffer eps; try { partfile.setown(createIFile(rfn)); // PROGLOG("VERIFY: part %s on %s",partfile->queryFilename(),rfn.queryEndpoint().getUrlStr(eps).str()); if (partfile) { if (parent->stopped) return; CriticalUnblock unblock(crit); item.crc = partfile->getCRC(); } else ok = false; } catch (IException *e) { StringBuffer s; s.appendf("VERIFY: part %s on %s",partfile->queryFilename(),rfn.queryEndpoint().getUrlStr(eps).str()); EXCLOG(e, s.str()); e->Release(); ok = false; } }
void CLogSerializer::Remove() { Close(); Owned<IFile> file = createIFile(m_FilePath.str()); if(file.get() && file->exists() == true) file->remove(); }
MemoryBuffer& CLocalDataLogger::readData(MemoryBuffer& dataCached,const char* cachedName) { DBGLOG("CLocalDataLogger::readData"); StringBuffer fileName; if (strstr(cachedName,"files_") != 0) { const char* filestr = strstr(cachedName,"files_") + 7; fileName.append(filestr); } else fileName.append(cachedName); StringBuffer filepath; //need to keep it consistant with the files_ method of obtaining files..... filepath.appendf("%s/%s",m_logDirectory.str(),fileName.str()); try{ DBGLOG("about to create file reference"); Owned<IFile> file = createIFile(filepath); if (file) { for (int i = 0; i < RETRIES; ++i) { DBGLOG("Trying to open for the %d time",i); try { DBGLOG("Trying to open %s",filepath.str()); Owned<IFileIO> io = file->open(IFOread); if (io) { DBGLOG("Managed to open"); offset_t filesize = io->size(); size32_t memfilesize = (size32_t)filesize; //Check size isn't >= 2^32 assertex(filesize == memfilesize); io->read(0, memfilesize, dataCached.reserveTruncate(memfilesize)); DBGLOG("Managed to read"); return dataCached; } } catch(IOSException *ose) { //The web site could be serving up the page as we try to update it... ose->Release(); Sleep(10); } catch(...) { DBGLOG("Unknown exception thrown while reading local data logger file"); } } } } catch(...) { DBGLOG("Unknown exception thrown while reading local data logger file2"); } return dataCached; }
virtual void init(MemoryBuffer &data, MemoryBuffer &slaveData) override { isLocal = 0 != (TIWlocal & helper->getFlags()); mpTag = container.queryJobChannel().deserializeMPTag(data); mpTag2 = container.queryJobChannel().deserializeMPTag(data); data.read(active); if (active) { data.read(logicalFilename); partDesc.setown(deserializePartFileDescriptor(data)); } data.read(singlePartKey); data.read(refactor); if (singlePartKey) buildTlk = false; else { data.read(buildTlk); if (firstNode()) { if (buildTlk) tlkDesc.setown(deserializePartFileDescriptor(data)); else if (!isLocal) // existing tlk then.. { tlkDesc.setown(deserializePartFileDescriptor(data)); unsigned c; data.read(c); while (c--) { RemoteFilename rf; rf.deserialize(data); if (!existingTlkIFile) { Owned<IFile> iFile = createIFile(rf); if (iFile->exists()) existingTlkIFile.set(iFile); } } if (!existingTlkIFile) throw MakeActivityException(this, TE_FileNotFound, "Top level key part does not exist, for key"); } } } IOutputMetaData * diskSize = helper->queryDiskRecordSize(); assertex(!(diskSize->getMetaFlags() & MDFneedserializedisk)); if (diskSize->isVariableSize()) { if (TIWmaxlength & helper->getFlags()) maxDiskRecordSize = helper->getMaxKeySize(); else maxDiskRecordSize = KEYBUILD_MAXLENGTH; //Current default behaviour, could be improved in the future } else maxDiskRecordSize = diskSize->getFixedSize(); reportOverflow = false; }
void CDiskWriteSlaveActivityBase::removeFiles() { if (!fName.length()) return; Owned<IFile> primary = createIFile(fName); try { primary->remove(); } catch (IException *e) { ActPrintLogEx(&queryContainer(), e, thorlog_null, MCwarning, "Failed to remove file: %s", fName.get()); } catch (CATCHALL) { ActPrintLogEx(&queryContainer(), thorlog_null, MCwarning, "Failed to remove: %s", fName.get()); } }
void removeFiles(IPartDescriptor &partDesc) { StringBuffer partFname; getPartFilename(partDesc, 0, partFname); Owned<IFile> primary = createIFile(partFname.str()); try { primary->remove(); } catch (IException *e) { ActPrintLog(e, "Failed to remove file: %s", partFname.str()); e->Release(); } catch (CATCHALL) { ActPrintLog("Failed to remove: %s", partFname.str()); } }
void CRecieveLogSerializer::LoadDataMap(GuidMap& GUIDmap) { DBGLOG("Loading ACKMap"); try{ m_file = createIFile(m_FilePath.str()); m_fileio = m_file->open(IFOread); if (m_fileio == 0) throw MakeStringException(-1, "Unable to open logging file %s",m_FilePath.str()); else DBGLOG("File %s successfully opened", m_FilePath.str()); long finger,bytesRead,dataLen; finger = bytesRead = dataLen = 0; MemoryBuffer filecontents,dataSize,data; bool bOk = true; unsigned int total = 0; while(bOk) { bytesRead = m_fileio->read(finger,8,dataSize.reserveTruncate(8)); if(bytesRead==0) break; finger+=9; dataLen = atoi(dataSize.toByteArray()); bytesRead = m_fileio->read(finger,dataLen,data.reserveTruncate(dataLen)); if(bytesRead==0) break; bool printTrace = false; if(total % TRACE_INTERVAL == 0) { DBGLOG("Loading ack #%u", total); printTrace = true; } LoadMap(data,GUIDmap,printTrace); total++; finger+=dataLen; data.clear(); dataSize.clear(); } DBGLOG("Total acks loaded %u", total); } catch(IException* ex) { StringBuffer errorStr; ex->errorMessage(errorStr); ERRLOG("Exception caught within CRecieveLogSerializer::LoadDataMap: %s",errorStr.str()); ex->Release(); } catch(...){ DBGLOG("Unknown Exception thrown in CRecieveLogSerializer::LoadDataMap"); } Close(); }
void open() { char drive [_MAX_DRIVE]; char dir [_MAX_DIR]; char fname [_MAX_DIR]; char ext [_MAX_EXT]; _splitpath(fileName.str(), drive, dir, fname, ext); StringBuffer directory; directory.append(drive).append(dir); Owned<IFile> cd = createIFile(directory.str()); cd->createDirectory(); IHThorSpillArg *helper = (IHThorSpillArg *)queryHelper(); void *ekey; size32_t ekeylen; helper->getEncryptKey(ekeylen,ekey); Owned<ICompressor> ecomp; if (ekeylen!=0) { ecomp.setown(createAESCompressor256(ekeylen,ekey)); memset(ekey,0,ekeylen); free(ekey); compress = true; } Owned<IFile> file = createIFile(fileName.str()); Owned<IFileIO> iFileIO; bool fixedRecordSize = queryRowMetaData()->isFixedSize(); size32_t minrecsize = queryRowMetaData()->getMinRecordSize(); if (fixedRecordSize) ActPrintLog("SPILL: created fixed output %s recsize=%u", (0!=ekeylen)?"[encrypted]":compress?"[compressed]":"",minrecsize); else ActPrintLog("SPILL: created variable output %s, minrecsize=%u", (0!=ekeylen)?"[encrypted]":compress?"[compressed]":"",minrecsize); unsigned rwFlags = (DEFAULT_RWFLAGS & ~rw_autoflush); // flushed by close() if (compress) rwFlags |= rw_compress; else rwFlags |= rw_crc; // only if !compress if (grouped) rwFlags |= rw_grouped; out.setown(createRowWriter(file, this, rwFlags)); }
offset_t write(IRowStream *input) { StringBuffer tempname; GetTempName(tempname,"srtmrg",false); dataFile.setown(createIFile(tempname.str())); Owned<IExtRowWriter> output = createRowWriter(dataFile, rowIf); bool overflowed = false; ActPrintLog(&activity, "Local Overflow Merge start"); unsigned ret=0; loop { const void *_row = input->nextRow(); if (!_row) break; ret++; OwnedConstThorRow row = _row; offset_t start = output->getPosition(); output->putRow(row.getLink()); idx++; if (idx==interval) { idx = 0; if (!sampleRows.append(row.getClear())) { // JCSMORE used to check if 'isFull()' here, but only to warn // I think this is bad news, if has run out of room here... // should at least warn in workunit I suspect overflowsize = output->getPosition(); if (!overflowed) { WARNLOG("Sample buffer full"); overflowed = true; } } } writeidxofs(start); } output->flush(); offset_t end = output->getPosition(); output.clear(); writeidxofs(end); if (idxFileIO) { idxFileStream->flush(); idxFileStream.clear(); idxFileIO.clear(); } if (overflowed) WARNLOG("Overflowed by %"I64F"d", overflowsize); ActPrintLog(&activity, "Local Overflow Merge done: overflow file '%s', size = %"I64F"d", dataFile->queryFilename(), dataFile->size()); return end; }
void CLogSerializer::Rollover(const char* ClosedPrefix) { Close(); Owned<IFile> file = createIFile(m_FilePath.str()); if(file.get() && file->exists() == true) { StringBuffer newFileName; GetRolloverFileName(m_FileName,newFileName,ClosedPrefix); file->rename(newFileName.str()); } }
void CLogSerializer::loadSendLogs(GuidSet& ackSet, GuidMap& missedLogs, unsigned long& total_missed)// { try { Close(); //release old file io, if any m_file = createIFile(m_FilePath.str()); m_fileio = m_file->open(IFOread); if (m_fileio == 0) throw MakeStringException(-1, "Unable to open logging file %s",m_FilePath.str()); offset_t finger = 0; total_missed = 0; while(true) { char dataSize[9]; memset(dataSize, 0, 9); size32_t bytesRead = m_fileio->read(finger,8,dataSize); if(bytesRead==0) break; MemoryBuffer data; int dataLen = atoi(dataSize); finger+=9; bytesRead = m_fileio->read(finger,dataLen,data.reserveTruncate(dataLen)); if(bytesRead==0) break; StringBuffer GUID,lostlogStr; splitLogRecord(data,GUID,lostlogStr); if (ackSet.find(GUID.str())==ackSet.end() && missedLogs.find(GUID.str()) == missedLogs.end()) { if(total_missed % TRACE_INTERVAL == 0) DBGLOG("Miss #%lu GUID: <%s>", total_missed, GUID.str()); missedLogs[GUID.str()] = lostlogStr.str(); total_missed++; } finger+=dataLen; } } catch(IException* ex) { StringBuffer errorStr; ex->errorMessage(errorStr); ERRLOG("Exception caught within CSendLogSerializer::LoadDataMap: %s",errorStr.str()); ex->Release(); } catch(...) { DBGLOG("Unknown Exception thrown in CSendLogSerializer::LoadDataMap"); } Close(); }
static bool getFileInfo(RemoteFilename &fn, Owned<IFile> &f, offset_t &size,CDateTime &modtime) { f.setown(createIFile(fn)); bool isdir = false; bool ret = f->getInfo(isdir,size,modtime); if (ret&&isdir) { StringBuffer fs; fn.getRemotePath(fs); throw MakeStringException(-1,"%s is a directory",fs.str()); } return ret; }
void CppCompiler::writeLogFile(const char* filepath, StringBuffer& log) { if(!filepath || !*filepath || !log.length()) return; Owned <IFile> f = createIFile(filepath); if(f->exists()) f->remove(); Owned <IFileIO> fio = f->open(IFOcreaterw); if(fio.get()) fio->write(0, log.length(), log.str()); }
//--------------------------------------------------------------------------- // beforeDeploy //--------------------------------------------------------------------------- void CConfigGenEngine::beforeDeploy() { m_installFiles.clear(); char tempPath[_MAX_PATH]; getTempPath(tempPath, sizeof(tempPath), m_name); m_envDepEngine.addTempDirectory( tempPath ); if (m_instances.ordinality() > 1) { strcat(tempPath, "Cache"); char* pszEnd = tempPath + strlen(tempPath); Owned<IFile> pFile = createIFile(tempPath); int i = 1; while (pFile->exists()) { //dir/file exists itoa(++i, pszEnd, 10); pFile.setown( createIFile(tempPath) ); } strcat(tempPath, PATHSEPSTR); m_cachePath.set( tempPath ); } else m_cachePath.set( tempPath ); ensurePath(tempPath); determineInstallFiles(m_process, m_installFiles); getCallback().installFileListChanged(); if (m_instances.ordinality() > 1) { EnvMachineOS os = m_envDepEngine.lookupMachineOS( m_instances.item(0) ); m_curInstance = "Cache"; copyInstallFiles("Cache", -1, tempPath, os); } }
void SafePluginMap::loadFromDirectory(const char * pluginDirectory) { const char * mask = "*" SharedObjectExtension; Owned<IFile> pluginDir = createIFile(pluginDirectory); Owned<IDirectoryIterator> pluginFiles = pluginDir->directoryFiles(mask,false,false); ForEach(*pluginFiles) { const char *thisPlugin = pluginFiles->query().queryFilename(); StringBuffer tail; splitFilename(thisPlugin, NULL, NULL, &tail, &tail); addPlugin(thisPlugin, tail.str()); } }
bool CLogSerializer::EnsureDirectory(StringBuffer& Dir) { try{ Owned<IFile> pDirectory = createIFile(Dir.str()); if(pDirectory->exists() == true) return true; return pDirectory->createDirectory(); } catch(IException *ex) { ex->Release(); } return false; }
void CLogSerializer::loadAckedLogs(GuidSet& ackedLogs)// { try { Close(); //release old file io, if any m_file = createIFile(m_FilePath.str()); m_fileio = m_file->open(IFOread); if (m_fileio == 0) throw MakeStringException(-1, "Unable to open logging file %s",m_FilePath.str()); offset_t finger = 0; m_ItemCount = 0; while(true) { char dataSize[9]; memset(dataSize, 0, 9); size32_t bytesRead = m_fileio->read(finger,8,dataSize); if(bytesRead==0) break; MemoryBuffer data; int dataLen = atoi(dataSize); finger+=9; bytesRead = m_fileio->read(finger,dataLen,data.reserveTruncate(dataLen)); if(bytesRead==0) break; StringBuffer GUID, line; splitLogRecord(data, GUID, line); ackedLogs.insert(GUID.str()); m_ItemCount++; finger+=dataLen; } fileSize = finger; DBGLOG("Total acks loaded %lu", m_ItemCount); } catch(IException* ex) { StringBuffer errorStr; ex->errorMessage(errorStr); ERRLOG("Exception caught within CLogSerializer::loadAckedLogs: %s",errorStr.str()); ex->Release(); } catch(...) { DBGLOG("Unknown Exception thrown in CLogSerializer::loadAckedLogs"); } Close(); }
offset_t getPartSize(IDistributedFilePart & part, unsigned copy) { try { RemoteFilename rfn; Owned<IFile> in = createIFile(part.getFilename(rfn,copy)); return in->size(); } catch (IException * e) { e->Release(); } return (offset_t) -1; }
void renameDfuTempToFinal(const RemoteFilename & realname) { RemoteFilename tempFilename; StringBuffer newTailname; getDfuTempName(tempFilename, realname); realname.getTail(newTailname); OwnedIFile output = createIFile(tempFilename); try { output->rename(newTailname); } catch (IException * e) { EXCLOG(e, "Failed to rename target file"); StringBuffer oldName; realname.getPath(oldName); LOG(MCdebugInfoDetail, unknownJob, "Error: Rename %s->%s failed - tring to delete target and rename again", oldName.str(), newTailname.str()); e->Release(); OwnedIFile old = createIFile(realname); old->remove(); output->rename(newTailname); } }
void EclObjectParameter::loadStdIn() { Owned<IFile> file = createIFile("stdin:"); Owned<IFileIO> io = file->openShared(IFOread, IFSHread); if (!io) throw MakeStringException(1, "stdin could not be opened"); size32_t rd; size32_t sizeRead = 0; do { rd = io->read(sizeRead, STDIO_BUFFSIZE, mb.reserve(STDIO_BUFFSIZE+1)); // +1 as will need sizeRead += rd; mb.setLength(sizeRead); } while (rd); finalizeContentType(); }
inline bool fileRead(const char *filename, MemoryBuffer &buff) { Owned<IFile> fi=createIFile(filename); if (fi) { Owned<IFileIO> fio=fi->open(IFOread); if (fio) { offset_t len=fio->size(); if (fio->read(0, len, buff.reserveTruncate(len))==len) return true; } } buff.clear(); return false; }