[llvm-commits] CVS: llvm/lib/System/Win32/Path.cpp
Jeff Cohen
jeffc at jolt-lang.org
Thu Dec 30 20:39:18 PST 2004
Changes in directory llvm/lib/System/Win32:
Path.cpp updated: 1.23 -> 1.24
---
Log message:
Bring win32/Path.cpp up to date with respect to Unix/Path.cpp
---
Diffs of the changes: (+104 -9)
Index: llvm/lib/System/Win32/Path.cpp
diff -u llvm/lib/System/Win32/Path.cpp:1.23 llvm/lib/System/Win32/Path.cpp:1.24
--- llvm/lib/System/Win32/Path.cpp:1.23 Thu Dec 23 20:38:34 2004
+++ llvm/lib/System/Win32/Path.cpp Thu Dec 30 22:39:07 2004
@@ -142,13 +142,6 @@
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("C:\\WINDOWS\\SYSTEM32\\"));
Paths.push_back(sys::Path("C:\\WINDOWS\\"));
}
@@ -172,11 +165,13 @@
Path
Path::GetLLVMDefaultConfigDir() {
+ // TODO: this isn't going to fly on Windows
return Path("/etc/llvm/");
}
Path
Path::GetUserHomeDirectory() {
+ // TODO: Typical Windows setup doesn't define HOME.
const char* home = getenv("HOME");
if (home) {
Path result;
@@ -288,7 +283,7 @@
info.fileSize <<= 32;
info.fileSize += fi.nFileSizeLow;
- info.mode = 0777; // Not applicable to Windows, so...
+ info.mode = fi.dwFileAttributes & FILE_ATTRIBUTE_READONLY ? 0555 : 0777;
info.user = 9999; // Not applicable to Windows, so...
info.group = 9999; // Not applicable to Windows, so...
@@ -302,6 +297,22 @@
path.erase(path.length() - 1);
}
+static bool AddPermissionBits(const std::string& Filename, int bits) {
+ DWORD attr = GetFileAttributes(Filename.c_str());
+
+ // If it doesn't exist, we're done.
+ if (attr == INVALID_FILE_ATTRIBUTES)
+ return false;
+
+ // The best we can do to interpret Unix permission bits is to use
+ // the owner writable bit.
+ if ((attr & FILE_ATTRIBUTE_READONLY) && (bits & 0200)) {
+ if (!SetFileAttributes(Filename.c_str(), attr & ~FILE_ATTRIBUTE_READONLY))
+ ThrowError(Filename + ": SetFileAttributes: ");
+ }
+ return true;
+}
+
void Path::makeReadable() {
// All files are readable on Windows (ignoring security attributes).
}
@@ -324,6 +335,35 @@
}
bool
+Path::getDirectoryContents(std::set<Path>& result) const {
+ if (!isDirectory())
+ return false;
+
+ result.clear();
+ WIN32_FIND_DATA fd;
+ HANDLE h = FindFirstFile(path.c_str(), &fd);
+ if (h == INVALID_HANDLE_VALUE) {
+ if (GetLastError() == ERROR_NO_MORE_FILES)
+ return true; // not really an error, now is it?
+ ThrowError(path + ": Can't read directory: ");
+ }
+
+ do {
+ if (fd.cFileName[0] == '.')
+ continue;
+ Path aPath(path + &fd.cFileName[0]);
+ if (fd.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY)
+ aPath.path += "/";
+ result.insert(aPath);
+ } while (FindNextFile(h, &fd));
+
+ CloseHandle(h);
+ if (GetLastError() != ERROR_NO_MORE_FILES)
+ ThrowError(path + ": Can't read directory: ");
+ return true;
+}
+
+bool
Path::setDirectory(const std::string& a_path) {
if (a_path.size() == 0)
return false;
@@ -575,13 +615,68 @@
return true;
}
+bool
+Path::renameFile(const Path& newName) {
+ if (!isFile()) return false;
+ if (!MoveFile(path.c_str(), newName.c_str()))
+ ThrowError("Can't move '" + path +
+ "' to '" + newName.path + "': ");
+ return true;
+}
+
+bool
+Path::setStatusInfo(const StatusInfo& si) const {
+ if (!isFile()) return false;
+
+ HANDLE h = CreateFile(path.c_str(),
+ FILE_READ_ATTRIBUTES | FILE_WRITE_ATTRIBUTES,
+ FILE_SHARE_READ | FILE_SHARE_WRITE | FILE_SHARE_DELETE,
+ NULL,
+ OPEN_EXISTING,
+ FILE_ATTRIBUTE_NORMAL,
+ NULL);
+ if (h == INVALID_HANDLE_VALUE)
+ return false;
+
+ BY_HANDLE_FILE_INFORMATION bhfi;
+ if (!GetFileInformationByHandle(h, &bhfi)) {
+ CloseHandle(h);
+ ThrowError(path + ": GetFileInformationByHandle: ");
+ }
+
+ FILETIME ft;
+ (uint64_t&)ft = si.modTime.toWin32Time();
+ BOOL ret = SetFileTime(h, NULL, &ft, &ft);
+ CloseHandle(h);
+ if (!ret)
+ ThrowError(path + ": SetFileTime: ");
+
+ // Best we can do with Unix permission bits is to interpret the owner
+ // writable bit.
+ if (si.mode & 0200) {
+ if (bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY) {
+ if (!SetFileAttributes(path.c_str(),
+ bhfi.dwFileAttributes & ~FILE_ATTRIBUTE_READONLY))
+ ThrowError(path + ": SetFileAttributes: ");
+ }
+ } else {
+ if (!(bhfi.dwFileAttributes & FILE_ATTRIBUTE_READONLY)) {
+ if (!SetFileAttributes(path.c_str(),
+ bhfi.dwFileAttributes | FILE_ATTRIBUTE_READONLY))
+ ThrowError(path + ": SetFileAttributes: ");
+ }
+ }
+
+ return true;
+}
+
void
sys::CopyFile(const sys::Path &Dest, const sys::Path &Src) {
// Can't use CopyFile macro defined in Windows.h because it would mess up the
// above line. We use the expansion it would have in a non-UNICODE build.
if (!::CopyFileA(Src.c_str(), Dest.c_str(), false))
ThrowError("Can't copy '" + Src.toString() +
- "' to '" + Dest.toString() + "'");
+ "' to '" + Dest.toString() + "': ");
}
void
More information about the llvm-commits
mailing list