+ return (result == 0) ? short_path : QString::fromWCharArray(&long_path[0]);
+}
+
+
+static QString const get_short_path(QString const & long_path, file_access how)
+{
+ // CreateFileW and GetShortPathNameW need the path in utf16 encoding.
+ if (how == CREATE) {
+ HANDLE h = CreateFileW((wchar_t *) long_path.utf16(),
+ GENERIC_WRITE, 0, NULL, CREATE_NEW,
+ FILE_ATTRIBUTE_NORMAL, NULL);
+ if (h == INVALID_HANDLE_VALUE
+ && GetLastError() != ERROR_FILE_EXISTS)
+ return long_path;
+ CloseHandle(h);
+ }
+ vector<wchar_t> short_path(MAX_PATH);
+ DWORD result = GetShortPathNameW((wchar_t *) long_path.utf16(),
+ &short_path[0], short_path.size());
+
+ if (result > short_path.size()) {
+ short_path.resize(result);
+ result = GetShortPathNameW((wchar_t *) long_path.utf16(),
+ &short_path[0], short_path.size());
+ LATTEST(result <= short_path.size());
+ }
+
+ return (result == 0) ? long_path : QString::fromWCharArray(&short_path[0]);