if (env_var != 0) {
getPathList(env_var,Paths);
}
-#ifdef LLVMGCCDIR
- {
- Path tmpPath(std::string(LLVMGCCDIR) + "bytecode-libs/");
- if (tmpPath.readable())
- Paths.push_back(tmpPath);
- }
-#endif
#ifdef LLVM_LIBDIR
{
Path tmpPath;
return Path("/etc/llvm/");
}
-Path
-Path::GetLLVMConfigDir() {
- return GetLLVMDefaultConfigDir();
-}
-
Path
Path::GetUserHomeDirectory() {
const char* home = getenv("HOME");
}
bool
-Path::destroyDirectory(bool remove_contents) {
+Path::destroyDirectory(bool remove_contents) const {
// Make sure we're dealing with a directory
if (!isDirectory()) return false;
}
bool
-Path::destroyFile() {
+Path::destroyFile() const {
if (!isFile()) return false;
DWORD attr = GetFileAttributes(path.c_str());
return true;
}
+bool Path::getMagicNumber(std::string& Magic, unsigned len) const {
+ if (!isFile())
+ return false;
+ assert(len < 1024 && "Request for magic string too long");
+ char* buf = (char*) alloca(1 + len);
+ std::ofstream ofs(path.c_str(),std::ofstream::in);
+ if (!ofs.is_open())
+ return false;
+ std::ifstream ifs(path.c_str());
+ if (!ifs.is_open())
+ return false;
+ ifs.read(buf, len);
+ ofs.close();
+ ifs.close();
+ buf[len] = '\0';
+ Magic = buf;
+ return true;
+}
+
+void
+sys::CopyFile(const sys::Path &Dest, const sys::Path &Src) {
+ if (!::CopyFile(Src.c_str(), Dest.c_str(), false))
+ ThrowError("Can't copy '" + Src.toString() +
+ "' to '" + Dest.toString() + "'");
+}
+
+void
+Path::makeUnique( bool reuse_current ) {
+ if (reuse_current && !exists())
+ return; // File doesn't exist already, just use it!
+
+ Path dir (*this);
+ dir.elideFile();
+ std::string fname = this->getLast();
+
+ char newName[MAX_PATH + 1];
+ if (!GetTempFileName(dir.c_str(), fname.c_str(), 0, newName))
+ ThrowError("Cannot make unique filename for '" + path + "'");
+
+ path = newName;
+}
+
+bool
+Path::createTemporaryFile(bool reuse_current) {
+ // Make sure we're dealing with a file
+ if (!isFile())
+ return false;
+
+ // Make this into a unique file name
+ makeUnique( reuse_current );
+ return true;
+}
+
}
}