[libcxx-commits] [libcxx] 8a783e6 - [libcxx] Implement is_absolute properly for windows

Martin Storsjö via libcxx-commits libcxx-commits at lists.llvm.org
Wed Feb 17 09:42:18 PST 2021


Author: Martin Storsjö
Date: 2021-02-17T19:33:05+02:00
New Revision: 8a783e68452f646360d9902d2c2bc0e115d7bfa9

URL: https://github.com/llvm/llvm-project/commit/8a783e68452f646360d9902d2c2bc0e115d7bfa9
DIFF: https://github.com/llvm/llvm-project/commit/8a783e68452f646360d9902d2c2bc0e115d7bfa9.diff

LOG: [libcxx] Implement is_absolute properly for windows

Differential Revision: https://reviews.llvm.org/D91177

Added: 
    

Modified: 
    libcxx/include/filesystem

Removed: 
    


################################################################################
diff  --git a/libcxx/include/filesystem b/libcxx/include/filesystem
index 8d0b0f51cb4be..754fe36138300 100644
--- a/libcxx/include/filesystem
+++ b/libcxx/include/filesystem
@@ -1341,7 +1341,28 @@ public:
   }
 
   _LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
+#if defined(_LIBCPP_WIN32API)
+    __string_view __root_name_str = __root_name();
+    __string_view __root_dir = __root_directory();
+    if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
+      // A drive letter with no root directory is relative, e.g. x:example.
+      return !__root_dir.empty();
+    }
+    // If no root name, it's relative, e.g. \example is relative to the current drive
+    if (__root_name_str.empty())
+      return false;
+    if (__root_name_str.size() < 3)
+      return false;
+    // A server root name, like \\server, is always absolute
+    if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
+      return false;
+    if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
+      return false;
+    // Seems to be a server root name
+    return true;
+#else
     return has_root_directory();
+#endif
   }
   _LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
 


        


More information about the libcxx-commits mailing list