stringT pws_os::getcwd() { char curdir[PATH_MAX]; if (::getcwd(curdir, PATH_MAX) == NULL) { curdir[0] = '?'; curdir[1] = '\0'; } #ifdef UNICODE stringT CurDir(pws_os::towc(curdir)); #else stringT CurDir(curdir); #endif return CurDir; }
stringT pws_os::getcwd() { charT *curdir = _tgetcwd(NULL, 512); // NULL means 512 doesn't matter stringT CurDir(curdir); free(curdir); return CurDir; }
stringT pws_os::getcwd() { char curdir[PATH_MAX]; if (::getcwd(curdir, PATH_MAX) == NULL) { curdir[0] = '?'; curdir[1] = '\0'; } stringT CurDir(pws_os::towc(curdir)); return CurDir; }
//--------------------------------------------------------------------------- void __fastcall TCDirectoryOutline::CreateWnd() { AnsiString CurrentPath; TCustomOutline::CreateWnd(); if (FDrive == 0) { AnsiString CurrentPath = ForceCase(CurDir()); if (CurrentPath.Length() != 0) { FDrive = CurrentPath[1]; FDirectory = CurrentPath; } } }
//--------------------------------------------------------------------------- void __fastcall TCDirectoryOutline::SetDrive(char NewDrive) { // the original sample did not throw an exception here. // should we do so now? NewDrive = static_cast<char>(toupper(NewDrive)); if ((NewDrive >= 'A' && NewDrive <= 'Z')) { if (!SameLetter(NewDrive, FDrive)) { FDrive = NewDrive; setdisk(DriveToInt(FDrive)); FDirectory = ForceCase(CurDir()); if (!ComponentState.Contains(csLoading)) BuildTree(); } } }
//--------------------------------------------------------------------------- void __fastcall TCDirectoryOutline::SetTextCase(TTextCase NewCase) { if (NewCase != FTextCase) { FTextCase = NewCase; AssignCaseProc(); if (NewCase == tcAsIs) { AnsiString CurrentPath = CurDir(); FDrive = CurrentPath[1]; FDirectory = CurrentPath; } if (!ComponentState.Contains(csLoading)) BuildTree(); } }
void Path::canonicalize( Path& out, int type ) const { // "./Foo/./Bar/../Xyz" // "foo/bar/../.." // "/home/foo/bar" // On a relative path the working directory is appened at the front. // "." elements will be removed. // On ".." elements the previous element will be removed. // Path separators will be changed to fit the system. std::vector<std::string> entries; entries.reserve(10); // TODO: Maybe declare this as a constant. <.< if((type == Path::Absolute) && !isAbsolutePath()) out = CurDir(); out /= *this; size_t pos = 0; size_t length = 0; std::string entry; while(NextPathElement(entry, pos, length, out.m_Path)) { if(entry == ".") { continue; } else if(entry == "..") { if(!entries.empty()) { entries.pop_back(); // easy peasy ;) continue; } else if(type != Path::Relative) { // Expect(false, "Can't process path entry '..'! (path: '%s')", out.m_Path.c_str()); } } entries.push_back( entry ); } switch(type) { case Path::Absolute: // ... break; case Path::Relative: { if(entries.empty()) out.m_Path = "."; else out.m_Path = ""; } break; default: FatalError("Invalid path type: %u", type); } for(int i = 0; i < entries.size(); i++) { out.m_Path += entries[i]; if(i < entries.size()-1) // not last element? out.m_Path.push_back(DirSeperator); // Could fail if you process something like this: '/..', see security test below. } // if(type != Path::Relative) // Expect(out.isAbsolutePath(), "Processing path '%s' did not yield a valid result. (result: '%s')", m_Path.c_str(), out.m_Path.c_str()); }