char* GetCurrentDirC(void) { static char dir[1024]; memcpy(dir, GetCurrentDir().c_str(), GetCurrentDir().length() + 1); return dir; }
SelectFileScreen::SelectFileScreen() { char cCurrentPath[FILENAME_MAX]; GetCurrentDir(cCurrentPath, sizeof(cCurrentPath)); m_DirString = Stringc(cCurrentPath); char forwardSlash = '\\'; m_DirString.change_from_to(forwardSlash, '/'); int dirSize = m_DirString.get_length(); if ( m_DirString[dirSize-1] != '/' ) m_DirString.concatenate("/"); m_FilterString = Stringc("*.*"); selectFileUI = new SelectFileUI(); selectFileUI->UIWindow->position( 30, 30 ); selectFileUI->fileBrowser->type(FL_SELECT_BROWSER); selectFileUI->fileBrowser->callback( staticScreenCB, this ); selectFileUI->dirInput->callback( staticScreenCB, this ); selectFileUI->dirInput->when(FL_WHEN_CHANGED); selectFileUI->fileInput->callback( staticScreenCB, this ); selectFileUI->acceptButton->callback( staticScreenCB, this ); selectFileUI->cancelButton->callback( staticScreenCB, this ); selectFileUI->favsMenuButton->callback( staticScreenCB, this ); LoadFavsMenu(); }
std::string empathy::getBase() { char cCurrentPath[FILENAME_MAX]; if(__base==""){ if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { __base= ""; std::cout<<"Error setting base Directory!"<<std::endl; }else{ cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */ __base=join_path(std::string(cCurrentPath),"empathy"); std::cout<<"Base changed to "<<__base<<std::endl; } } return __base; }
std::string getPath() { std::string fullpath; // ---------------------------------------------------------------------------- // This makes relative paths work in C++ in Xcode by changing directory to the Resources folder inside the .app bundle #ifdef __APPLE__ CFBundleRef mainBundle = CFBundleGetMainBundle(); CFURLRef resourcesURL = CFBundleCopyResourcesDirectoryURL(mainBundle); char path[PATH_MAX]; if (!CFURLGetFileSystemRepresentation(resourcesURL, TRUE, (UInt8 *)path, PATH_MAX)) { // error! } CFRelease(resourcesURL); chdir(path); fullpath = path; #else char cCurrentPath[1024]; if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) return ""; cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; fullpath = cCurrentPath; #endif return fullpath; }
//--------------------------------------------------------------------------- void __fastcall CTerminalRobotTyper::RestoreKeyInterval(){ TIniFile *ini = new TIniFile(GetCurrentDir() + "\\app.ini"); int keyInterval = ini->ReadInteger(terminal->xmlConfig->TerminalID , "KeyboardInterval", terminal->panel->TrackBarKey->Position); delete ini; terminal->panel->TrackBarKey->Position =keyInterval; keyIntervalRestored =true; }
ULONG DosWowSetDefaultDrive(UCHAR Drive) { PCDS pCDS; if (NULL != (pCDS = GetCDSFromDrv (Drive))) { if (GetCurrentDir (pCDS, Drive)) { if (*(PUCHAR)DosWowData.lpCurDrv != Drive) { // The upper bit in the TDB_Drive byte is used to indicate // that the current drive and directory information in the // TDB is stale. Turn it off here. PTDB pTDB; if (*pCurTDB) { pTDB = (PTDB)SEGPTR(*pCurTDB,0); if (TDB_SIGNATURE == pTDB->TDB_sig) { pTDB->TDB_Drive &= ~TDB_DIR_VALID; } } *(PUCHAR)DosWowData.lpCurDrv = Drive; } } } return (*(PUCHAR)DosWowData.lpCurDrv); }
unsigned int LoadTexture(const std::string& dataPath) { glEnable(GL_TEXTURE_2D); std::string fPath = GetCurrentDir(); // Get current directory, SOIL doesn't seem to work from executable directory fPath.append("img\\" + dataPath); unsigned int tex_2d = SOIL_load_OGL_texture ( fPath.c_str(), SOIL_LOAD_AUTO, SOIL_CREATE_NEW_ID, SOIL_FLAG_MIPMAPS | SOIL_FLAG_INVERT_Y | SOIL_FLAG_NTSC_SAFE_RGB | SOIL_FLAG_COMPRESS_TO_DXT ); if (tex_2d == 0) { std::string s = "\n\n---- SOIL ERROR ----\nFilename: " + fPath; s.append("\nSOIL Message: "); s.append(SOIL_last_result()); s.append("\n\n"); Log::Write(s.c_str(), ENGINE_LOG); } glBindTexture(GL_TEXTURE_2D, tex_2d); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR); glTexParameterf(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR); glBindTexture(GL_TEXTURE_2D, 0); glDisable(GL_TEXTURE_2D); return tex_2d; }
int main(int argc, char* argv[]){ int exitCode = psm::StatusNoError; char cCurrentPath[FILENAME_MAX]; cCurrentPath[sizeof(cCurrentPath)-1] = '\0'; /* not really required */ if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { return errno; } printf("The current working directory is %s", cCurrentPath); psm::IApp * app = new(std::nothrow) PSMAPP(); app->processArguments(argc, argv); exitCode = app->run(); delete app; app = nullptr; return exitCode; }
int main() { FILE * f; char fname[FILENAME_MAX] = "log_testClassPoint.txt"; char cCurrentPath[FILENAME_MAX]; f = fopen(fname, "w"); if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { return EXIT_FAILURE; } cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */ fprintf (f, "The current working directory is %s\n\n", cCurrentPath); int res = 0, ntests = 0; res += testNorm(f); ntests++; res += testNormalized(f); ntests++; res += testScalarP(f); ntests++; res += testDet(f); ntests++; res += testCoordTransToEllipse(f); ntests++; res += testCoordTransToCart(f); ntests++; res += testRotate(f); ntests++; fclose(f); return (res==ntests)?EXIT_SUCCESS:EXIT_FAILURE; }
//get_working_dir std::string get_working_dir() { char buff[FILENAME_MAX]; GetCurrentDir(buff, FILENAME_MAX); std::string current_working_dir(buff); return current_working_dir; }
// On success, currdir_relative_to_root will be a canonical path. Res FindRoot(string* absolute_root, string* currdir_relative_to_root) { string currdir = GetCurrentDir(); // Look for root dir. Root dir is marked by the presence of a // "root.dmb" file. string root = currdir; for (;;) { if (FileExists(PathJoin(root, "root.dmb"))) { break; } if (HasParentDir(root)) { root = ParentDir(root); } else { return Res(ERR, "Can't find root.dmb in ancestor directories"); } } *absolute_root = root; const char* remainder = currdir.c_str() + root.length(); if (remainder[0] == '/') { remainder++; } *currdir_relative_to_root = remainder; assert(currdir_relative_to_root->size() == 0 || (*currdir_relative_to_root)[currdir_relative_to_root->length() - 1] != '/'); return Res(OK); }
// remove any . or .. and make absolute if necessary Path& Path::normalize() { size_t i = 0; bool wasMadeAbsolute = isAbsolute(); while (i < mPaths.size()) { if (mPaths[i] == ".") { mPaths.erase(mPaths.begin()+i); } else if (mPaths[i] == "..") { if (i == 0) { if (wasMadeAbsolute) { // invalid path mPaths.clear(); break; } Path cwd = GetCurrentDir(); cwd.pop(); size_t sz = cwd.mPaths.size(); mPaths.erase(mPaths.begin()+i); mPaths.insert(mPaths.begin(), cwd.mPaths.begin(), cwd.mPaths.end()); i = sz; wasMadeAbsolute = true; } else { mPaths.erase(mPaths.begin()+i); mPaths.erase(mPaths.begin()+i-1); --i; } } else { ++i; } } mFullName = fullname(DIR_SEP); return *this; }
//---------------- // void WriteDatFile( TYPE_File *writeFile ) { char* currentDir; appendToLogfile("WriteDatFile: Started.", INFO); appendToLogfile("WriteDatFile: GetCurrentDir called.", WARNING); currentDir = GetCurrentDir(); // Store the current directory. appendStringToLogfile("WriteDatFile: GetCurrentDir returned=%s.",currentDir, WARNING); appendStringToLogfile("WriteDatFile: Moving to=%s.",TAPIniDir, WARNING); GotoPath(TAPIniDir); // Go to the Project Directory. if ( TAP_Hdd_Exist( PLAYDATA_FILENAME ) ) TAP_Hdd_Delete( PLAYDATA_FILENAME ); // Just delete any old copies appendToLogfile("WriteDatFile: Creating DATA file.", ERR); TAP_Hdd_Create( PLAYDATA_FILENAME, ATTR_PROGRAM ); // Create the file appendToLogfile("WriteDatFile: Opening DATA file.", ERR); writeFile = TAP_Hdd_Fopen( PLAYDATA_FILENAME ); if ( writeFile == NULL ) return; // Check we can open it appendToLogfile("WriteDatFile: Writing to DATA file.", ERR); TAP_Hdd_Fwrite( playDataBuffer_ini, PLAYBACKDATA_BUFFER_SIZE_ini, 1, writeFile ); // dump the whole buffer in one hit appendToLogfile("WriteDatFile: Closing DATA file.", ERR); TAP_Hdd_Fclose( writeFile ); appendStringToLogfile("WriteDatFile: Returning to=%s.",currentDir, WARNING); GotoPath(currentDir); // Return to the original directory. TAP_MemFree( currentDir ); // Free allocated memory. appendToLogfile("WriteDatFile: Finished.", INFO); }
std::string getCurrentDir() { char cCurrentPath[FILENAME_MAX]; if (!GetCurrentDir(cCurrentPath, sizeof (cCurrentPath))) { return std::string(itoa(errno)); } cCurrentPath[sizeof (cCurrentPath) - 1] = '\0'; /* not really required */ return std::string(cCurrentPath); }
HRESULT CZZExcel2Word::InitExportSettings() { std::wstring curdir = GetCurrentDir(); std::wstring initFilePath; m_stringWordTemplatePath = curdir + Template_FILE_NAME; initFilePath = curdir+INI_FILE_NAME; return InitExportSettings(initFilePath.c_str()); }
/* -------------------------------------------------------- */ void Menu::saveAs_activate_cb() { if(!this->saveAsFile) Log::LogWarn(LEVEL_LOG_INFO, "Unable to load open window", __FILE__, __LINE__); this->saveAsFile->set_current_folder(GetCurrentDir()); this->saveAsFile->run(); }
// if path is relative, prepend current directory Path& Path::makeAbsolute() { if (!isAbsolute()) { Path cwd = GetCurrentDir(); mPaths.insert(mPaths.begin(), cwd.mPaths.begin(), cwd.mPaths.end()); mFullName = fullname(DIR_SEP); } return *this; }
//--------------------------------------------------------------------------- void __fastcall TForm1::FormCreate(TObject *Sender) { start=1; mode=0; Dir_for_file=GetCurrentDir(); start_form_ini(Form1); start=0; }
std::string GetCurrentWorkingDir(void) { char buff[FILENAME_MAX]; auto result = GetCurrentDir(buff, FILENAME_MAX); if (result) { std::string current_working_dir(buff); return current_working_dir; } return ""; }
std::string GetWorkingDirectory() { if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { return ""; } cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */ return cCurrentPath; }
//--------------------------------------------------------------------------- void __fastcall TForm1::Button5Click(TObject *Sender) { AnsiString cd; FILE *f; int i; dword curpos; if(OpenDialog->Execute()) { cd=GetCurrentDir()+"\\"; default_txt= OpenDialog->FileName.SubString(cd.Length()+1,OpenDialog->FileName.Length()-cd.Length()); Timer->Enabled=true; f=fopen(OpenDialog->FileName.c_str(),"rb+"); Log->Clear(); //Заголовок Log->Lines->Add("Чтение заголовка..."); fread(BookHeader,sizeof(BookHeader),1,f); Title->Text=""; for(i=0;i<64;i++)Title->Text=Title->Text+(char)BookHeader[i]; Author->Text=""; for(i=64;i<224;i++)Author->Text=Author->Text+(char)BookHeader[i]; //Количество страниц Log->Lines->Add("Чтение количества страниц..."); fread(&PagesCount,sizeof(PagesCount),1,f); CurrentPage=1; PC->Caption=IntToStr(PagesCount); CP->Caption=IntToStr(CurrentPage); PCMax->Value=PagesCount; //Адреса страниц Log->Lines->Add("Чтение адресов страниц..."); fread(PageAddress,sizeof(dword)*PagesCount,1,f); curpos=ftell(f); fseek(f,0,SEEK_END); PageAddress[PagesCount]=ftell(f); fseek(f,curpos,SEEK_SET); //Размер страниц Log->Lines->Add("Подсчет размеров страниц..."); for(i=0;i<PagesCount;i++)PageSize[i]=PageAddress[i+1]-PageAddress[i]; //Страницы Log->Lines->Add("Чтение содержимого страниц..."); for(i=0;i<PagesCount;i++) { fseek(f,PageAddress[i],SEEK_SET); fread(Page[i],sizeof(byte)*PageSize[i],1,f); Application->ProcessMessages(); } Log->Lines->Add("Чтение документа "+OpenDialog->FileName+" завершено."); Form1->Caption="TES: Daggerfall Book Editor { "+OpenDialog->FileName+" }"; Timer->Enabled=false; fclose(f); SpeedButton3Click(NULL); SaveDialog->FileName=OpenDialog->FileName; Form1->Caption="TES2:Daggerfall Books-files Editor { "+default_txt+" }"; Application->Title="{ "+default_txt+" }"; } }
void __fastcall TfMain::FormShow(TObject *Sender) { TStringList* sl = new(TStringList); sl->NameValueSeparator = '='; TFile f; if(f.Exists(ExtractFileDir(Application->ExeName) + "\\Library.lb")){ sl->LoadFromFile(GetCurrentDir() + "\\Library.lb"); for(int i = 0; i < sl->Count; i++){ TListItem* Item = lvLib->Items->Add(); Item->Caption = ExtractFileName(sl->Names[i]); Item->GroupID = 0; Item->SubItems->Add(sl->Names[i]); //path [0] TStringList* ss = new(TStringList); ss->NameValueSeparator = '/'; ss->Add(sl->ValueFromIndex[i]); Item->SubItems->Add(ss->Names[0]); //bookmark [1] Item->SubItems->Add(ss->ValueFromIndex[0]); //size [2] ss->~TStringList(); } } sl->Clear(); if(f.Exists(ExtractFileDir(Application->ExeName) + "\\Settings.ini")){ sl->LoadFromFile(GetCurrentDir() + "\\Settings.ini"); leLogin->Text = sl->ValueFromIndex[0]; lePass->Text = sl->ValueFromIndex[1]; if(sl->ValueFromIndex[2] == "1") cbRememberPass->Checked = true; else cbRememberPass->Checked = false; leServer->Text = sl->ValueFromIndex[3]; } sl->~TStringList(); }
// get path void HGPU_io_path_get(char** path){ if (!path) HGPU_error(HGPU_ERROR_ARRAY_OUT_OF_BOUND); size_t path_length = HGPU_FILENAME_MAX; char* path_new = *path; if (!path_new) HGPU_string_resize(&path_new,path_length); if (!GetCurrentDir(path_new,(int) path_length)) HGPU_error_message(HGPU_ERROR_DEVICE_INITIALIZATION_FAILED,"could not obtain inf path"); HGPU_io_path_set_separator(&path_new,path_length); *path = path_new; }
SetDirectory::SetDirectory(const char* filename) { directory = GetParentDir(filename); if (!directory.empty()) { previousDir = GetCurrentDir(); if (chdir(directory.c_str()) != 0) msg_error("SetDirectory") << "can't change directory."; } }
std::string get_current_working_directory() { std::string cwd(256, '\0'); //todo: use a max_filepath macro GetCurrentDir(&cwd[0], cwd.length()); //suposedly grabbing the address of std::string[0] works in c++11 onwards size_t new_size = 0; for (; cwd[new_size] != '\0'; ++new_size); cwd.resize(new_size); return cwd; }
/* * muodostaTiedostopolku - muodostaa tiedostpolun työhakemistoon * * char *polku - tiedostopolku, joka toimii myös paluuarvona. Sen pituuden tulisi olla vähintään FILENAME_MAX * char *tiedosto - tiedoston nimi * * Paluuarvo char * - tiedoston polku työhakemistossa * * Muodostaa tiedostolle polun nykyiseen työhakemistoon seuraavalla kaavalla: * Windows: <työhakemisto>\tiedosto * Linux: <työhakemisto>/tiedosto * */ void muodostaTiedostopolku(char *polku, char *tiedosto) { GetCurrentDir(polku, FILENAME_MAX); // Linuxissa polku alkaa /-merkillä. Valitaan sen avulla sopiva erotinmerkki. char erotin = '\\'; if (polku[0] == '/') erotin = '/'; // Tallennetaan tiedostopolkuun <polku><erotin><tiedosto> sprintf(polku, "%s%c%s", polku, erotin, tiedosto); }
//--------------------------------------------------------------------------- __fastcall TMainForm::TMainForm(TComponent* Owner) : TForm(Owner) { Bitmap=new Graphics::TBitmap; CurDir=GetCurrentDir(); if(FileExists(CurDir+"\\config.txt")) Pars.LoadFromFile(CurDir+"\\config.txt"); CalOn=false; MovOn=false; ExSignals=new float[1]; EmSignals=new float[1]; }
int ring_currentdir ( char *cDirPath ) { int nSize ; nSize = 200 ; if ( !GetCurrentDir(cDirPath, nSize) ) { return errno ; } cDirPath[nSize-1] = '\0' ; return 0 ; }
//------------------------------------------------------------------------------ std::string getCurrentWorkingDir() { char cCurrentPath[FILENAME_MAX]; if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { // Should probably throw... return ""; } return std::string(cCurrentPath); }
void CMAC::initProgramPath() { char cCurrentPath[FILENAME_MAX]; if (!GetCurrentDir(cCurrentPath, sizeof(cCurrentPath))) { cout<<"ERROR: Can't find current path"<<endl; } cCurrentPath[sizeof(cCurrentPath) - 1] = '\0'; /* not really required */ programPath = cCurrentPath; }