summaryrefslogtreecommitdiffstats
path: root/llvm/lib/Support/Windows
diff options
context:
space:
mode:
authorBenjamin Kramer <benny.kra@googlemail.com>2011-08-20 21:36:38 +0000
committerBenjamin Kramer <benny.kra@googlemail.com>2011-08-20 21:36:38 +0000
commit58994ec9b9191f8871800212c41d2e9d68bc6867 (patch)
tree69798ec2dbb61aea47a457903773afb17177f713 /llvm/lib/Support/Windows
parenta8f99ba749e266a6b20bbefdfbc5e5b31b9aa059 (diff)
downloadbcm5719-llvm-58994ec9b9191f8871800212c41d2e9d68bc6867.tar.gz
bcm5719-llvm-58994ec9b9191f8871800212c41d2e9d68bc6867.zip
PathV2: Handle more reserved filenames on windows.
Patch by Aaron Ballman! llvm-svn: 138213
Diffstat (limited to 'llvm/lib/Support/Windows')
-rw-r--r--llvm/lib/Support/Windows/PathV2.inc26
1 files changed, 24 insertions, 2 deletions
diff --git a/llvm/lib/Support/Windows/PathV2.inc b/llvm/lib/Support/Windows/PathV2.inc
index e34d74a23ba..bc597b2dcc8 100644
--- a/llvm/lib/Support/Windows/PathV2.inc
+++ b/llvm/lib/Support/Windows/PathV2.inc
@@ -445,13 +445,35 @@ error_code file_size(const Twine &path, uint64_t &result) {
return success;
}
+static bool isReservedName(StringRef path) {
+ // This list of reserved names comes from MSDN, at:
+ // http://msdn.microsoft.com/en-us/library/aa365247%28v=vs.85%29.aspx
+ static const char *sReservedNames[] = { "nul", "con", "prn", "aux",
+ "com1", "com2", "com3", "com4", "com5", "com6",
+ "com7", "com8", "com9", "lpt1", "lpt2", "lpt3",
+ "lpt4", "lpt5", "lpt6", "lpt7", "lpt8", "lpt9" };
+
+ // First, check to see if this is a device namespace, which always
+ // starts with \\.\, since device namespaces are not legal file paths.
+ if (path.startswith("\\\\.\\"))
+ return true;
+
+ // Then compare against the list of ancient reserved names
+ for (size_t i = 0; i < sizeof(sReservedNames) / sizeof(const char *); ++i) {
+ if (path.equals_lower(sReservedNames[i]))
+ return true;
+ }
+
+ // The path isn't what we consider reserved.
+ return false;
+}
+
error_code status(const Twine &path, file_status &result) {
SmallString<128> path_storage;
SmallVector<wchar_t, 128> path_utf16;
StringRef path8 = path.toStringRef(path_storage);
- // FIXME: We should detect as many "special file name" as possible.
- if (path8.compare_lower("nul") == 0) {
+ if (isReservedName(path8)) {
result = file_status(file_type::character_file);
return success;
}
OpenPOWER on IntegriCloud