diff options
Diffstat (limited to 'lib/Support/Unix/Path.inc')
-rw-r--r-- | lib/Support/Unix/Path.inc | 217 |
1 files changed, 0 insertions, 217 deletions
diff --git a/lib/Support/Unix/Path.inc b/lib/Support/Unix/Path.inc index 6a5ebb8..57f02be 100644 --- a/lib/Support/Unix/Path.inc +++ b/lib/Support/Unix/Path.inc @@ -109,28 +109,6 @@ Path::isValid() const { return !path.empty(); } -bool -Path::isAbsolute(const char *NameStart, unsigned NameLen) { - assert(NameStart); - if (NameLen == 0) - return false; - return NameStart[0] == '/'; -} - -bool -Path::isAbsolute() const { - if (path.empty()) - return false; - return path[0] == '/'; -} - -Path -Path::GetRootDirectory() { - Path result; - result.set("/"); - return result; -} - Path Path::GetTemporaryDirectory(std::string *ErrMsg) { #if defined(HAVE_MKDTEMP) @@ -207,48 +185,6 @@ Path::GetTemporaryDirectory(std::string *ErrMsg) { #endif } -void -Path::GetSystemLibraryPaths(std::vector<sys::Path>& Paths) { -#ifdef LTDL_SHLIBPATH_VAR - char* env_var = getenv(LTDL_SHLIBPATH_VAR); - if (env_var != 0) { - getPathList(env_var,Paths); - } -#endif - // FIXME: Should this look at LD_LIBRARY_PATH too? - Paths.push_back(sys::Path("/usr/local/lib/")); - Paths.push_back(sys::Path("/usr/X11R6/lib/")); - Paths.push_back(sys::Path("/usr/lib/")); - Paths.push_back(sys::Path("/lib/")); -} - -void -Path::GetBitcodeLibraryPaths(std::vector<sys::Path>& Paths) { - char * env_var = getenv("LLVM_LIB_SEARCH_PATH"); - if (env_var != 0) { - getPathList(env_var,Paths); - } -#ifdef LLVM_LIBDIR - { - Path tmpPath; - if (tmpPath.set(LLVM_LIBDIR)) - if (tmpPath.canRead()) - Paths.push_back(tmpPath); - } -#endif - GetSystemLibraryPaths(Paths); -} - -Path -Path::GetUserHomeDirectory() { - const char* home = getenv("HOME"); - Path result; - if (home && result.set(home)) - return result; - result.set("/"); - return result; -} - Path Path::GetCurrentDirectory() { char pathname[MAXPATHLEN]; @@ -367,57 +303,6 @@ Path Path::GetMainExecutable(const char *argv0, void *MainAddr) { return Path(); } - -StringRef Path::getDirname() const { - return getDirnameCharSep(path, "/"); -} - -StringRef -Path::getBasename() const { - // Find the last slash - std::string::size_type slash = path.rfind('/'); - if (slash == std::string::npos) - slash = 0; - else - slash++; - - std::string::size_type dot = path.rfind('.'); - if (dot == std::string::npos || dot < slash) - return StringRef(path).substr(slash); - else - return StringRef(path).substr(slash, dot - slash); -} - -StringRef -Path::getSuffix() const { - // Find the last slash - std::string::size_type slash = path.rfind('/'); - if (slash == std::string::npos) - slash = 0; - else - slash++; - - std::string::size_type dot = path.rfind('.'); - if (dot == std::string::npos || dot < slash) - return StringRef(); - else - return StringRef(path).substr(dot + 1); -} - -bool Path::getMagicNumber(std::string &Magic, unsigned len) const { - assert(len < 1024 && "Request for magic string too long"); - char Buf[1025]; - int fd = ::open(path.c_str(), O_RDONLY); - if (fd < 0) - return false; - ssize_t bytes_read = ::read(fd, Buf, len); - ::close(fd); - if (ssize_t(len) != bytes_read) - return false; - Magic.assign(Buf, len); - return true; -} - bool Path::exists() const { return 0 == access(path.c_str(), F_OK ); @@ -476,28 +361,6 @@ Path::canExecute() const { return true; } -StringRef -Path::getLast() const { - // Find the last slash - size_t pos = path.rfind('/'); - - // Handle the corner cases - if (pos == std::string::npos) - return path; - - // If the last character is a slash - if (pos == path.length()-1) { - // Find the second to last slash - size_t pos2 = path.rfind('/', pos-1); - if (pos2 == std::string::npos) - return StringRef(path).substr(0,pos); - else - return StringRef(path).substr(pos2+1,pos-pos2-1); - } - // Return everything after the last slash - return StringRef(path).substr(pos+1); -} - const FileStatus * PathWithStatus::getFileStatus(bool update, std::string *ErrStr) const { if (!fsIsValid || update) { @@ -550,12 +413,6 @@ bool Path::makeWriteableOnDisk(std::string* ErrMsg) { return false; } -bool Path::makeExecutableOnDisk(std::string* ErrMsg) { - if (!AddPermissionBits(*this, 0111)) - return MakeErrMsg(ErrMsg, path + ": can't make file executable"); - return false; -} - bool Path::getDirectoryContents(std::set<Path>& result, std::string* ErrMsg) const { DIR* direntries = ::opendir(path.c_str()); @@ -682,16 +539,6 @@ Path::createDirectoryOnDisk( bool create_parents, std::string* ErrMsg ) { } bool -Path::createFileOnDisk(std::string* ErrMsg) { - // Create the file - int fd = ::creat(path.c_str(), S_IRUSR | S_IWUSR); - if (fd < 0) - return MakeErrMsg(ErrMsg, path + ": can't create file"); - ::close(fd); - return false; -} - -bool Path::createTemporaryFileOnDisk(bool reuse_current, std::string* ErrMsg) { // Make this into a unique file name if (makeUnique( reuse_current, ErrMsg )) @@ -774,53 +621,6 @@ Path::setStatusInfoOnDisk(const FileStatus &si, std::string *ErrStr) const { } bool -sys::CopyFile(const sys::Path &Dest, const sys::Path &Src, std::string* ErrMsg){ - int inFile = -1; - int outFile = -1; - inFile = ::open(Src.c_str(), O_RDONLY); - if (inFile == -1) - return MakeErrMsg(ErrMsg, Src.str() + - ": can't open source file to copy"); - - outFile = ::open(Dest.c_str(), O_WRONLY|O_CREAT, 0666); - if (outFile == -1) { - ::close(inFile); - return MakeErrMsg(ErrMsg, Dest.str() + - ": can't create destination file for copy"); - } - - char Buffer[16*1024]; - while (ssize_t Amt = ::read(inFile, Buffer, 16*1024)) { - if (Amt == -1) { - if (errno != EINTR && errno != EAGAIN) { - ::close(inFile); - ::close(outFile); - return MakeErrMsg(ErrMsg, Src.str()+": can't read source file"); - } - } else { - char *BufPtr = Buffer; - while (Amt) { - ssize_t AmtWritten = ::write(outFile, BufPtr, Amt); - if (AmtWritten == -1) { - if (errno != EINTR && errno != EAGAIN) { - ::close(inFile); - ::close(outFile); - return MakeErrMsg(ErrMsg, Dest.str() + - ": can't write destination file"); - } - } else { - Amt -= AmtWritten; - BufPtr += AmtWritten; - } - } - } - } - ::close(inFile); - ::close(outFile); - return false; -} - -bool Path::makeUnique(bool reuse_current, std::string* ErrMsg) { bool Exists; if (reuse_current && (fs::exists(path, Exists) || !Exists)) @@ -880,21 +680,4 @@ Path::makeUnique(bool reuse_current, std::string* ErrMsg) { #endif return false; } - -const char *Path::MapInFilePages(int FD, size_t FileSize, off_t Offset) { - int Flags = MAP_PRIVATE; -#ifdef MAP_FILE - Flags |= MAP_FILE; -#endif - void *BasePtr = ::mmap(0, FileSize, PROT_READ, Flags, FD, Offset); - if (BasePtr == MAP_FAILED) - return 0; - return (const char*)BasePtr; -} - -void Path::UnMapFilePages(const char *BasePtr, size_t FileSize) { - const void *Addr = static_cast<const void *>(BasePtr); - ::munmap(const_cast<void *>(Addr), FileSize); -} - } // end llvm namespace |