void CLoadPortalFileDialog::OnLoadOther() { CFileDialog dlg(TRUE, "prt", portals.fn, OFN_NOCHANGEDIR | OFN_HIDEREADONLY | OFN_LONGNAMES | OFN_FILEMUSTEXIST, "Portal files (*.prt)|*.prt|All Files (*.*)|*.*||", NULL); dlg.m_ofn.lpstrTitle = "Locate portal file"; if(IDOK == dlg.DoModal()) { _fullpath(portals.fn, dlg.GetPathName().GetBuffer(1), _MAX_PATH); m_fn_ctrl.SetWindowText(portals.fn); } }
/* * realpath() for Windows. Turns slashes into backslashes and calls _fullpath */ char *realpath(const char *path, char *resolved_path) { char *p; char tmp[_MAX_PATH + 1]; strlcpy(tmp, path, sizeof(tmp)); p = tmp; while (*p) { if (*p == '/') { *p = '\\'; } p++; } return _fullpath(resolved_path, tmp, _MAX_PATH); }
static BOOL GetFileName ( CString & strFileName ) { CString sTmp (strFileName); _fullpath (strFileName.GetBuffer (258), sTmp, 256); strFileName.ReleaseBuffer (-1); // get the drive name CString sDrive (strFileName); int iInd = sDrive.Find ('\\'); if (iInd >= 0) sDrive.ReleaseBuffer ( iInd + 1 ); // if it's a CD we prompt them to insert the CD if (GetDriveType (sDrive) == DRIVE_CDROM) { CDlgSelCD dlg; dlg.m_sFileName = strFileName; dlg.m_strMsg.LoadString (IDS_INSERT_CD); char sBuf[2]; sBuf[0] = toupper (strFileName[0]); sBuf[1] = 0; csPrintf (&dlg.m_strMsg, (char const *) sBuf); if (dlg.DoModal () != IDOK) { TRAP (); return (FALSE); } strFileName = dlg.m_sFileName; } else // not a CD - prompt for the location { CString sMsg; sMsg.LoadString (IDS_BAD_DATA_FILE); csPrintf (&sMsg, (char const *) strFileName); if (AfxMessageBox (sMsg, MB_YESNO | MB_ICONSTOP) != IDYES) return (FALSE); CString sFilters; sFilters.LoadString (IDS_DATA_FILTERS); CFileDialog dlg (TRUE, "dat", strFileName, OFN_FILEMUSTEXIST, sFilters, NULL); if (dlg.DoModal () != IDOK) return (FALSE); strFileName = dlg.GetPathName (); } return (TRUE); }
void main( int argc, char *argv[] ) { int i; char buff[ PATH_MAX ]; for( i = 1; i < argc; ++i ) { puts( argv[i] ); if( _fullpath( buff, argv[i], PATH_MAX ) ) { puts( buff ); } else { puts( "FAIL!" ); } } }
std::string realpath(std::string fileName) { struct free_delete { void operator()(char* x) const { free(static_cast<void *>(x)); } }; #ifdef _MSC_VER std::unique_ptr<char, free_delete> buffer(_fullpath(nullptr, fileName.c_str(), _MAX_PATH)); #else std::unique_ptr<char, free_delete> buffer(realpath(fileName.c_str(), nullptr)); #endif return buffer.get(); }
bool CBrowseDir::SetInitDir(const char *dir) { //先把dir转换为绝对路径 if (_fullpath(m_szInitDir,dir,_MAX_PATH) == NULL) return false; //判断目录是否存在 if (_chdir(m_szInitDir) != 0) return false; //如果目录的最后一个字母不是'\',则在最后加上一个'\' int len=strlen(m_szInitDir); if (m_szInitDir[len-1] != '\\') strcat(m_szInitDir,"\\"); return true; }
/*************** MAIN PROGRAM ******************************/ int main(int arg_count, char **args) { char startpath[_MAX_PATH], *apu; char *defaultdir = "."; unsigned long disk_size,disk_free, summa; double slack; printf("\nDU/" VERSION_BITS "bit v" VERSION_NO " Copyright (c) Timo Kokkonen, OH6LXV " RELEASE_DATE "\n\n"); strcpy(startpath,"."); if (arg_count>1) { if (!strcmp(args[1],"/?")) { print_syntax(); exit(0); } if (args[arg_count-1][0]=='/') if (sscanf(&args[arg_count-1][1],"%d",&sublevels)!=1) { printf("\nInvalid parameter '%s'.\n",args[arg_count-1]); print_syntax(); exit(1); } } if ((arg_count>=2)&&(args[1][0]!='/')) apu=args[1]; else apu=defaultdir; if (!_fullpath(startpath,apu,_MAX_PATH)) { printf("Cannot convert '%s' to absolute path.\n",apu); exit(1); } if (startpath[strlen(startpath)-1]!='\\') strcat(startpath,"\\"); strcpy(startpath,SplitDir(startpath)); if (!getDiskSize(startpath[0]-64,&disk_size,&disk_free,&cluster_size)) { printf("Cannot read drive %c: \n",startpath[0]); exit(1); } summa=calc_dir(startpath); if (true_sum!=0) slack=(1-(double)summa/true_sum)*100.0; else slack=0; // printf(" %lu %lu %lu \n",disk_size-disk_free,summa,true_sum); printf("\n %lu bytes in %lu file(s), %1.1lf%% slack (%lu bytes).\n", true_sum, file_counter, slack, true_sum-summa); return 0; }
IO_METHOD(IoObject, installPrefix) { char acPath[256]; char root[256]; if( GetModuleFileName( NULL, acPath, 256 ) != 0) { // guaranteed file name of at least one character after path strcpy(( strrchr( acPath, '\\' ) ), "\\..\\"); _fullpath(root,acPath,256); } return IoState_symbolWithCString_(IOSTATE, root); }
////////////////////////////////////////////////////////////////////////////////////////// // Open a file. XsensResultValue Cmt1f::open(const char* filename, const bool create, const bool readOnly) { if (m_isOpen) return m_lastResult = XRV_ALREADYOPEN; //! \test does this work for non-existing files? Or do we need a check and create? m_readOnly = readOnly; if (readOnly) m_handle = fopen(filename, "rb"); // open for read only (r) else m_handle = fopen(filename, "r+b"); // open for update (r/w) if (m_handle == NULL) { if (create) m_handle = fopen(filename, "w+b"); // create for update (r/w) else { m_handle = fopen(filename, "rb"); // open for read only (r) m_readOnly = true; } } if (m_handle == NULL) return m_lastResult = XRV_INPUTCANNOTBEOPENED; #ifdef _WIN32 if (_fullpath(m_filename,filename,CMT_MAX_FILENAME_LENGTH) == NULL) { fclose(m_handle); return m_lastResult = XRV_INVALIDPARAM; } #else // use the same trick again. if (realpath(filename, m_filename) == NULL) { fclose(m_handle); return m_lastResult = XRV_INVALIDPARAM; } #endif mbstowcs(m_filename_w,m_filename,CMT_MAX_FILENAME_LENGTH); m_unicode = false; m_isOpen = true; m_readPos = 0; m_writePos = 0; m_reading = true; FSEEK_R(0); m_fileSize = FTELL(); FSEEK(0); return (m_lastResult = XRV_OK); }
//============================================================================= //============================================================================= std::string CPdpManager::GetFilePath(unsigned int idx )const { string Path = GetProjectPath(); string PathFile; vector<char> absPath; Path += GetFileName(idx); absPath.resize(MAX_PATH+1); if (0 == _fullpath(&(absPath[0]), Path.c_str(),absPath.size())) return ""; return &(absPath[0]); }
char* sl_realpath(sl_vm_t* vm, char* path) { char *cpath, *gcbuff; if(!path[0] || path[1] != ':') { gcbuff = sl_alloc_buffer(vm->arena, strlen(vm->cwd) + strlen(path) + 10); strcpy(gcbuff, vm->cwd); strcat(gcbuff, "/"); strcat(gcbuff, path); path = gcbuff; } #ifdef _MAX_PATH cpath = sl_alloc_buffer(vm->arena, _MAX_PATH + 1); cpath = _fullpath(cpath, path, _MAX_PATH); return cpath; #else cpath = _fullpath(NULL, path, 0); gcbuff = sl_alloc_buffer(vm->arena, strlen(cpath) + 1); strcpy(gcbuff, cpath); free(cpath); return gcbuff; #endif }
FDirectory::FDirectory(const char * directory) : FResourceFile(NULL, NULL) { FString dirname; #ifdef _WIN32 directory = _fullpath(NULL, directory, _MAX_PATH); #else // Todo for Linux: Resolve the path befire using it #endif dirname = directory; dirname.ReplaceChars('\\', '/'); if (dirname[dirname.Len()-1] != '/') dirname += '/'; Filename = copystring(dirname); }
/* get full path from relative path -------------------------------------------- * args : char *relpath I relative path * char *fullpath O full path * return : int 0:success, -1:failure *-----------------------------------------------------------------------------*/ extern int getfullpath(char *relpath, char *abspath) { #ifdef WIN32 if (_fullpath(abspath,relpath,_MAX_PATH)==NULL) { SDRPRINTF("error: getfullpath %s\n",relpath); return -1; } #else if (realpath(relpath,abspath)==NULL) { SDRPRINTF("error: getfullpath %s\n",relpath); return -1; } #endif return 0; }
bool Loader::Open(char *fName) { Close(); strcpy(fileName, fName); f = fopen(fileName, "rb"); if (!f) return false; _fullpath(fileFullPath, fileName, _MAX_PATH); fileLength = _filelength(_fileno(f)); curLine = 0; return true; }
void RuntimeEngine::setProjectPath(const std::string &workPath) { #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32 || CC_TARGET_PLATFORM == CC_PLATFORM_MAC) vector<std::string> searchPathArray = FileUtils::getInstance()->getSearchPaths(); if (workPath.empty()) { std::string appPath = std::string(""); #if (CC_TARGET_PLATFORM == CC_PLATFORM_WIN32) TCHAR szAppDir[MAX_PATH] = { 0 }; if (GetModuleFileName(NULL, szAppDir, MAX_PATH)) { int nEnd = 0; for (int i = 0; szAppDir[i]; i++) { if (szAppDir[i] == '\\') nEnd = i; } szAppDir[nEnd] = 0; int iLen = 2 * wcslen(szAppDir); char* chRtn = new char[iLen + 1]; wcstombs(chRtn, szAppDir, iLen + 1); std::string strPath = chRtn; delete[] chRtn; chRtn = NULL; char fuldir[MAX_PATH] = { 0 }; _fullpath(fuldir, strPath.c_str(), MAX_PATH); appPath = fuldir; } #elif (CC_TARGET_PLATFORM == CC_PLATFORM_MAC) appPath.append("/../../../"); #endif appPath = replaceAll(appPath, "\\", "/"); g_projectPath = appPath; } else { g_projectPath = workPath; } // add project's root directory to search path searchPathArray.insert(searchPathArray.begin(), g_projectPath); // add writable path to search path searchPathArray.insert(searchPathArray.begin(), FileServer::getShareInstance()->getWritePath()); FileUtils::getInstance()->setSearchPaths(searchPathArray); #endif }
char *realpath(const char *name, char *resolvedname) { if (name == NULL) { return NULL; } else if (access(name, R_OK) != 0) { return NULL; } else { resolvedname = _fullpath(resolvedname, name, MAX_PATH_SIZE); return resolvedname; } }
static rdos_handle_type *AllocHandleObj( const char *file_name ) { rdos_handle_type *h; char *buf = 0; if( file_name ) buf = _fullpath( 0, file_name, 0 ); h = ( rdos_handle_type * )lib_malloc( sizeof( rdos_handle_type ) ); h->rdos_handle = HANDLE_TYPE_FILE; h->mode = 0; h->type = 0; h->ref_count = 1; h->file_name = buf; return( h ); }
/* * Convert to forward slashes. Resolve to full pathname optionally */ char* w32ify(char* filename, int resolve) { static char w32_path[FILENAME_MAX]; char* p; if (resolve) _fullpath(w32_path, filename, sizeof(w32_path)); else strncpy(w32_path, filename, sizeof(w32_path)); for (p = w32_path; p && *p; p++) if (*p == '\\') *p = '/'; return w32_path; }
// Is absolute path? Boolean System::is_absolute_path(const char *path) { char full[_MAX_PATH]; char path_slash[_MAX_PATH]; char *p; strncpy(path_slash, path, _MAX_PATH); path_slash[_MAX_PATH-1] = '\0'; for (p = path_slash; p < path_slash + strlen(path_slash); p++) if (*p == '/') *p = '\\'; return (strcasecmp( _fullpath(full, path_slash, _MAX_PATH), path_slash) == 0); }
LPCTSTR PrintFullPathCultureNames(string& partialPathS) { partialPathS = "names\\" + partialPathS; const char* partialPath = partialPathS.c_str(); char full[_MAX_PATH]; if (_fullpath(full, partialPath, _MAX_PATH) != NULL) { miscellaneousAttributes& misc = miscellaneousAttributes::get_instance(); misc.cultureNamesPath = full; CString str(full); LPCTSTR res = str; return res; } else { std::cerr << "Could not resolve absolute path for the culture name file\n"; throw exception(); } }
void BasicPathName<TChar>::internalCanonicalizePath(const char* srcPath, BasicPathName<char>* outPath) const { char tmpPath[LN_MAX_PATH + 1] = { 0 }; char* canonPath; #ifdef _WIN32 canonPath = _fullpath(tmpPath, srcPath, LN_MAX_PATH); #else canonPath = realpath(mPath.c_str(), pathbuf); #endif if (canonPath == NULL) { // 変換失敗 *outPath = BasicPathName<char>(); } else { *outPath = BasicPathName<char>(tmpPath); } }
void kpr2jsResolvePath(xsMachine* the) { #if mxWindows char* srcPath; char aPath[1024]; DWORD attributes; int aResult = 0; srcPath = xsToString(xsArg(0)); if (_fullpath(aPath, srcPath, 1024) != NULL) { attributes = GetFileAttributes(aPath); if (attributes != 0xFFFFFFFF) { if (xsToInteger(xsArgc) == 1) aResult = 1; else if (xsToBoolean(xsArg(1))) aResult = (attributes & FILE_ATTRIBUTE_DIRECTORY) ? 1 : 0; else aResult = (attributes & FILE_ATTRIBUTE_DIRECTORY) ? 0 : 1; } } #else char* srcPath; char aPath[PATH_MAX]; struct stat a_stat; int aResult = 0; srcPath = xsToString(xsArg(0)); if (realpath(srcPath, aPath) != NULL) { if (stat(aPath, &a_stat) == 0) { if (xsToInteger(xsArgc) == 1) aResult = 1; else if (xsToBoolean(xsArg(1))) aResult = S_ISDIR(a_stat.st_mode) ? 1 : 0; else aResult = S_ISREG(a_stat.st_mode) ? 1 : 0; } } #endif if (aResult) { if (xsToBoolean(xsArg(1))) { aResult = strlen(aPath) - 1; if (aPath[aResult] == mxSeparator) aPath[aResult] = 0; } xsResult = xsString(aPath); } }
int HEFileOpen(HWND hwnd,char *filename,int enableReload) { char *buf = NULL; ULONG size; int ret = 0; WinSendMsg(hwndHMLE,HMLM_NEWDOC,0L,0L); size = fileRead2Buf( filename, &buf ); if( buf != NULL ) { BOOL readOnly = ( BOOL )WinSendMsg( hwndHMLE, HMLM_QUERYREADONLY, 0, 0 ); WinSendMsg( hwndHMLE, HMLM_SETREADONLY, MPFROMLONG( FALSE ), 0 ); WinSendMsg(hwndHMLE,HMLM_SETIMPORTEXPORT,buf,MPFROMLONG(size+1)); WinSendMsg(hwndHMLE,HMLM_IMPORT,0,0); WinSendMsg(hwndHMLE,HMLM_SETFIRSTCHAR,MPFROMLONG(0),0); WinSendMsg( hwndHMLE, HMLM_SETREADONLY, MPFROMLONG( readOnly ), 0 ); /* _fullpath( szFullPath,filename, sizeof( szFullPath )); extractDirname(); _chdir2(szDir); */ if (enableReload) EnableReloadButton(hwnd); ret = queryHanTypeBuf( buf ); free( buf ); } else { // szFullPath[0]=0; ret = -1; } _fullpath( szFullPath,filename, sizeof( szFullPath )); extractDirname(); _chdir2(szDir); HESetTitlebarText(hwnd); WinPostMsg(hwndStatbar,STATBAR_USERM_SETMODIFIED,0L,0L); WinPostMsg(hwndHMLE,HMLM_SETCHANGED,0,0); WinPostMsg(hwndHMLE,HMLM_REFRESH,0,0); return ret; }
/** * Return if the root path of the given filename exists or not. * boost::filesystem::is_directory might be better * though it requires building. */ inline bool is_directory(const std::string& filename) { #ifndef WIN32_MSC struct stat buf; const int ret = stat(dirname(strdup(filename.c_str())), &buf); return (ret == 0); #else char drive[_MAX_DRIVE + 1], dir[_MAX_DIR + 1], path_dir[_MAX_PATH + 1], full[_MAX_PATH]; // struct _stat buf; _fullpath(full, filename.c_str(), _MAX_PATH); _splitpath(full, drive, dir, NULL, NULL); _makepath(path_dir, drive, dir, NULL, NULL); // const int ret = _stat(path_dir, &buf); const int ret = _access(path_dir, 0); return (ret == 0); #endif }
nsresult XPCOMGlueLoad(const char *xpcomFile, GetFrozenFunctionsFunc *func) { CHAR pszError[_MAX_PATH]; ULONG ulrc = NO_ERROR; HMODULE h; if (xpcomFile[0] == '.' && xpcomFile[1] == '\0') { xpcomFile = XPCOM_DLL; } else { char xpcomDir[MAXPATHLEN]; _fullpath(xpcomDir, xpcomFile, sizeof(xpcomDir)); char *lastSlash = ns_strrpbrk(xpcomDir, "/\\"); if (lastSlash) { *lastSlash = '\0'; XPCOMGlueLoadDependentLibs(xpcomDir, ReadDependentCB); snprintf(lastSlash, MAXPATHLEN - strlen(xpcomDir), "\\" XUL_DLL); DosLoadModule(pszError, _MAX_PATH, xpcomDir, &sXULLibrary); } } ulrc = DosLoadModule(pszError, _MAX_PATH, xpcomFile, &h); if (ulrc != NO_ERROR) return nsnull; AppendDependentLib(h); GetFrozenFunctionsFunc sym; ulrc = DosQueryProcAddr(h, 0, "_NS_GetFrozenFunctions", (PFN*)&sym); if (ulrc != NO_ERROR) { XPCOMGlueUnload(); return NS_ERROR_NOT_AVAILABLE; } *func = sym; return NS_OK; }
SkString get_absolute_path(const SkString& path) { #if SK_BUILD_FOR_MAC || SK_BUILD_FOR_UNIX || SK_BUILD_FOR_ANDROID SkString fullPath(PATH_MAX + 1); if (realpath(path.c_str(), fullPath.writable_str()) == NULL) { fullPath.reset(); } return fullPath; #elif SK_BUILD_FOR_WIN32 SkString fullPath(MAX_PATH); if (_fullpath(fullPath.writable_str(), path.c_str(), MAX_PATH) == NULL) { fullPath.reset(); } return fullPath; #else return SkString(); #endif }
char * canonicalize_file_name (const char *path) { char *ret; #ifdef __MINGW32__ ret = xmalloc (PATH_MAX); if (!_fullpath (ret, path, PATH_MAX)) return NULL; #elif defined (PATH_MAX) ret = xmalloc (PATH_MAX); if (!realpath (path, ret)) return NULL; #else ret = realpath (path, NULL); #endif return ret; }
int main (int argc, char** argv) { RTC::Manager* manager; manager = RTC::Manager::init(argc, argv); // Initialize manager manager->init(argc, argv); #ifdef _WINDOWS std::string path = getParam("manager.modules.load_path"); coil::eraseBlank(path); coil::vstring pathList = coil::split(path, ","); for (int i = 0; i < pathList.size(); i++) { std::string filepath = pathList[i]; char szFullPath[MAX_PATH]; _fullpath(szFullPath, filepath.c_str(), sizeof(szFullPath) / sizeof(szFullPath[0])); std::string path = "PATH="; path += getenv("PATH"); path += ";"; path += szFullPath; putenv(path.c_str()); } #endif // Set module initialization proceduer // This procedure will be invoked in activateManager() function. manager->setModuleInitProc(MyModuleInit); // Activate manager and register to naming service manager->activateManager(); // run the manager in blocking mode // runManager(false) is the default. manager->runManager(); // If you want to run the manager in non-blocking mode, do like this // manager->runManager(true); return 0; }
kString *knh_buff_newRealPathString(CTX, kBytes *ba, size_t pos) { char buf[K_PATHMAX], *path = (char*)knh_Bytes_ensureZero(_ctx, ba) + pos; #if defined(K_USING_WINDOWS_) char *ptr = _fullpath(buf, path, K_PATHMAX); #elif defined(K_USING_POSIX_) char *ptr = realpath(path, buf); #else char *ptr = NULL; KNH_TODO("realpath in your new environment"); #endif kString *s = new_String(_ctx, (const char*)ptr); if(ptr != buf && ptr != NULL) { free(ptr); } return s; }
std::string Path::getAbsoluteFilePath(const std::string& filePath) { std::string absolute_path; #ifdef _WIN32 char absolute[_MAX_PATH]; if (_fullpath(absolute, filePath.c_str(), _MAX_PATH)) absolute_path = absolute; #elif defined(__linux__) || defined(__sun) || defined(__hpux) || defined(__GNUC__) char * absolute = realpath(filePath.c_str(), nullptr); if (absolute) absolute_path = absolute; free(absolute); #else #error Platform absolute path function needed #endif return absolute_path; }