return result;
}
-std::string
-Path::GetDLLSuffix() {
- return "dll";
-}
-
static void getPathList(const char*path, std::vector<sys::Path>& Paths) {
const char* at = path;
const char* delim = strchr(at, ';');
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");
return path.substr(pos+1);
}
+void
+Path::getStatusInfo(StatusInfo& info) const {
+ WIN32_FILE_ATTRIBUTE_DATA fi;
+ if (!GetFileAttributesEx(path.c_str(), GetFileExInfoStandard, &fi))
+ ThrowError(std::string(path) + ": Can't get status: ");
+
+ info.fileSize = fi.nFileSizeHigh;
+ info.fileSize <<= 32;
+ info.fileSize += fi.nFileSizeLow;
+
+ info.mode = 0777; // Not applicable to Windows, so...
+ info.user = 9999; // Not applicable to Windows, so...
+ info.group = 9999; // Not applicable to Windows, so...
+
+ __int64 ft = *reinterpret_cast<__int64*>(&fi.ftLastWriteTime);
+ info.modTime.fromWin32Time(ft);
+
+ info.isDir = fi.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY;
+ if (info.isDir && path[path.length() - 1] != '/')
+ path += '/';
+ else if (!info.isDir && path[path.length() - 1] == '/')
+ path.erase(path.length() - 1);
+}
+
+void Path::makeReadable() {
+ // All files are readable on Windows (ignoring security attributes).
+}
+
+void Path::makeWriteable() {
+ DWORD attr = GetFileAttributes(path.c_str());
+
+ // If it doesn't exist, we're done.
+ if (attr == INVALID_FILE_ATTRIBUTES)
+ return;
+
+ if (attr & FILE_ATTRIBUTE_READONLY) {
+ if (!SetFileAttributes(path.c_str(), attr & ~FILE_ATTRIBUTE_READONLY))
+ ThrowError(std::string(path) + ": Can't make file writable: ");
+ }
+}
+
+void Path::makeExecutable() {
+ // All files are executable on Windows (ignoring security attributes).
+}
+
bool
Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
path = a_path;
FlipBackSlashes(path);
size_t last = a_path.size() -1;
- if (last != 0 && a_path[last] != '/')
+ if (a_path[last] != '/')
path += '/';
if (!isValid()) {
path = save.path;
}
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;
+}
+
}
}