[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 Nov 10 08:45:56 PST 2020


mstorsjo created this revision.
mstorsjo added a reviewer: libc++.
Herald added a project: libc++.
Herald added 1 blocking reviewer(s): libc++.
mstorsjo requested review of this revision.

Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D91177

Files:
  libcxx/include/filesystem


Index: libcxx/include/filesystem
===================================================================
--- libcxx/include/filesystem
+++ libcxx/include/filesystem
@@ -1338,7 +1338,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.304213.patch
Type: text/x-patch
Size: 1200 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/libcxx-commits/attachments/20201110/0c3fb0ba/attachment.bin>


More information about the libcxx-commits mailing list