| 1108 | } |
| 1109 | |
| 1110 | wstring prepare_basedir(const wchar_t *path) |
| 1111 | { |
| 1112 | wstring basedir = path; |
| 1113 | |
| 1114 | // strip any trailing backslashes |
| 1115 | while (basedir.size() > 0 && |
| 1116 | basedir[basedir.size() - 1] == '\\') |
| 1117 | basedir.erase(basedir.size() - 1); |
| 1118 | |
| 1119 | wstring holder = basedir; |
| 1120 | |
| 1121 | WCHAR drive[_MAX_DRIVE] = { 0 }; |
| 1122 | WCHAR dir[_MAX_DIR]; |
| 1123 | WCHAR fname[_MAX_FNAME]; |
| 1124 | WCHAR ext[_MAX_EXT]; |
| 1125 | |
| 1126 | const auto err = _wsplitpath_s(holder.c_str(), drive, dir, fname, ext); |
| 1127 | |
| 1128 | const bool unc = !err && wcslen(drive) == 0; |
| 1129 | |
| 1130 | // for UNC paths, need to eat all leading \ for them to work |
| 1131 | while (unc && holder.length() > 1 && holder[0] == '\\') { |
| 1132 | holder = holder.c_str() + 1; |
| 1133 | } |
| 1134 | |
| 1135 | basedir = !unc ? |
| 1136 | L"\\\\?\\" : L"\\\\?\\UNC\\"; // this prefix enables up to 32K long file paths on NTFS |
| 1137 | |
| 1138 | basedir += holder; |
| 1139 | |
| 1140 | return basedir; |
| 1141 | } |
| 1142 | |
| 1143 | #endif // __WIN32 |
no test coverage detected