[libcxx-commits] [PATCH] D91177: [21/N] [libcxx] Implement is_absolute properly for windows

Martin Storsjö via Phabricator via libcxx-commits libcxx-commits at lists.llvm.org
Tue Feb 16 23:46:52 PST 2021


mstorsjo updated this revision to Diff 324206.
mstorsjo added a comment.

Rebased


CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D91177/new/

https://reviews.llvm.org/D91177

Files:
  libcxx/include/filesystem


Index: libcxx/include/filesystem
===================================================================
--- libcxx/include/filesystem
+++ libcxx/include/filesystem
@@ -1341,7 +1341,28 @@
   }
 
   _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(); }
 


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D91177.324206.patch
Type: text/x-patch
Size: 1200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20210217/f574ad18/attachment-0001.bin>


More information about the libcxx-commits mailing list