# define _GLIBCXX_USE_CXX11_ABI 1
#endif
+#ifdef __CYGWIN__
+// Interpret "//x" as a root-name, not root-dir + filename
+# define SLASHSLASH_IS_ROOTNAME 1
+#endif
+
#include <filesystem>
#include <algorithm>
#include <bits/stl_uninitialized.h>
// look for root name or root directory
if (is_dir_sep(input[0]))
{
-#ifdef __CYGWIN__
+#if SLASHSLASH_IS_ROOTNAME
// look for root name, such as "//foo"
if (len > 2 && input[1] == input[0])
{
string_view_type sep;
if (has_filename())
sep = { &preferred_separator, 1 }; // need to add a separator
-#ifdef __CYGWIN__
+#if SLASHSLASH_IS_ROOTNAME
else if (_M_type() == _Type::_Root_name) // root-name with no root-dir
sep = { &preferred_separator, 1 }; // need to add a separator
#endif
capacity += __p._M_cmpts.size();
else if (!__p.empty() || !sep.empty())
capacity += 1;
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ ++capacity; // Need to insert root-directory after root-name
+#endif
if (orig_type == _Type::_Multi)
{
string_view_type s(_M_pathname.data(), orig_pathlen);
::new(output++) _Cmpt(s, orig_type, 0);
++_M_cmpts._M_impl->_M_size;
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ {
+ ::new(output++) _Cmpt(sep, _Type::_Root_dir,
+ orig_pathlen + sep.length());
+ ++_M_cmpts._M_impl->_M_size;
+ }
+#endif
}
if (__p._M_type() == _Type::_Multi)
basic_string_view<value_type> sep;
if (has_filename())
sep = { &preferred_separator, 1 }; // need to add a separator
-#ifdef __CYGWIN__
+#if SLASHSLASH_IS_ROOTNAME
else if (_M_type() == _Type::_Root_name) // root-name with no root-dir
sep = { &preferred_separator, 1 }; // need to add a separator
#endif
else if (!sep.empty())
++capacity;
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ ++capacity; // Need to insert root-directory after root-name
+#endif
+
__try
{
_M_cmpts.type(_Type::_Multi);
// Create single component from original path
::new(output++) _Cmpt(orig_pathname, orig_type, 0);
++_M_cmpts._M_impl->_M_size;
+
+#if SLASHSLASH_IS_ROOTNAME
+ if (!sep.empty() && orig_type == _Type::_Root_name)
+ {
+ ::new(output++) _Cmpt(sep, _Type::_Root_dir,
+ orig_pathlen + sep.length());
+ ++_M_cmpts._M_impl->_M_size;
+ }
+#endif
}
if (next != buf.begin())
{
// See if there's a filename or root-name at the end of the original path
// that we can add to.
- if (_M_type() == _Type::_Filename)
+ if (_M_type() == _Type::_Filename
+#if SLASHSLASH_IS_ROOTNAME
+ || _M_type() == _Type::_Root_name
+#endif
+ )
{
if (p._M_type() == _Type::_Filename)
{
&& _M_cmpts.back()._M_type() == _Type::_Filename)
orig_filenamelen = 0; // current path has empty filename at end
- // TODO handle "//rootname" + "foo" case for Cygwin.
-
int capacity = 0;
if (_M_type() == _Type::_Multi)
capacity += _M_cmpts.size();
ptr->_M_pathname.reserve(_M_pathname.length() + extra.length());
ptr->_M_pathname = _M_pathname;
ptr->_M_pathname += extra;
+
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ {
+ basic_string_view<value_type> s(p._M_pathname);
+ ::new(output++) _Cmpt(s.substr(extra.length(), 1),
+ _Type::_Root_dir, orig_pathlen + extra.length());
+ ++_M_cmpts._M_impl->_M_size;
+ }
+#endif
}
else if (orig_filenamelen == 0 && it != last)
{
{
basic_string_view<value_type> s = it->_M_pathname;
auto pos = orig_pathlen;
-#ifdef __CYGWIN__
+#if SLASHSLASH_IS_ROOTNAME
s.remove_prefix(2);
pos += 2;
#endif
{
// See if there's a filename or root-name at the end of the original path
// that we can add to.
- if (_M_type() == _Type::_Filename)
+ if (_M_type() == _Type::_Filename
+#if SLASHSLASH_IS_ROOTNAME
+ || _M_type() == _Type::_Root_name
+#endif
+ )
{
if (cmpt.str.length() == s.length())
{
&& _M_cmpts.back()._M_type() == _Type::_Filename)
orig_filenamelen = 0; // original path had empty filename at end
-
- // TODO handle "//rootname" + "foo" case for Cygwin.
-
std::array<_Parser::cmpt, 64> buf;
auto next = buf.begin();
if (is_dir_sep(s.back()))
++capacity;
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ ++capacity; // Need to insert root-directory after root-name
+#endif
+
__try
{
_M_cmpts.type(_Type::_Multi);
p->_M_pathname.reserve(orig_pathname.length() + extra.length());
p->_M_pathname = orig_pathname;
p->_M_pathname += extra;
+
+#if SLASHSLASH_IS_ROOTNAME
+ if (orig_type == _Type::_Root_name)
+ {
+ ::new(output++) _Cmpt(s.substr(extra.length(), 1),
+ _Type::_Root_dir, orig_pathlen + extra.length());
+ ++_M_cmpts._M_impl->_M_size;
+ }
+#endif
}
else if (orig_filenamelen == 0)
{
}
else if (is_dot(p))
ret /= path();
+#if SLASHSLASH_IS_ROOTNAME
+ else if (p._M_type() == _Type::_Root_dir)
+ ret += '/'; // using operator/=('/') would replace whole of ret
+#endif
else
ret /= p;
}