FILE *DIGLoader( Open )( const char *name, size_t name_len, const char *ext, char *result, size_t max_result ) /************************************************************************************************************/ { char realname[ _MAX_PATH2 ]; char *filename; FILE *fp; /* unused parameters */ (void)max_result; memcpy( realname, name, name_len ); realname[name_len] = '\0'; if( ext != NULL && *ext != NULLCHAR ) { _splitpath2( realname, result, NULL, NULL, &filename, NULL ); _makepath( realname, NULL, NULL, filename, ext ); } filename = findFile( result, realname, FilePathList ); if( filename == NULL ) { filename = findFile( result, realname, DipExePathList ); } fp = NULL; if( filename != NULL ) fp = fopen( filename, "rb" ); return( fp ); }
Common::SeekableReadStream *TlkArchive::createReadStreamForMember(const Common::String &name) const { const uint32 *fileDesc = findFile(name); if (!fileDesc) return 0; Common::SeekableReadStream *parent = _file->createReadStream(); if (!parent) return 0; parent->seek(fileDesc[1], SEEK_SET); const uint32 size = parent->readUint32LE(); const uint32 fileStart = fileDesc[1] + 4; return new Common::SeekableSubReadStream(parent, fileStart, fileStart + size, DisposeAfterUse::YES); }
/* chmod ���� */ void File::splitFile(char* sourceFile, char* first_target, char* second_target) // sourceFile�� file�̸� first_target�� xFilenamea, second_target�� xFilenameb { // source������ ������ �о�´� int fd = findFile(sourceFile); TableManager* t = TableManager::getInstance(); TableManager& tm = *t; InodeElement* sourceInodeE = (InodeElement*)tm.getElement(INODET, fd); int halfSize = atoi(sourceInodeE->inode.size) / 2; // first_target���Ͽ� �ݸ�ŭ ���� int firstTargetFd = findFile(first_target); char* firstFileData; readFile(fd, firstFileData, halfSize); writeFile(firstTargetFd, firstFileData, halfSize); // second_target�� ������ �� ���� int secondTargetFd = findFile(second_target); char* secondFileData; readFile(fd, secondFileData, halfSize); writeFile(secondTargetFd, secondFileData, halfSize); }
static int _dfs_open(const char *path, struct fuse_file_info *fi) { DfsFile *f; dfs_out("\n\tFUSE OPEN '%s'\n\n", path); if (!(f = findFile((char *)path))) { return -ENOENT; } long flags = fi ? fi->flags : 0; dfs_out("\tOPEN : '%s', flags %o, len %d, reclen %d, recipe %x, data %x\n", path, flags, f->len, f->recipelen, f->recipe, f->data); if (f->stat.st_mode & S_IFDIR) { return -EISDIR; } if (0 && !(fi->flags & f->stat.st_mode)) { dfs_out("OPEN permissions problem: %o, %o\n", fi->flags, f->stat.st_mode); return -EACCES; } // Why? don't remember.... fi->fh = (uint64_t)f->stat.st_mode; if (f->len && !f->data) { assert(f->recipe); f->data = malloc(f->len); assert(f->data); char *data = f->data, *dataEnd = f->data + f->len; char *sig = f->recipe, *sigEnd = f->recipe + f->recipelen; while ((data < dataEnd) && (sig < sigEnd)) { Extent *ex = get_extent(sig); if (!ex) dfs_die("No get signature '%s'\n", sig); memcpy(data, ex->data, ex->sz); data += ex->sz; sig += strlen(sig) + 1; free(ex); } assert((data == dataEnd) && (sig == sigEnd)); } return 0; }
STATIC enum cacheRet maybeCache( const char *fullpath, CENTRYPTR *pc ) /********************************************************************/ { char path[_MAX_PATH]; char name[NAME_MAX + 1]; DHEADPTR dcur; CENTRYPTR centry; enum cacheRet ret; PGROUP pg; char const *ext; assert( fullpath != NULL ); _splitpath2( fullpath, pg.buffer, &pg.drive, &pg.dir, &pg.fname, &pg.ext ); _makepath( path, pg.drive, pg.dir, NULL, NULL ); ext = pg.ext; if( ext[0] == '.' && ext[1] == 0 ) { ext = NULL; } _makepath( name, NULL, NULL, pg.fname, ext ); FixName( path ); FixName( name ); dcur = findDir( path ); if( dcur == NULL ) { /* must cache new directory */ ret = cacheDir( &dcur, path ); if( ret != CACHE_OK ) { return( ret ); } dcur->dh_next = cacheHead; cacheHead = dcur; } /* now dcur points to Cached directory */ assert( dcur != NULL ); centry = findFile( dcur, name ); if( centry == NULL ) { return( CACHE_FILE_NOT_FOUND ); } if( pc != NULL ) { *pc = centry; } return( CACHE_OK ); }
//! (static) ObjRef StdLib::loadOnce(Runtime & runtime,const std::string & filename){ static const StringId mapId("__loadOnce_loadedFiles"); std::string condensedFilename( IO::condensePath(findFile(runtime,filename)) ); Map * m=dynamic_cast<Map*>(runtime.getAttribute(mapId).getValue()); if(m==nullptr){ m=Map::create(); runtime.setAttribute(mapId, Attribute(m)); } ObjRef obj=m->getValue(condensedFilename); if(obj.toBool()){ // already loaded? return nullptr; } m->setValue(String::create(condensedFilename),Bool::create(true)); return _loadAndExecute(runtime,condensedFilename); }
std::string LLDir::findSkinnedFilename(const std::string &subdir1, const std::string &subdir2, const std::string &filename) const { // generate subdirectory path fragment, e.g. "/foo/bar", "/foo", "" std::string subdirs = ((subdir1.empty() ? "" : mDirDelimiter) + subdir1) + ((subdir2.empty() ? "" : mDirDelimiter) + subdir2); std::vector<std::string> search_paths; search_paths.push_back(getUserSkinDir() + subdirs); // first look in user skin override search_paths.push_back(getSkinDir() + subdirs); // then in current skin search_paths.push_back(getDefaultSkinDir() + subdirs); // then default skin search_paths.push_back(getCacheDir() + subdirs); // and last in preload directory std::string found_file = findFile(filename, search_paths); return found_file; }
void Favorites::previous() { qDebug("Favorites::previous"); int current = findFile(current_file); //if (current < 0) current = 0; current--; if (current < 0) current = f_list.count()-1; QAction * a = _menu->actions()[current+FIRST_MENU_ENTRY]; // Skip "edit" and separator if (a != 0) { a->trigger(); } }
//------------------------------------------------------------------------------ std::string findFileInDirs(const std::string& file, const std::vector<std::string>& strDirs, bool subdirs) { if (fileExists(file)) return file; for (auto it = strDirs.begin(); it != strDirs.end(); ++it) { // Skip non-existant directories. if (!fileExists(*it)) continue; std::string searchFile = *it + "/" + file; if (findFile(searchFile, subdirs) != "") return searchFile; } return ""; }
MainFrame::MainFrame(const wxString& title, const wxPoint& pos, const wxSize& size, long style) : wxFrame(NULL, -1, title, pos, size, style) { // Presentation général wxString ImgFileName; #if defined(__WXMSW__) SetIcon(wxIcon(_T("win32icon"))); #elif defined(__UNIX__) ImgFileName = findFile(_T("data/icon.png")); if(wxFileExists(ImgFileName)) { SetIcon(wxIcon(ImgFileName, wxBITMAP_TYPE_PNG)); } #endif //#ifdef WIN32 // File menu wxMenu *FileMenu = new wxMenu; m_menuItemShowAll = new wxMenuItem(FileMenu, wxID_ANY, wxString(_("Show all drive")) + _T("\tCtrl+A"), _("Show all drives, even those not detected as USB stick."), wxITEM_CHECK); FileMenu->Append(m_menuItemShowAll); FileMenu->AppendSeparator(); FileMenu->Append(wxID_EXIT); // Help Menu wxMenu *HelpMenu = new wxMenu; HelpMenu->Append(wxID_ABOUT); // Menubar m_MenuBar = new wxMenuBar(); m_MenuBar->Append(FileMenu,_("&File")); m_MenuBar->Append(HelpMenu,_("&Help")); SetMenuBar(m_MenuBar); // Body wxBoxSizer* MainSizer = new wxBoxSizer( wxVERTICAL ); m_MainPanel = new MainPanel(this ,wxID_ANY); MainSizer->Add(m_MainPanel, 1, wxEXPAND | wxALL, 4); SetSizer( MainSizer ); // Events Connect( m_menuItemShowAll->GetId(), wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainPanel::OnShowAllDrive), NULL, m_MainPanel); Connect( wxID_EXIT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnQuit)); Connect( wxID_ABOUT, wxEVT_COMMAND_MENU_SELECTED, wxCommandEventHandler(MainFrame::OnAbout)); }
TFileName CT_StartAppTestStep::SearchAndReturnCompleteFileName(const TDesC& aFileName) { RFs fs; TInt ret = fs.Connect(); TEST(ret==KErrNone); TParsePtrC parse(aFileName); TFindFile findFile(fs); ret = findFile.FindByDir(parse.NameAndExt(), parse.Path()); if (ret!=KErrNone) { TBuf<64> buffer; buffer.Format(_L("Error while finding the file, %d"), ret); } fs.Close(); return findFile.File(); }
///////////////////////////////////////////////////////// // read a treeidmap from file // ///////////////////////////////////////////////////////// void pix_fiducialtrack :: treeMess(t_symbol*s) { if(NULL==s || NULL==s->s_name || &s_==s)return; std::string fn = findFile(s->s_name); snprintf(m_treefile, MAXPDSTRING, "%s", fn.c_str()); terminate_fidtrackerX(&fidtrackerx); terminate_treeidmap (&treeidmap); deinit_segmenter(); initialize_treeidmap_from_file( &treeidmap, m_treefile ); initialize_fidtrackerX( &fidtrackerx, &treeidmap, NULL); if(treeidmap.max_adjacencies<=0){ error("could not load TreeIdMap from '%s'", s->s_name); } }
void *DL_PREFIX(dlopen)(const char *path, int mode) { const struct stat *sbuf; struct dlstatus *dls; const char *fullPath; dolock(); resetdlerror(); if (!path) { dls = &mainStatus; goto dlopenok; } if (!(sbuf = findFile(path, &fullPath))) { error("file \"%s\" not found", path); goto dlopenerror; } /* Now checks that it hasn't been closed already */ if ((dls = lookupStatus(sbuf)) && (dls->refs > 0)) { /* debug("status found"); */ dls = reference(dls, mode); goto dlopenok; } #ifdef RTLD_NOLOAD if (isFlagSet(mode, RTLD_NOLOAD)) { error("no existing handle and RTLD_NOLOAD specified"); goto dlopenerror; } #endif if (isFlagSet(mode, RTLD_LAZY) && isFlagSet(mode, RTLD_NOW)) { error("how can I load something both RTLD_LAZY and RTLD_NOW?"); goto dlopenerror; } dls = loadModule(fullPath, sbuf, mode); dlopenok: dounlock(); return (void *)dls; dlopenerror: dounlock(); return NULL; }
void LFS::remove(std::string& lfsFileName) { unsigned iNodeAddress = findFile(lfsFileName); unsigned iMapIndex = getImapIndexFromINodeAddress(iNodeAddress); unsigned iMapAddress = iMapAddresses[iMapIndex]; unsigned segmentIndex = getSegmentIndexFromAddress(iMapAddress); unsigned blockIndex = getBlockIndexFromAddress(iMapAddress); IMap iMap(segments[segmentIndex]->blocks[blockIndex]); iMap.removeINodeAtIndex(getBlockIndexFromAddress(iNodeAddress)); unsigned iMapOffset = segments[currentSegmentIdx]->addBlock(iMap, iMapIndex); if (iMapOffset == 0) { selectNewCleanSegment(); iMapOffset = segments[currentSegmentIdx]->addBlock(iMap, iMapIndex); } iMapAddress = (currentSegmentIdx << 10) + iMapOffset; iMapAddresses[currentIMapIdx] = iMapAddress; files.erase(lfsFileName); }
void glsl_vertex :: loadShader() { if(NULL==m_shaderFilename || NULL==m_shaderFilename->s_name)return; if(!isRunnable()) { return; } // Clean up any open files closeMess(); std::string fn = findFile(m_shaderFilename->s_name); const char*buf=fn.c_str(); FILE *file = fopen(buf,"rb"); if(file) { fseek(file,0,SEEK_END); long size = ftell(file); if(size<0){fclose(file);error("error reading filesize");return;} m_shaderString = new char[size + 1]; memset(m_shaderString,0,size + 1); fseek(file,0,SEEK_SET); size_t count=fread(m_shaderString,1,size,file); m_shaderString[size]='\0'; int err=ferror(file); fclose(file); if(err){error("error %d reading file (%d<%d)", err, count, size); return;} } else { error("could not find shader-file: '%s'", buf); return; /* // assuming that the "filename" is actually a shader-program per se m_shaderString = new char[strlen(buf) + 1]; strcpy(m_shaderString,buf); */ } m_size=strlen(m_shaderString); if(GLEW_VERSION_2_0) openMessGL2(); else if (GLEW_ARB_vertex_shader) openMessARB(); verbose(1, "Loaded file: %s", buf); m_shaderFilename=NULL; }
void PrintDiskUsage(RFs& aFs, const TDesC& aPath, TInt aOffset = 0) { _LIT(KSpace, " "); TheTest.Printf(_L("%*.*S%S\r\n"), aOffset, aOffset, &KSpace, &aPath); TFindFile findFile(aFs); CDir* fileNameCol = NULL; TBuf<8> fileNameMask; fileNameMask.Copy(_L("*.*")); TInt err = findFile.FindWildByDir(fileNameMask, aPath, fileNameCol); if(err == KErrNone) { do { const TDesC& file = findFile.File();//"file" variable contains the drive and the path. the file name in "file" is invalid in this case. (void)TheParse.Set(file, NULL, NULL); TPtrC driveName = TheParse.Drive(); if(aPath.FindF(driveName) >= 0) { TInt cnt = fileNameCol->Count(); for(TInt i=0;i<cnt;++i) { const ::TEntry& entry = (*fileNameCol)[i]; if(!entry.IsDir()) { TheTest.Printf(_L("%*.*S %S, size=%d\r\n"), aOffset, aOffset, &KSpace, &entry.iName, entry.iSize); } else { TBuf<100> path; path.Copy(aPath); path.Append(entry.iName); path.Append(_L("\\")); PrintDiskUsage(aFs, path, aOffset + 4); } } } // if(aPath.FindF(driveName) >= 0) delete fileNameCol; fileNameCol = NULL; } while((err = findFile.FindWild(fileNameCol)) == KErrNone);//Get the next set of files } else { TheTest.Printf(_L(" FindWildByDir() failed with err=%d\r\n"), err); } }
Blob * Config::readBlob(const std::string &name) { std::string filename = findFile(name); std::ifstream is(filename.c_str(), std::ios::in); is.seekg(0, is.end); size_t length = is.tellg(); is.seekg(0, is.beg); char *buffer = new char [length]; is.read (buffer, length); is.close(); return new Blob(buffer, length); }
QString Cleaner::findFile(QDir dir, QString filename) { QStringList dirs; if (QFile::exists(dir.canonicalPath() + "/" + filename)) return QString(dir.canonicalPath() + "/" + filename); else { // file not in this dir, search recursively dirs = dir.entryList(QDir::AllDirs | QDir::NoDotAndDotDot); for (int i=0; i<dirs.size(); i++) { QString tmp; tmp = findFile(QDir(dir.canonicalPath() + "/" + dirs[i]), filename); if (!(tmp.isNull() || tmp.isEmpty())) { return QString(tmp); } } return(QString()); } }
int _dfs_rmdir(const char *path) { /* Assumes treeMut is locked */ DfsFile *f; if (!(f = findFile((char *)path))) return -ENOENT; if (!(f->stat.st_mode & S_IFDIR)) return -ENOTDIR; if (f->num_children) return -ENOTEMPTY; freeNode(path, f); return 0; }
pair<string, int64_t> ShareManager::toRealWithSize(const string& virtualFile, bool isInSharingHub) { Lock l(cs); if(virtualFile == "MyList.DcLst") { throw ShareException("NMDC-style lists no longer supported, please upgrade your client"); } if(virtualFile == Transfer::USER_LIST_NAME_BZ || virtualFile == Transfer::USER_LIST_NAME) { generateXmlList(); if (!isInSharingHub) { string emptyList = Util::getPath(Util::PATH_USER_CONFIG) + "Emptyfiles.xml.bz2"; return make_pair(emptyList, 0); } return make_pair(getBZXmlFile(), 0); } auto f = findFile(virtualFile); return make_pair(f.getRealPath(this), f.getSize()); }
int InsertInNode(struct superblock* sb, const char* dirName, const uint64_t fileBlock) { int exists; struct inode*dirNode = NULL; struct nodeinfo* meta = NULL; dirNode = malloc(sb->blksz); meta = malloc(sb->blksz); uint64_t dirBlock = findFile(sb, dirName, &exists); seek_read(sb, dirBlock, dirNode); seek_read(sb, dirNode->meta, meta); int len = 0; char** fileparts = getFileParts(dirName, &len); if (strcmp(meta->name, fileparts[len - 1]) != 0)return 0; //dir does not exists if ((++meta->size) % getLinksMaxLen(sb) == 0) { //needs to create another link block struct inode* linknode = NULL; linknode = malloc(sb->blksz); linknode->links[0] = fileBlock; linknode->links[1] = 0; uint64_t lastLinkBlock = getNodeLastLinkBlock(sb, dirBlock); struct inode* lastLinkNode = NULL; lastLinkNode = malloc(sb->blksz); seek_read(sb, lastLinkBlock, lastLinkNode); if (lastLinkNode->next != 0) { exit(EXIT_FAILURE); } lastLinkNode->next = fs_get_block(sb); seek_write(sb, lastLinkNode->next, linknode); seek_write(sb, lastLinkBlock, lastLinkNode); free(linknode); free(lastLinkNode); } else { int linkLen = getLinksLen(dirNode); dirNode->links[linkLen] = fileBlock; dirNode->links[linkLen + 1] = 0; } seek_write(sb, dirBlock, dirNode); seek_write(sb, dirNode->meta, meta); freeFileParts(&fileparts, len); free(dirNode); free(meta); return FALSE; }
static int dfs_write(const char *path, const char *buf, size_t size, off_t offset, struct fuse_file_info *fi) { size_t len; pthread_mutex_lock(&treeMut); path = narrow_path(path); dfs_out("WRITE: '%s', sz %d, offset %d\n", path, size, offset); if (remove_write) { pthread_mutex_unlock(&treeMut); return -EACCES; } DfsFile *f = findFile((char *)path); if (!f) { pthread_mutex_unlock(&treeMut); return -ENOENT; } if (f->stat.st_mode & S_IFDIR) { pthread_mutex_unlock(&treeMut); return -EISDIR; } // Handles issue where a collision can cause us to fail this check if(!(!f->recipelen || f->data)) { struct fuse_file_info fii; fii.flags = 0; _dfs_open(path, &fii); } //assert(!f->recipelen || f->data); if ((size + offset) > f->len) { f->data = (char *)realloc(f->data, size + offset); f->stat.st_size = f->len = size + offset; } memcpy(f->data + offset, buf, size); f->dirty = 1; f->stat.st_mtime = f->stat.st_atime = time(NULL); pthread_mutex_unlock(&treeMut); return size; }
int FSManager::copyOut(string fileName, string newFile) { cout << "Rozpoczynam kopiowanie pliku " << fileName << " z dysku wirtualnego...\n"; fstream file; char * blockData; Block block; unsigned int currentBlock = findFile(fileName); if (currentBlock == 0) { cout << "Blad: metoda copyOut(" << fileName << ", " << newFile << ") -> funkcja findFile zwrocila niepoprawny blok.\n"; return -1; } diskFile.seekg(sizeof (DiskInfo) + currentBlock * blkSize); file.open(newFile.c_str(), fstream::out | fstream::binary); if (file.fail() || file.eof()) { cout << "Blad: metoda copyOut(" << fileName << ", " << newFile << ") -> wystapil blad podczas otwarcia pliku do zapisu.\n"; return -1; } blockData = new char[blkSize]; if (!blockData) { cout << "Blad: metoda copyOut(" << fileName << ", " << newFile << ") -> nie udalo sie zainicjowac wskaznika blockData\n"; return -1; } while (1) { diskFile.seekg(blkSize * currentBlock + sizeof (DiskInfo)); diskFile.read((char *) & block, sizeof (block)); diskFile.read(blockData, block.size); file.write(blockData, block.size); if (block.next == 0) break; else currentBlock = block.next; } file.close(); delete[] blockData; cout << "Plik pomyślnie skopiowany z dysku wirtualnego.\n\n"; return 0; }
std::vector<ufile> findFile(const std::string& folder, const std::string& tofind, int searchLevels, int currentRecursiveLevel){ std::vector<ufile> curlist = dir(folder); std::vector<ufile> ret; for(unsigned int a = 0; a < curlist.size(); a++){ std::string tttttmp = curlist[a].name; if (curlist[a].type==filetype::folder){ if (currentRecursiveLevel<searchLevels){ std::vector<ufile> recursed = findFile(curlist[a].name,tofind,searchLevels,currentRecursiveLevel+1); ret.insert(ret.end(),recursed.begin(),recursed.end()); } } else{ if (contains(strtolower(tofind),strtolower(curlist[a].name))>0){ ret.push_back(curlist[a]); } } } return ret; }
FilePtr DataFileFinder::openFile(const DataFileOptions &options) const { // TODO: There is a small race here, since there is some time between // the exists() calls and actually opening the file. It would be better // to leave the file open after a successful exists() if the desire is to // actually open the file. std::string filename = findFile(options); if (filename.empty()) { return nullptr; } #if 0 if (debug) { fprintf(debug, "Opening library file %s\n", fn); } #endif return TextInputFile::openRawHandle(filename); }
QString pIconManager::filePath( const QString& fileName, const QString& prefix ) { QString path = prefix; if ( path.isEmpty() ) path = QLatin1String( ":/" ); const FileNamePair pair = qMakePair( fileName, path ); QString fn = mFileNameCache.value( pair ); if ( !fn.isEmpty() ) { return fn; } QDir dir( path ); fn = findFile( dir, fileName ); mFileNameCache[ pair ] = fn; return fn; }
// --------------------------------------------------------------------------------- // 설명 : 순차모드로 파일을 open 한다. // 동작조건: 파일 경로가 입력되어 있어야 한다. (NEFileSystem의 setPath) // 메모 : // 히스토리: 2011-07-07 이태훈 개발 완료 // --------------------------------------------------------------------------------- void NE_DLL NESequencialFileLoader::open() { // pre: if(_sequencial_file_in_stream.is_open()) return; const NEFileSystem::TaskUnit* task = &getLastElement(); if( ! &task) return; if( ! task->isPathInputted()) return; if(! task->isTaskExecutedAtLeastOnce()) findFile(); // 여기에 도달했다는 건 최소한 1번은 findFile을 했다는 얘기 // 왜 TaskUnit을 두번 가져오는 가: // findFile() 을 하면서 처음 task가 pop(= delete) 될수도 있다. const NEFileSystem::TaskUnit& task_after_finding = getLastElement(); if( ! &task_after_finding) return; if(! task->isFileInformationFilledIn()) return; if(! task->isThereAnyTask()) return; // main: _sequencial_file_in_stream.open(task->getFilePath(), std::ios_base::in); }
ssize_t fs_read_file(struct superblock *sb, const char *fname, char *buf, size_t bufsz) { if (existsFile(sb, fname) == FALSE) { errno = ENOENT; return -1; } int len = 0, exists = 0; char** fileParts = getFileParts(fname, &len); uint64_t fileBlock = findFile(sb, fname, &exists); struct inode* node; initNode(&node, sb->blksz); struct nodeinfo* meta = (struct nodeinfo*) calloc(1, sb->blksz); seek_read(sb, fileBlock, node); seek_read(sb, node->meta, meta); assert(strcmp(meta->name, fileParts[len - 1]) == 0); size_t size = MIN(meta->size, bufsz); size = MAX(sb->blksz, size); size_t read_blocks = 0; char* buf_p = (char*) calloc(1, size); char* p = buf_p; do { int i = 0; while (node->links[i] != 0) { seek_read(sb, node->links[i++], p); p = p + sb->blksz; read_blocks++; } if (node->next == 0)break; seek_read(sb, node->next, node); } while (node->next != 0); strcpy(buf, buf_p); freeFileParts(&fileParts, len); free(meta); free(node); free(buf_p); return size; }
Str findFile(const char *name, const char *path) { #ifdef __BCPLUSPLUS__ Str p = path; Str res; if (p[p.size() - 1] != '\\' && p[p.size() - 1] != '/') { p = p + "/"; } _finddata_t ff; Str direct = p + name; if (_findfirst(direct, &ff) >= 0) { return direct; } Array <Str> dirs; long srch; if ((srch = _findfirst(p + "*.*", &ff)) >= 0) { do { Str findName(ff.name); if (ff.attrib & _A_SUBDIR && findName != "." && findName != "..") { dirs.append(new Str(p + findName + "/")); } } while (_findnext(srch, &ff) >= 0); _findclose(srch); } for (int i=0; i<dirs.count(); i++) { res = findFile(name, dirs[i]); if (res != "") return res; } return ""; #else return Str(path) + name; #endif }
std::string Config::readFile(const std::string &name) { std::string filename = findFile(name); std::ifstream is(filename.c_str(), std::ios::in); is.seekg(0, is.end); size_t length = is.tellg(); is.seekg(0, is.beg); char *buffer = new char [length+1]; buffer[length] = '\0'; is.read (buffer,length); is.close(); std::string result = buffer; delete[] buffer; return result; }