-
Notifications
You must be signed in to change notification settings - Fork 1.6k
Fix <filesystem> linker errors for UWP developers #356
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,73 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||
|
|
||
| // This must be as small as possible, because its contents are | ||
| // injected into the msvcprt.lib and msvcprtd.lib import libraries. | ||
| // Do not include or define anything else here. | ||
| // In particular, basic_string must not be included here. | ||
|
|
||
| // TRANSITION, the code in this file should be moved back to filesystem.cpp | ||
| // when a Windows 10 SDK beyond version 1903 is available (see GH-322). | ||
|
|
||
| #include <internal_shared.h> | ||
| #include <limits.h> | ||
| #include <xfilesystem_abi.h> | ||
|
|
||
| #include <Windows.h> | ||
|
|
||
| namespace { | ||
| static_assert(sizeof(uintmax_t) == sizeof(ULARGE_INTEGER) && alignof(uintmax_t) == alignof(ULARGE_INTEGER), | ||
| "Size and alignment must match for reinterpret_cast<PULARGE_INTEGER>"); | ||
|
|
||
| [[nodiscard]] __std_win_error _Fs_space_attempt(wchar_t* const _Temp_buffer, const DWORD _Temp_buffer_characters, | ||
| const wchar_t* const _Target, uintmax_t* const _Available, uintmax_t* const _Total_bytes, | ||
| uintmax_t* const _Free_bytes) noexcept { | ||
| if (GetVolumePathNameW(_Target, _Temp_buffer, _Temp_buffer_characters)) { | ||
| if (GetDiskFreeSpaceExW(_Temp_buffer, reinterpret_cast<PULARGE_INTEGER>(_Available), | ||
| reinterpret_cast<PULARGE_INTEGER>(_Total_bytes), reinterpret_cast<PULARGE_INTEGER>(_Free_bytes))) { | ||
| return __std_win_error::_Success; | ||
| } | ||
| } | ||
|
|
||
| return __std_win_error{GetLastError()}; | ||
| } | ||
| } // unnamed namespace | ||
|
|
||
| _EXTERN_C | ||
| [[nodiscard]] __std_win_error __stdcall __std_fs_space(const wchar_t* const _Target, uintmax_t* const _Available, | ||
| uintmax_t* const _Total_bytes, uintmax_t* const _Free_bytes) noexcept { | ||
| // get capacity information for the volume on which the file _Target resides | ||
| __std_win_error _Last_error; | ||
| if (GetFileAttributesW(_Target) == INVALID_FILE_ATTRIBUTES) { | ||
| _Last_error = __std_win_error{GetLastError()}; | ||
| } else { | ||
| { | ||
| constexpr DWORD _Static_size = MAX_PATH; | ||
| wchar_t _Temp_buf[_Static_size]; | ||
| _Last_error = _Fs_space_attempt(_Temp_buf, _Static_size, _Target, _Available, _Total_bytes, _Free_bytes); | ||
| if (_Last_error == __std_win_error::_Success) { | ||
| return __std_win_error::_Success; | ||
| } | ||
| } | ||
|
|
||
| if (_Last_error == __std_win_error::_Filename_exceeds_range) { | ||
| constexpr DWORD _Dynamic_size = USHRT_MAX + 1; // assuming maximum NT path fits in a UNICODE_STRING | ||
| const auto _Temp_buf = _malloc_crt_t(wchar_t, _Dynamic_size); | ||
| if (_Temp_buf) { | ||
| _Last_error = | ||
| _Fs_space_attempt(_Temp_buf.get(), _Dynamic_size, _Target, _Available, _Total_bytes, _Free_bytes); | ||
| if (_Last_error == __std_win_error::_Success) { | ||
| return __std_win_error::_Success; | ||
| } | ||
| } else { | ||
| _Last_error = __std_win_error::_Not_enough_memory; | ||
| } | ||
| } | ||
| } | ||
|
|
||
| *_Available = ~0ull; | ||
| *_Total_bytes = ~0ull; | ||
| *_Free_bytes = ~0ull; | ||
| return _Last_error; | ||
| } | ||
| _END_EXTERN_C | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.