Merge branch 'upstream-KWSys' into update-kwsys

* upstream-KWSys:
  KWSys 2017-04-19 (9f6ffaff)
This commit is contained in:
Brad King committed 2017-04-19 08:02:06 -04:00
commit 697a5d64d8
8 files changed
+194 -188

No files matched your search

+1
View File
@@ -69,6 +69,7 @@
CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR) CMAKE_MINIMUM_REQUIRED(VERSION 2.6.3 FATAL_ERROR)
FOREACH(p FOREACH(p
CMP0025 # CMake 3.0, Compiler id for Apple Clang is now AppleClang. CMP0025 # CMake 3.0, Compiler id for Apple Clang is now AppleClang.
CMP0048 # CMake 3.0, Let the project command manage version variables.
CMP0056 # CMake 3.2, Honor link flags in try_compile() source-file signature. CMP0056 # CMake 3.2, Honor link flags in try_compile() source-file signature.
CMP0063 # CMake 3.3, Honor visibility properties for all target types. CMP0063 # CMake 3.3, Honor visibility properties for all target types.
) )
+11
View File
@@ -59,6 +59,17 @@ public:
static std::string ToNarrow(const std::wstring& str); static std::string ToNarrow(const std::wstring& str);
static std::string ToNarrow(const wchar_t* str); static std::string ToNarrow(const wchar_t* str);
#if defined(_WIN32)
/**
* Convert the path to an extended length path to avoid MAX_PATH length
* limitations on Windows. If the input is a local path the result will be
* prefixed with \\?\; if the input is instead a network path, the result
* will be prefixed with \\?\UNC\. All output will also be converted to
* absolute paths with Windows-style backslashes.
**/
static std::wstring ToWindowsExtendedPath(std::string const&);
#endif
#endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING #endif // @KWSYS_NAMESPACE@_STL_HAS_WSTRING
}; // class Encoding }; // class Encoding
+58
View File
@@ -29,6 +29,7 @@
#if defined(_WIN32) #if defined(_WIN32)
#include <windows.h> #include <windows.h>
#include <ctype.h>
#include <shellapi.h> #include <shellapi.h>
#endif #endif
@@ -214,6 +215,63 @@ std::string Encoding::ToNarrow(const wchar_t* wcstr)
} }
return str; return str;
} }
#if defined(_WIN32)
// Convert local paths to UNC style paths
std::wstring Encoding::ToWindowsExtendedPath(std::string const& source)
{
std::wstring wsource = Encoding::ToWide(source);
// Resolve any relative paths
DWORD wfull_len;
/* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
* won't return a large enough buffer size if the input is too small */
wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
std::vector<wchar_t> wfull(wfull_len);
GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
/* This should get the correct size without any extra padding from the
* previous size workaround. */
wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
if (wfull_len >= 2 && isalpha(wfull[0]) &&
wfull[1] == L':') { /* C:\Foo\bar\FooBar.txt */
return L"\\\\?\\" + std::wstring(&wfull[0]);
} else if (wfull_len >= 2 && wfull[0] == L'\\' &&
wfull[1] == L'\\') { /* Starts with \\ */
if (wfull_len >= 4 && wfull[2] == L'?' &&
wfull[3] == L'\\') { /* Starts with \\?\ */
if (wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
wfull[6] == L'C' &&
wfull[7] == L'\\') { /* \\?\UNC\Foo\bar\FooBar.txt */
return std::wstring(&wfull[0]);
} else if (wfull_len >= 6 && isalpha(wfull[4]) &&
wfull[5] == L':') { /* \\?\C:\Foo\bar\FooBar.txt */
return std::wstring(&wfull[0]);
} else if (wfull_len >= 5) { /* \\?\Foo\bar\FooBar.txt */
return L"\\\\?\\UNC\\" + std::wstring(&wfull[4]);
}
} else if (wfull_len >= 4 && wfull[2] == L'.' &&
wfull[3] == L'\\') { /* Starts with \\.\ a device name */
if (wfull_len >= 6 && isalpha(wfull[4]) &&
wfull[5] == L':') { /* \\.\C:\Foo\bar\FooBar.txt */
return L"\\\\?\\" + std::wstring(&wfull[4]);
} else if (wfull_len >=
5) { /* \\.\Foo\bar\ Device name is left unchanged */
return std::wstring(&wfull[0]);
}
} else if (wfull_len >= 3) { /* \\Foo\bar\FooBar.txt */
return L"\\\\?\\UNC\\" + std::wstring(&wfull[2]);
}
}
// If this case has been reached, then the path is invalid. Leave it
// unchanged
return Encoding::ToWide(source);
}
#endif
#endif // KWSYS_STL_HAS_WSTRING #endif // KWSYS_STL_HAS_WSTRING
} // namespace KWSYS_NAMESPACE } // namespace KWSYS_NAMESPACE
+2 -2
View File
@@ -33,7 +33,7 @@ public:
typedef std::basic_filebuf<CharType, Traits> my_base_type; typedef std::basic_filebuf<CharType, Traits> my_base_type;
basic_filebuf* open(char const* s, std::ios_base::openmode mode) basic_filebuf* open(char const* s, std::ios_base::openmode mode)
{ {
const std::wstring wstr = Encoding::ToWide(s); const std::wstring wstr = Encoding::ToWindowsExtendedPath(s);
return static_cast<basic_filebuf*>(my_base_type::open(wstr.c_str(), mode)); return static_cast<basic_filebuf*>(my_base_type::open(wstr.c_str(), mode));
} }
#endif #endif
@@ -93,7 +93,7 @@ public:
#if defined(_MSC_VER) #if defined(_MSC_VER)
const bool success = buf_->open(file_name, mode) != 0; const bool success = buf_->open(file_name, mode) != 0;
#else #else
const std::wstring wstr = Encoding::ToWide(file_name); const std::wstring wstr = Encoding::ToWindowsExtendedPath(file_name);
bool success = false; bool success = false;
std::wstring cmode = getcmode(mode); std::wstring cmode = getcmode(mode);
file_ = _wfopen(wstr.c_str(), cmode.c_str()); file_ = _wfopen(wstr.c_str(), cmode.c_str());
+38 -100
View File
@@ -216,12 +216,12 @@ static time_t windows_filetime_to_posix_time(const FILETIME& ft)
inline int Mkdir(const std::string& dir) inline int Mkdir(const std::string& dir)
{ {
return _wmkdir( return _wmkdir(
KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); KWSYS_NAMESPACE::Encoding::ToWindowsExtendedPath(dir).c_str());
} }
inline int Rmdir(const std::string& dir) inline int Rmdir(const std::string& dir)
{ {
return _wrmdir( return _wrmdir(
KWSYS_NAMESPACE::SystemTools::ConvertToWindowsExtendedPath(dir).c_str()); KWSYS_NAMESPACE::Encoding::ToWindowsExtendedPath(dir).c_str());
} }
inline const char* Getcwd(char* buf, unsigned int len) inline const char* Getcwd(char* buf, unsigned int len)
{ {
@@ -745,7 +745,7 @@ const char* SystemTools::GetExecutableExtension()
FILE* SystemTools::Fopen(const std::string& file, const char* mode) FILE* SystemTools::Fopen(const std::string& file, const char* mode)
{ {
#ifdef _WIN32 #ifdef _WIN32
return _wfopen(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), return _wfopen(Encoding::ToWindowsExtendedPath(file).c_str(),
Encoding::ToWide(mode).c_str()); Encoding::ToWide(mode).c_str());
#else #else
return fopen(file.c_str(), mode); return fopen(file.c_str(), mode);
@@ -1159,8 +1159,7 @@ bool SystemTools::PathExists(const std::string& path)
struct stat st; struct stat st;
return lstat(path.c_str(), &st) == 0; return lstat(path.c_str(), &st) == 0;
#elif defined(_WIN32) #elif defined(_WIN32)
return (GetFileAttributesW( return (GetFileAttributesW(Encoding::ToWindowsExtendedPath(path).c_str()) !=
SystemTools::ConvertToWindowsExtendedPath(path).c_str()) !=
INVALID_FILE_ATTRIBUTES); INVALID_FILE_ATTRIBUTES);
#else #else
struct stat st; struct stat st;
@@ -1191,9 +1190,9 @@ bool SystemTools::FileExists(const std::string& filename)
} }
return access(filename.c_str(), R_OK) == 0; return access(filename.c_str(), R_OK) == 0;
#elif defined(_WIN32) #elif defined(_WIN32)
return (GetFileAttributesW( return (
SystemTools::ConvertToWindowsExtendedPath(filename).c_str()) != GetFileAttributesW(Encoding::ToWindowsExtendedPath(filename).c_str()) !=
INVALID_FILE_ATTRIBUTES); INVALID_FILE_ATTRIBUTES);
#else #else
// SCO OpenServer 5.0.7/3.2's command has 711 permission. // SCO OpenServer 5.0.7/3.2's command has 711 permission.
#if defined(_SCO_DS) #if defined(_SCO_DS)
@@ -1249,7 +1248,7 @@ bool SystemTools::TestFileAccess(const std::string& filename,
permissions &= ~TEST_FILE_EXECUTE; permissions &= ~TEST_FILE_EXECUTE;
permissions |= TEST_FILE_READ; permissions |= TEST_FILE_READ;
} }
return _waccess(SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), return _waccess(Encoding::ToWindowsExtendedPath(filename).c_str(),
permissions) == 0; permissions) == 0;
#else #else
return access(filename.c_str(), permissions) == 0; return access(filename.c_str(), permissions) == 0;
@@ -1274,7 +1273,7 @@ int SystemTools::Stat(const std::string& path, SystemTools::Stat_t* buf)
return -1; return -1;
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
// Ideally we should use ConvertToWindowsExtendedPath to support // Ideally we should use Encoding::ToWindowsExtendedPath to support
// long paths, but _wstat64 rejects paths with '?' in them, thinking // long paths, but _wstat64 rejects paths with '?' in them, thinking
// they are wildcards. // they are wildcards.
std::wstring const& wpath = Encoding::ToWide(path); std::wstring const& wpath = Encoding::ToWide(path);
@@ -1324,10 +1323,9 @@ bool SystemTools::Touch(const std::string& filename, bool create)
} }
} }
#if defined(_WIN32) && !defined(__CYGWIN__) #if defined(_WIN32) && !defined(__CYGWIN__)
HANDLE h = HANDLE h = CreateFileW(Encoding::ToWindowsExtendedPath(filename).c_str(),
CreateFileW(SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0,
FILE_WRITE_ATTRIBUTES, FILE_SHARE_WRITE, 0, OPEN_EXISTING, OPEN_EXISTING, FILE_FLAG_BACKUP_SEMANTICS, 0);
FILE_FLAG_BACKUP_SEMANTICS, 0);
if (!h) { if (!h) {
return false; return false;
} }
@@ -1425,14 +1423,12 @@ bool SystemTools::FileTimeCompare(const std::string& f1, const std::string& f2,
// Windows version. Get the modification time from extended file attributes. // Windows version. Get the modification time from extended file attributes.
WIN32_FILE_ATTRIBUTE_DATA f1d; WIN32_FILE_ATTRIBUTE_DATA f1d;
WIN32_FILE_ATTRIBUTE_DATA f2d; WIN32_FILE_ATTRIBUTE_DATA f2d;
if (!GetFileAttributesExW( if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f1).c_str(),
SystemTools::ConvertToWindowsExtendedPath(f1).c_str(), GetFileExInfoStandard, &f1d)) {
GetFileExInfoStandard, &f1d)) {
return false; return false;
} }
if (!GetFileAttributesExW( if (!GetFileAttributesExW(Encoding::ToWindowsExtendedPath(f2).c_str(),
SystemTools::ConvertToWindowsExtendedPath(f2).c_str(), GetFileExInfoStandard, &f2d)) {
GetFileExInfoStandard, &f2d)) {
return false; return false;
} }
@@ -1960,59 +1956,10 @@ void SystemTools::ConvertToUnixSlashes(std::string& path)
} }
#ifdef _WIN32 #ifdef _WIN32
// Convert local paths to UNC style paths
std::wstring SystemTools::ConvertToWindowsExtendedPath( std::wstring SystemTools::ConvertToWindowsExtendedPath(
const std::string& source) const std::string& source)
{ {
std::wstring wsource = Encoding::ToWide(source); return Encoding::ToWindowsExtendedPath(source);
// Resolve any relative paths
DWORD wfull_len;
/* The +3 is a workaround for a bug in some versions of GetFullPathNameW that
* won't return a large enough buffer size if the input is too small */
wfull_len = GetFullPathNameW(wsource.c_str(), 0, NULL, NULL) + 3;
std::vector<wchar_t> wfull(wfull_len);
GetFullPathNameW(wsource.c_str(), wfull_len, &wfull[0], NULL);
/* This should get the correct size without any extra padding from the
* previous size workaround. */
wfull_len = static_cast<DWORD>(wcslen(&wfull[0]));
if (wfull_len >= 2 && isalpha(wfull[0]) &&
wfull[1] == L':') { /* C:\Foo\bar\FooBar.txt */
return L"\\\\?\\" + std::wstring(&wfull[0]);
} else if (wfull_len >= 2 && wfull[0] == L'\\' &&
wfull[1] == L'\\') { /* Starts with \\ */
if (wfull_len >= 4 && wfull[2] == L'?' &&
wfull[3] == L'\\') { /* Starts with \\?\ */
if (wfull_len >= 8 && wfull[4] == L'U' && wfull[5] == L'N' &&
wfull[6] == L'C' &&
wfull[7] == L'\\') { /* \\?\UNC\Foo\bar\FooBar.txt */
return std::wstring(&wfull[0]);
} else if (wfull_len >= 6 && isalpha(wfull[4]) &&
wfull[5] == L':') { /* \\?\C:\Foo\bar\FooBar.txt */
return std::wstring(&wfull[0]);
} else if (wfull_len >= 5) { /* \\?\Foo\bar\FooBar.txt */
return L"\\\\?\\UNC\\" + std::wstring(&wfull[4]);
}
} else if (wfull_len >= 4 && wfull[2] == L'.' &&
wfull[3] == L'\\') { /* Starts with \\.\ a device name */
if (wfull_len >= 6 && isalpha(wfull[4]) &&
wfull[5] == L':') { /* \\.\C:\Foo\bar\FooBar.txt */
return L"\\\\?\\" + std::wstring(&wfull[4]);
} else if (wfull_len >=
5) { /* \\.\Foo\bar\ Device name is left unchanged */
return std::wstring(&wfull[0]);
}
} else if (wfull_len >= 3) { /* \\Foo\bar\FooBar.txt */
return L"\\\\?\\UNC\\" + std::wstring(&wfull[2]);
}
}
// If this case has been reached, then the path is invalid. Leave it
// unchanged
return Encoding::ToWide(source);
} }
#endif #endif
@@ -2129,15 +2076,14 @@ bool SystemTools::FilesDiffer(const std::string& source,
#if defined(_WIN32) #if defined(_WIN32)
WIN32_FILE_ATTRIBUTE_DATA statSource; WIN32_FILE_ATTRIBUTE_DATA statSource;
if (GetFileAttributesExW( if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(source).c_str(),
SystemTools::ConvertToWindowsExtendedPath(source).c_str(), GetFileExInfoStandard, &statSource) == 0) {
GetFileExInfoStandard, &statSource) == 0) {
return true; return true;
} }
WIN32_FILE_ATTRIBUTE_DATA statDestination; WIN32_FILE_ATTRIBUTE_DATA statDestination;
if (GetFileAttributesExW( if (GetFileAttributesExW(
SystemTools::ConvertToWindowsExtendedPath(destination).c_str(), Encoding::ToWindowsExtendedPath(destination).c_str(),
GetFileExInfoStandard, &statDestination) == 0) { GetFileExInfoStandard, &statDestination) == 0) {
return true; return true;
} }
@@ -2261,8 +2207,7 @@ bool SystemTools::CopyFileAlways(const std::string& source,
// Open files // Open files
#if defined(_WIN32) #if defined(_WIN32)
kwsys::ifstream fin( kwsys::ifstream fin(
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source)) Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)).c_str(),
.c_str(),
std::ios::in | std::ios::binary); std::ios::in | std::ios::binary);
#else #else
kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary); kwsys::ifstream fin(source.c_str(), std::ios::in | std::ios::binary);
@@ -2279,8 +2224,7 @@ bool SystemTools::CopyFileAlways(const std::string& source,
#if defined(_WIN32) #if defined(_WIN32)
kwsys::ofstream fout( kwsys::ofstream fout(
Encoding::ToNarrow( Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(real_destination))
SystemTools::ConvertToWindowsExtendedPath(real_destination))
.c_str(), .c_str(),
std::ios::out | std::ios::trunc | std::ios::binary); std::ios::out | std::ios::trunc | std::ios::binary);
#else #else
@@ -2345,8 +2289,7 @@ bool SystemTools::CopyADirectory(const std::string& source,
{ {
Directory dir; Directory dir;
#ifdef _WIN32 #ifdef _WIN32
dir.Load( dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)));
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source)));
#else #else
dir.Load(source); dir.Load(source);
#endif #endif
@@ -2384,9 +2327,8 @@ unsigned long SystemTools::FileLength(const std::string& filename)
unsigned long length = 0; unsigned long length = 0;
#ifdef _WIN32 #ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA fs; WIN32_FILE_ATTRIBUTE_DATA fs;
if (GetFileAttributesExW( if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), GetFileExInfoStandard, &fs) != 0) {
GetFileExInfoStandard, &fs) != 0) {
/* To support the full 64-bit file size, use fs.nFileSizeHigh /* To support the full 64-bit file size, use fs.nFileSizeHigh
* and fs.nFileSizeLow to construct the 64 bit size * and fs.nFileSizeLow to construct the 64 bit size
@@ -2420,9 +2362,8 @@ long int SystemTools::ModifiedTime(const std::string& filename)
long int mt = 0; long int mt = 0;
#ifdef _WIN32 #ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA fs; WIN32_FILE_ATTRIBUTE_DATA fs;
if (GetFileAttributesExW( if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), GetFileExInfoStandard, &fs) != 0) {
GetFileExInfoStandard, &fs) != 0) {
mt = windows_filetime_to_posix_time(fs.ftLastWriteTime); mt = windows_filetime_to_posix_time(fs.ftLastWriteTime);
} }
#else #else
@@ -2440,9 +2381,8 @@ long int SystemTools::CreationTime(const std::string& filename)
long int ct = 0; long int ct = 0;
#ifdef _WIN32 #ifdef _WIN32
WIN32_FILE_ATTRIBUTE_DATA fs; WIN32_FILE_ATTRIBUTE_DATA fs;
if (GetFileAttributesExW( if (GetFileAttributesExW(Encoding::ToWindowsExtendedPath(filename).c_str(),
SystemTools::ConvertToWindowsExtendedPath(filename).c_str(), GetFileExInfoStandard, &fs) != 0) {
GetFileExInfoStandard, &fs) != 0) {
ct = windows_filetime_to_posix_time(fs.ftCreationTime); ct = windows_filetime_to_posix_time(fs.ftCreationTime);
} }
#else #else
@@ -2656,7 +2596,7 @@ static bool DeleteJunction(const std::wstring& source)
bool SystemTools::RemoveFile(const std::string& source) bool SystemTools::RemoveFile(const std::string& source)
{ {
#ifdef _WIN32 #ifdef _WIN32
std::wstring const& ws = SystemTools::ConvertToWindowsExtendedPath(source); std::wstring const& ws = Encoding::ToWindowsExtendedPath(source);
if (DeleteFileW(ws.c_str())) { if (DeleteFileW(ws.c_str())) {
return true; return true;
} }
@@ -2706,8 +2646,7 @@ bool SystemTools::RemoveADirectory(const std::string& source)
Directory dir; Directory dir;
#ifdef _WIN32 #ifdef _WIN32
dir.Load( dir.Load(Encoding::ToNarrow(Encoding::ToWindowsExtendedPath(source)));
Encoding::ToNarrow(SystemTools::ConvertToWindowsExtendedPath(source)));
#else #else
dir.Load(source); dir.Load(source);
#endif #endif
@@ -3064,8 +3003,8 @@ bool SystemTools::FileIsDirectory(const std::string& inName)
// Now check the file node type. // Now check the file node type.
#if defined(_WIN32) #if defined(_WIN32)
DWORD attr = GetFileAttributesW( DWORD attr =
SystemTools::ConvertToWindowsExtendedPath(name).c_str()); GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str());
if (attr != INVALID_FILE_ATTRIBUTES) { if (attr != INVALID_FILE_ATTRIBUTES) {
return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0; return (attr & FILE_ATTRIBUTE_DIRECTORY) != 0;
#else #else
@@ -3081,8 +3020,8 @@ bool SystemTools::FileIsDirectory(const std::string& inName)
bool SystemTools::FileIsSymlink(const std::string& name) bool SystemTools::FileIsSymlink(const std::string& name)
{ {
#if defined(_WIN32) #if defined(_WIN32)
DWORD attr = GetFileAttributesW( DWORD attr =
SystemTools::ConvertToWindowsExtendedPath(name).c_str()); GetFileAttributesW(Encoding::ToWindowsExtendedPath(name).c_str());
if (attr != INVALID_FILE_ATTRIBUTES) { if (attr != INVALID_FILE_ATTRIBUTES) {
return (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0; return (attr & FILE_ATTRIBUTE_REPARSE_POINT) != 0;
} else { } else {
@@ -4398,8 +4337,8 @@ bool SystemTools::GetPermissions(const char* file, mode_t& mode)
bool SystemTools::GetPermissions(const std::string& file, mode_t& mode) bool SystemTools::GetPermissions(const std::string& file, mode_t& mode)
{ {
#if defined(_WIN32) #if defined(_WIN32)
DWORD attr = GetFileAttributesW( DWORD attr =
SystemTools::ConvertToWindowsExtendedPath(file).c_str()); GetFileAttributesW(Encoding::ToWindowsExtendedPath(file).c_str());
if (attr == INVALID_FILE_ATTRIBUTES) { if (attr == INVALID_FILE_ATTRIBUTES) {
return false; return false;
} }
@@ -4451,8 +4390,7 @@ bool SystemTools::SetPermissions(const std::string& file, mode_t mode,
mode &= ~currentMask; mode &= ~currentMask;
} }
#ifdef _WIN32 #ifdef _WIN32
if (_wchmod(SystemTools::ConvertToWindowsExtendedPath(file).c_str(), mode) < if (_wchmod(Encoding::ToWindowsExtendedPath(file).c_str(), mode) < 0)
0)
#else #else
if (chmod(file.c_str(), mode) < 0) if (chmod(file.c_str(), mode) < 0)
#endif #endif
+1 -7
View File
@@ -265,13 +265,7 @@ public:
static void ConvertToUnixSlashes(std::string& path); static void ConvertToUnixSlashes(std::string& path);
#ifdef _WIN32 #ifdef _WIN32
/** /** Calls Encoding::ToWindowsExtendedPath. */
* Convert the path to an extended length path to avoid MAX_PATH length
* limitations on Windows. If the input is a local path the result will be
* prefixed with \\?\; if the input is instead a network path, the result
* will be prefixed with \\?\UNC\. All output will also be converted to
* absolute paths with Windows-style backslashes.
**/
static std::wstring ConvertToWindowsExtendedPath(const std::string&); static std::wstring ConvertToWindowsExtendedPath(const std::string&);
#endif #endif
+83
View File
@@ -180,6 +180,88 @@ static int testCommandLineArguments()
return status; return status;
} }
static int testToWindowsExtendedPath()
{
#ifdef _WIN32
int ret = 0;
if (kwsys::Encoding::ToWindowsExtendedPath(
"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
<< std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath(
"L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath(
"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
<< std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath(
"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
<< std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("//") != L"//") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"//\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\") != L"\\\\.\\") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"\\\\.\\\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X") != L"\\\\.\\X") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"\\\\.\\X\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X:") != L"\\\\?\\X:") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"\\\\.\\X:\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("\\\\.\\X:\\") !=
L"\\\\?\\X:\\") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"\\\\.\\X:\\\"" << std::endl;
++ret;
}
if (kwsys::Encoding::ToWindowsExtendedPath("NUL") != L"\\\\.\\NUL") {
std::cout << "Problem with ToWindowsExtendedPath "
<< "\"NUL\"" << std::endl;
++ret;
}
return ret;
#else
return 0;
#endif
}
//---------------------------------------------------------------------------- //----------------------------------------------------------------------------
int testEncoding(int, char* []) int testEncoding(int, char* [])
{ {
@@ -196,6 +278,7 @@ int testEncoding(int, char* [])
ret |= testRobustEncoding(); ret |= testRobustEncoding();
ret |= testCommandLineArguments(); ret |= testCommandLineArguments();
ret |= testWithNulls(); ret |= testWithNulls();
ret |= testToWindowsExtendedPath();
return ret; return ret;
} }
-79
View File
@@ -585,85 +585,6 @@ static bool CheckStringOperations()
res = false; res = false;
} }
#ifdef _WIN32
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
<< std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
"L:/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
L"\\\\?\\L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"L:/Local Mojo/Hex Power Pack/Iffy Voodoo\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") !=
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"\\\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\""
<< std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath(
"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo") !=
L"\\\\?\\UNC\\Foo\\Local Mojo\\Hex Power Pack\\Iffy Voodoo") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"//Foo/Local Mojo/Hex Power Pack/Iffy Voodoo\""
<< std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("//") != L"//") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"//\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\") !=
L"\\\\.\\") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"\\\\.\\\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X") !=
L"\\\\.\\X") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"\\\\.\\X\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:") !=
L"\\\\?\\X:") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"\\\\.\\X:\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("\\\\.\\X:\\") !=
L"\\\\?\\X:\\") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"\\\\.\\X:\\\"" << std::endl;
res = false;
}
if (kwsys::SystemTools::ConvertToWindowsExtendedPath("NUL") !=
L"\\\\.\\NUL") {
std::cerr << "Problem with ConvertToWindowsExtendedPath "
<< "\"NUL\"" << std::endl;
res = false;
}
#endif
if (kwsys::SystemTools::ConvertToWindowsOutputPath( if (kwsys::SystemTools::ConvertToWindowsOutputPath(
"L://Local Mojo/Hex Power Pack/Iffy Voodoo") != "L://Local Mojo/Hex Power Pack/Iffy Voodoo") !=
"\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") { "\"L:\\Local Mojo\\Hex Power Pack\\Iffy Voodoo\"") {