Skip to content

Commit 8a783e6

Browse files
committed
[libcxx] Implement is_absolute properly for windows
Differential Revision: https://reviews.llvm.org/D91177
1 parent f0ec9f1 commit 8a783e6

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

libcxx/include/filesystem

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,7 +1341,28 @@ public:
13411341
}
13421342

13431343
_LIBCPP_INLINE_VISIBILITY bool is_absolute() const {
1344+
#if defined(_LIBCPP_WIN32API)
1345+
__string_view __root_name_str = __root_name();
1346+
__string_view __root_dir = __root_directory();
1347+
if (__root_name_str.size() == 2 && __root_name_str[1] == ':') {
1348+
// A drive letter with no root directory is relative, e.g. x:example.
1349+
return !__root_dir.empty();
1350+
}
1351+
// If no root name, it's relative, e.g. \example is relative to the current drive
1352+
if (__root_name_str.empty())
1353+
return false;
1354+
if (__root_name_str.size() < 3)
1355+
return false;
1356+
// A server root name, like \\server, is always absolute
1357+
if (__root_name_str[0] != '/' && __root_name_str[0] != '\\')
1358+
return false;
1359+
if (__root_name_str[1] != '/' && __root_name_str[1] != '\\')
1360+
return false;
1361+
// Seems to be a server root name
1362+
return true;
1363+
#else
13441364
return has_root_directory();
1365+
#endif
13451366
}
13461367
_LIBCPP_INLINE_VISIBILITY bool is_relative() const { return !is_absolute(); }
13471368

0 commit comments

Comments
 (0)