Skip to content

Commit ed4c693

Browse files
committed
Implement long file path support for Windows
1 parent 96dd457 commit ed4c693

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

src/file.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,10 @@ namespace Sass {
4949

5050
// return the current directory
5151
// always with forward slashes
52+
// always with trailing slash
5253
std::string get_cwd()
5354
{
54-
const size_t wd_len = 1024;
55+
const size_t wd_len = 4096;
5556
#ifndef _WIN32
5657
char wd[wd_len];
5758
std::string cwd = getcwd(wd, wd_len);
@@ -69,7 +70,10 @@ namespace Sass {
6970
bool file_exists(const std::string& path)
7071
{
7172
#ifdef _WIN32
72-
std::wstring wpath = UTF_8::convert_to_utf16(path);
73+
// windows unicode filepaths are encoded in utf16
74+
std::string abspath(join_paths(get_cwd(), path));
75+
std::wstring wpath(UTF_8::convert_to_utf16("\\\\?\\" + abspath));
76+
std::replace(wpath.begin(), wpath.end(), '/', '\\');
7377
DWORD dwAttrib = GetFileAttributesW(wpath.c_str());
7478
return (dwAttrib != INVALID_FILE_ATTRIBUTES &&
7579
(!(dwAttrib & FILE_ATTRIBUTE_DIRECTORY)));
@@ -388,7 +392,9 @@ namespace Sass {
388392
BYTE* pBuffer;
389393
DWORD dwBytes;
390394
// windows unicode filepaths are encoded in utf16
391-
std::wstring wpath = UTF_8::convert_to_utf16(path);
395+
std::string abspath(join_paths(get_cwd(), path));
396+
std::wstring wpath(UTF_8::convert_to_utf16("\\\\?\\" + abspath));
397+
std::replace(wpath.begin(), wpath.end(), '/', '\\');
392398
HANDLE hFile = CreateFileW(wpath.c_str(), GENERIC_READ, FILE_SHARE_READ, NULL, OPEN_EXISTING, 0, NULL);
393399
if (hFile == INVALID_HANDLE_VALUE) return 0;
394400
DWORD dwFileLength = GetFileSize(hFile, NULL);

0 commit comments

Comments
 (0)