void Foam::argList::getRootCase() { fileName casePath; // [-case dir] specified HashTable<string>::const_iterator iter = options_.find("case"); if (iter != options_.end()) { casePath = iter(); casePath.clean(); if (casePath.empty() || casePath == ".") { // Handle degenerate form and '-case .' like no -case specified casePath = cwd(); options_.erase("case"); } else if (!casePath.isAbsolute() && casePath.name() == "..") { // Avoid relative cases ending in '..' - makes for very ugly names casePath = cwd()/casePath; casePath.clean(); } } else { // Nothing specified, use the current dir casePath = cwd(); } rootPath_ = casePath.path(); globalCase_ = casePath.name(); case_ = globalCase_; // Set the case and case-name as an environment variable if (rootPath_.isAbsolute()) { // Absolute path - use as-is setEnv("FOAM_CASE", rootPath_/globalCase_, true); setEnv("FOAM_CASENAME", globalCase_, true); } else { // Qualify relative path casePath = cwd()/rootPath_/globalCase_; casePath.clean(); setEnv("FOAM_CASE", casePath, true); setEnv("FOAM_CASENAME", casePath.name(), true); } }
void QPython::addImportPath(QString path) { ENSURE_GIL_STATE; // Strip leading "file://" (for use with Qt.resolvedUrl()) if (path.startsWith("file://")) { #ifdef WIN32 // On Windows, path would be "file:///C:\...", so strip 8 chars to get // a Windows-compatible absolute filename to be used as import path path = path.mid(8); #else path = path.mid(7); #endif } if (SINCE_API_VERSION(1, 3) && path.startsWith("qrc:")) { const char *module = "pyotherside.qrc_importer"; QString filename = "/io/thp/pyotherside/qrc_importer.py"; QString errorMessage = priv->importFromQRC(module, filename); if (!errorMessage.isNull()) { emitError(errorMessage); } } QByteArray utf8bytes = path.toUtf8(); PyObject *sys_path = PySys_GetObject((char*)"path"); PyObjectRef cwd(PyUnicode_FromString(utf8bytes.constData()), true); PyList_Insert(sys_path, 0, cwd.borrow()); }
void reApplication::SetupPaths(){ wxStandardPaths& standardPaths = wxStandardPaths::Get(); wxString appPath = standardPaths.GetExecutablePath(); wxFileName cwd(appPath); wxSetWorkingDirectory(cwd.GetPath()); }
//-------------------------------------------------------------- // find a file in parent directories BOOL mgOSFindFile( mgString& location, const char* fileName) { WCHAR* oldCWD = _wgetcwd(NULL, 0); if (oldCWD == NULL) return false; mgString cwd(oldCWD); while (true) { if (cwd.endsWith("\\")) location.format("%s%s", (const char*) cwd, fileName); else location.format("%s\\%s", (const char*) cwd, fileName); WCHAR* wideName; int wideLen; location.toWCHAR(wideName, wideLen); struct _stat filestat; BOOL found = 0 == _wstat(wideName, &filestat); delete wideName; wideName = NULL; if (found) return true; else { // remove last directory from cwd int slash = cwd.reverseFind(cwd.length(), '\\'); if (slash != -1) cwd.deleteAt(slash, cwd.length()-slash); else return false; // no more directories. file not found. } } }
void CommandEventHandler::handleLine(std::string line) { Logger::instance()->log("Recvd line: " + line); CommandLine cl(line); if (cl.cmd.empty()) return; std::string result(agentWarn("unknown command")); if (cl.cmd.compare("cat") == 0) result = cat(cl.args); else if (cl.cmd.compare("cd") == 0) result = cd(cl.args); else if (cl.cmd.compare("cwd") == 0) result = cwd(cl.args); else if (cl.cmd.compare("clok") == 0) result = clok(cl.args); else if (cl.cmd.compare("dirw") == 0) result = dirw(cl.args); else if (cl.cmd.compare("exec") == 0) result = exec(cl.args); else if (cl.cmd.compare("hash") == 0) result = hash(cl.args); else if (cl.cmd.compare("info") == 0) result = info(cl.args); else if (cl.cmd.compare("ps") == 0) result = ps(cl.args); else if (cl.cmd.compare("pull") == 0) result = pull(cl.args); else if (cl.cmd.compare("push") == 0) result = push(cl.args); else if (cl.cmd.compare("isdir") == 0) result = isDir(cl.args); else if (cl.cmd.compare("ls") == 0) result = ls(cl.args); else if (cl.cmd.compare("mkdr") == 0) result = mkdr(cl.args); else if (cl.cmd.compare("quit") == 0) result = quit(cl.args); else if (cl.cmd.compare("rebt") == 0) result = rebt(cl.args); else if (cl.cmd.compare("rm") == 0) result = rm(cl.args); else if (cl.cmd.compare("rmdr") == 0) result = rmdr(cl.args); else if (cl.cmd.compare("testroot") == 0) result = testroot(cl.args); else if (cl.cmd.compare("ver") == 0) result = ver(cl.args); if (!mBufSocket.sendClosed() && !mDataEventHandler) { // FIXME: It appears that DeviceManager will get confused if // the prompt isn't sent with the response for some commands. // I think this is a bug in DeviceManager, but it needs to be // further investigated. result += std::string(ENDL); result += mPrompt; mBufSocket.write(result.c_str(), result.size() + 1); } }
/* Opens the file with the given NAME. Returns the new file if successful or a null pointer otherwise. Fails if no file named NAME exists, or if an internal memory allocation fails. */ struct file * filesys_open (const char *name) { struct pifs_inode *inode = pifs_open2 (&fs_pifs, name, POO_NO_CREATE, cwd ()); if (!inode) return NULL; return file_open (inode); }
void deprecated(std::string msg, ParserState pstate) { std::string cwd(Sass::File::get_cwd()); std::cerr << "DEPRECATION WARNING: " << msg << std::endl; std::cerr << "will be an error in future versions of Sass." << std::endl; std::string rel_path(Sass::File::resolve_relative_path(pstate.path, cwd, cwd)); std::cerr << " on line " << pstate.line+1 << " of " << rel_path << std::endl; }
/* * If up button pushed, making the parent tree widget current will call fill * directory. */ void restorePage::upButtonPushed() { cwd(".."); QTreeWidgetItem *item = m_dirPaths.value(m_cwd); if (item) { directoryWidget->setCurrentItem(item); } statusLine->setText(""); }
void lastDirSet(void) { char *dir; if((dir = cwd(0)) != 0) { ctxtSet(CTXT_TAG_LASTDIR, 1, dir); free(dir); } else error_out_of_memory(); }
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; }
bool filesys_create_folder (const char *name) { struct pifs_inode *inode; inode = pifs_open2 (&fs_pifs, name, POO_FOLDER_MUST_CREATE, cwd ()); if (!inode) return false; pifs_close (inode); return true; }
std::string getcwd() { char *buf = (char *)malloc((PATH_MAX + 1) * sizeof(char)); buf = getcwd(buf, PATH_MAX + 1); std::string cwd(buf); free(buf); return cwd; }
Logger::Logger(const std::string& exe) : prefix_(exe.substr(exe.rfind('/') + 1)), level_(ERROR) { try { log_.reset(open(std::string(cwd() + "/" + prefix_ + ".log").c_str(), O_RDWR | O_APPEND | O_CREAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH)); } catch(std::runtime_error& ex) { std::cerr << "ERROR: couldn't open log" << ex.what() << std::endl; } }
/* * Executed when the tree item in the directory pane is changed. This will * allow us to populate the file pane and make this the cwd. */ void restorePage::directoryItemChanged(QTreeWidgetItem *currentitem, QTreeWidgetItem * /*previousitem*/) { QString fullpath = m_dirTreeItems.value(currentitem); statusLine->setText(""); if (fullpath != "") { cwd(fullpath.toUtf8().data()); fillDirectory(); } }
//-------------------------------------------------------------- // move current working directory up tree until file is found void mgOSFindWD( const char* fileName) { char* oldCWD = getcwd(NULL, 0); if (oldCWD == NULL) throw new mgException("unable to get getcwd"); mgDebug("CWD is %s", oldCWD); BOOL changed = false; mgString cwd(oldCWD); while (true) { mgString name; if (cwd.endsWith("/")) name.format("%s%s", (const char*) cwd, fileName); else name.format("%s/%s", (const char*) cwd, fileName); struct stat filestat; if (0 == stat(name, &filestat)) { mgDebug("found %s", (const char*) name); break; } else { // remove last directory from cwd int slash = cwd.reverseFind(cwd.length(), '/'); if (slash != -1) { cwd.deleteAt(slash, cwd.length()-slash); changed = true; } else { // no more directories. file not found. throw new mgException("mgOSFindWD cannot find %s", fileName); } } } // set the new working directory if (changed) { // move errors.txt to new location mgString oldErrors, newErrors; oldErrors.format("%s/errors.txt", (const char*) oldCWD); newErrors.format("%s/errors.txt", (const char*) cwd); rename(oldErrors, newErrors); if (0 != chdir(cwd)) throw new mgException("unable to chdir(%s)", (const char*) cwd); } free(oldCWD); }
void deprecated_bind(std::string msg, ParserState pstate) { std::string cwd(Sass::File::get_cwd()); std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd)); std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd)); std::string output_path(Sass::File::path_for_console(rel_path, abs_path, pstate.path)); std::cerr << "WARNING: " << msg << std::endl; std::cerr << " on line " << pstate.line+1 << " of " << output_path << std::endl; std::cerr << "This will be an error in future versions of Sass." << std::endl; }
char* GetCWD(char* inBuffer, int inBufferLength) { std::string cwd(HGetCurrentDirectory()); WinToUnixPath(cwd); // if (cwd.get()) std::snprintf(inBuffer, static_cast<unsigned long>(inBufferLength), "%s", cwd.c_str()); // else // *inBuffer = 0; return inBuffer; }
void deprecated(std::string msg, std::string msg2, ParserState pstate) { std::string cwd(Sass::File::get_cwd()); std::string abs_path(Sass::File::rel2abs(pstate.path, cwd, cwd)); std::string rel_path(Sass::File::abs2rel(pstate.path, cwd, cwd)); std::string output_path(Sass::File::path_for_console(rel_path, pstate.path, pstate.path)); std::cerr << "DEPRECATION WARNING on line " << pstate.line + 1; if (output_path.length()) std::cerr << " of " << output_path; std::cerr << ":" << std::endl; std::cerr << msg << " and will be an error in future versions of Sass." << std::endl; if (msg2.length()) std::cerr << msg2 << std::endl; std::cerr << std::endl; }
void Path::parseUnix(const std::string& path) { clear(); std::string::const_iterator it = path.begin(); std::string::const_iterator end = path.end(); if (it != end) { if (*it == '/') { _absolute = true; ++it; } else if (*it == '~') { ++it; if (it == end || *it == '/') { Path cwd(home()); _dirs = cwd._dirs; _absolute = true; } else --it; } while (it != end) { std::string name; while (it != end && *it != '/') name += *it++; if (it != end) { if (_dirs.empty()) { if (!name.empty() && *(name.rbegin()) == ':') { _absolute = true; _device.assign(name, 0, name.length() - 1); } else { pushDirectory(name); } } else pushDirectory(name); } else _name = name; if (it != end) ++it; } } }
bool ValidateFileName (std::wstring& aName, const bool aMustExist) { assert (! aName.empty ()); if (aName.size () < 3) { return false; } std::wstring filename (aName); bool isUNC ((filename.at (0) == L'/') && (filename.at (1) == L'/')); bool isRelative (! isUNC && ((filename.at (1) != L':'))); if (! isRelative) { if (! isUNC && (filename.at (2) != L'/')) { return false; } } else { const int maxlen = PATHMAX * 8; /* The value of PATHMAX assumes short name FAT environment, not long names and / or NTFS, UNC, URL, etc. etc.. Using a larger value significantly reduces the chances of failure when the application is deep in a subdirectory tree. Windows calls require fixed length buffers. */ wchar_t directorybuffer [maxlen]; std::wstring cwd (_wgetcwd (directorybuffer, maxlen)); if (cwd.empty ()) { return false; } if (cwd.size () > 3) { cwd += KSisDirectorySeparator; // trailing backslash is returned inconsistently according to docs for getcwd } filename = cwd + filename; } if (aMustExist) { DWORD attributes (GetFileAttributesW (filename.c_str ())); if (attributes == RESULT) { return false; } } aName = filename; return true; }
bool Client::handleLogin() { //Fetch Login details. - Done in the caller for this. //Send login details to a function which returns a bool. bool validUser = this->sendLogin( data.user.userID , data.user.password , data.user.clientDirectory); //No serverDir because thats on the end of the server. //return the value of the authenication if ( validUser ) { this->user.userID = data.user.userID; this->user.password = data.user.password; this->user.clientDirectory = data.user.clientDirectory; //NEED TO GET FROM THE SERVER. //Check Directories. If No Directory, make Directories + Log files. bfs::path cwd(bfs::current_path()); bfs::path syncpath = cwd; bfs::path sharepath = cwd; syncpath /= (user.userID + "/" + CLIENT_SYNC_DIR) ; sharepath /= (user.userID + "/" + CLIENT_SHARE_DIR ); bfs::path syncfile = syncpath; syncfile /= ("/" + user.userID + CLIENT_SYNC_DIR); bfs::path sharefile = sharepath; sharefile /= ("/" + user.userID + CLIENT_SHARE_DIR); if( bfs::exists(syncpath) ) { //dir } else { bfs::create_directories(syncpath); } if (bfs::exists(syncfile)) { //file } else { this->createFileLog(syncfile.string()); } if ( bfs::exists(sharepath) ) { //dir } else { bfs::create_directories(sharepath); } if ( bfs::exists(sharefile)) { //file } else { this->createFileLog(sharefile.string()); } //Server files are taken from the dropbox thing. i,e after dropbox is created. //ASSERT : Created files. return true; } else { this->user.userID = ""; this->user.password = ""; this->user.clientDirectory = ""; //TODO : Do Nothing. return false; } }
// Converts a possibly relative path to an absolute one std::string makeAbsolute(const std::string &path) { // Check for a URL scheme if (path.empty() || path.find("://") != std::string::npos) { return path; } // Make path absolute std::string abspath(path); if (abspath[0] != '/') { abspath = cwd() + "/" + path; } return canonicalize(abspath); }
void printSourceFileAndLine ( Ostream& os, const fileName& filename, Dl_info *info, void *addr ) { uintptr_t address = uintptr_t(addr); word myAddress = addressToWord(address); if (filename.ext() == "so") { // Convert address into offset into dynamic library uintptr_t offset = uintptr_t(info->dli_fbase); intptr_t relativeAddress = address - offset; myAddress = addressToWord(relativeAddress); } if (filename[0] == '/') { string line = pOpen ( "addr2line -f --demangle=auto --exe " + filename + " " + myAddress, 1 ); if (line == "") { os << " addr2line failed"; } else if (line == "??:0") { os << " in " << filename; } else { string cwdLine(line.replaceAll(cwd() + '/', "")); string homeLine(cwdLine.replaceAll(home(), '~')); os << " at " << homeLine.c_str(); } } }
static int ccx_getattr(const char *path, struct stat *stbuf) { char *info; memset(stbuf, 0, sizeof(struct stat)); stbuf->st_uid = uid; stbuf->st_gid = gid; if(strcmp(path, "/") == 0) { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 3; /* . + .. + fake node */ return 0; } if(!cwd(rdirname(path))) { return -ENOENT; } if(cc_xstream_client_file_info(ccxconn, rbasename(path), &info) != CC_XSTREAM_CLIENT_OK) { return -ENOENT; } if(strcmp(rxmltext(info, "ATTRIB", ""), "file") == 0) { stbuf->st_mode = S_IFREG | 0444; stbuf->st_nlink = 1; stbuf->st_size = atoll(rxmltext(info, "SIZE", "0")); /* seams to only be sent for files */ stbuf->st_atime = atoll(rxmltext(info, "ACCESS", "0")); stbuf->st_mtime = atoll(rxmltext(info, "MODIFICATION", "0")); stbuf->st_ctime = atoll(rxmltext(info, "CHANGE", "0")); } else { stbuf->st_mode = S_IFDIR | 0755; stbuf->st_nlink = 3; /* . + .. + fake node */ stbuf->st_size = 1; stbuf->st_atime = stbuf->st_mtime = stbuf->st_ctime = now; } cc_xfree(info); return 0; }
bool processManifest(std::string manifestPath, TestResults &accumulatedResults) { fprintf(stderr, "manifest %s\n", manifestPath.c_str()); std::string base = basename(manifestPath); std::string dir = dirname(manifestPath); std::string cwd(getcwd()); chdir(dir.c_str()); std::ifstream fin(base.c_str()); YAML::Parser parser(fin); TestResults testResults; YAML::Node doc; while (parser.GetNextDocument(doc)) { for (YAML::Iterator it=doc.begin(); it!=doc.end(); ++it) { if (it->Type() == YAML::NodeType::Map) { testResults.entries++; ManifestEntry manifestEntry(*it); ManifestEntry::Result result = manifestEntry.process(); if (result == ManifestEntry::kSuccess) testResults.successes++; else if (result == ManifestEntry::kFailure) testResults.failures++; else if (result == ManifestEntry::kSkipped) testResults.skipped++; else if (result == ManifestEntry::kManifestError) testResults.manifestErrors++; } } } chdir(cwd.c_str()); fprintf(stderr, "entries: %d, successes: %d, failures: %d, skipped: %d, manifest errors: %d\n", testResults.entries, testResults.successes, testResults.failures, testResults.skipped, testResults.manifestErrors); accumulatedResults.accumulate(testResults); return 0; }
std::string canonicalPath( char* arg ) { std::auto_ptr< char > cwd( ::getcwd( 0, 0 ) ); std::string fullpath( cwd.get() ); std::string inFile( arg ); #if defined( __UNIX__ ) || defined( __APPLE__ ) const char* srchstr = "../"; char sep = '/'; #else const char* srchstr = "..\\"; char sep = '\\'; #endif std::string::size_type idx1( inFile.find( srchstr ) ); if( idx1 == 0 ) { while( idx1 == 0 ) { //must be at start of line std::string::size_type idx2( fullpath.rfind( sep ) ); if( idx2 != std::string::npos ) { fullpath.erase( idx2 ); inFile.erase( idx1, 3 ); } else if( !fullpath.empty() ) { #if defined( __UNIX__ ) || defined( __APPLE__ ) idx2 = 0; #else idx2 = fullpath.find( ':' ); //don't kill drive if( idx2 != std::string::npos ) ++idx2; #endif fullpath.erase( idx2 ); inFile.erase( 0, 3 ); break; } idx1 = inFile.find( srchstr ); } fullpath += sep; fullpath += inFile; } else fullpath = inFile; #if !defined( __UNIX__ ) && !defined( __APPLE__ ) if( fullpath.size() > PATH_MAX ) throw FatalError( ERR_PATH_MAX ); #endif return fullpath; }
int cmd_pushd(char *param) { char *curdir; if((curdir = cwd(0)) != 0) { int rc; rc = ctxtPush(CTXT_TAG_DIRSTACK, curdir); free(curdir); if(rc == E_None) { /* Change to directory specified on command line */ if(param && *param) return cmd_cdd(param); return 0; } } return 1; }
int main(int argc, char *argv[]) { char temp[PATH_MAX]; std::string PATH(getenv("PATH")); std::string cwd(getcwd(temp, MAX_PATH)); #if defined(PLATFORM_WINDOWS) putenv((std::string("PATH=")+cwd+"\\bin;"+PATH).c_str()); #else putenv((std::string("PATH=")+cwd+"/bin:"+PATH).c_str()); #endif HelloHiro helloHiro; if(initemu(0,0,0,0) != 0) return 0; Application::run(); }
/* Creates a file named NAME with the given INITIAL_SIZE. Returns true if successful, false otherwise. Fails if a file named NAME already exists, or if internal memory allocation fails. */ bool filesys_create (const char *name, off_t initial_size) { struct pifs_inode *inode; inode = pifs_open2 (&fs_pifs, name, POO_FILE_MUST_CREATE, cwd ()); if (!inode) return false; if (initial_size <= 0) { pifs_close (inode); return true; } void *space = malloc (512); if (!space) { pifs_delete_file (inode); pifs_close (inode); return false; } memset (space, 0, 512); size_t pos = 0; while (initial_size > 0) { off_t len = initial_size > 512 ? 512 : initial_size; off_t wrote = pifs_write (inode, pos, len, space); if (wrote < 0) { free (space); pifs_delete_file (inode); pifs_close (inode); return false; } pos += wrote; initial_size -= wrote; } free (space); pifs_close (inode); return true; }
//-------------------------------------------------------------- // find a file in parent directories BOOL mgOSFindFile( mgString& location, const char* fileName) { char* oldCWD = getcwd(NULL, 0); if (oldCWD == NULL) return false; mgString cwd(oldCWD); while (true) { if (cwd.endsWith("/")) location.format("%s%s", (const char*) cwd, fileName); else location.format("%s/%s", (const char*) cwd, fileName); struct stat filestat; if (0 == stat(location, &filestat)) return true; else { // remove last directory from cwd int slash = cwd.reverseFind(cwd.length(), '/'); if (slash != -1) cwd.deleteAt(slash, cwd.length()-slash); else return false; // no more directories. file not found. } } }