Skip to content
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

wchar_t filename support for windows #1570

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 8 additions & 5 deletions asio/include/asio/basic_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,8 +129,9 @@ class basic_file
* @param open_flags A set of flags that determine how the file should be
* opened.
*/
template<typename CharacterType = char>
explicit basic_file(const executor_type& ex,
const char* path, file_base::flags open_flags)
const CharacterType* path, file_base::flags open_flags)
: impl_(0, ex)
{
asio::error_code ec;
Expand All @@ -151,9 +152,9 @@ class basic_file
* @param open_flags A set of flags that determine how the file should be
* opened.
*/
template <typename ExecutionContext>
template <typename ExecutionContext, typename CharacterType = char>
explicit basic_file(ExecutionContext& context,
const char* path, file_base::flags open_flags,
const CharacterType* path, file_base::flags open_flags,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value,
defaulted_constraint
Expand Down Expand Up @@ -360,7 +361,8 @@ class basic_file
* file.open("/path/to/my/file", asio::stream_file::read_only);
* @endcode
*/
void open(const char* path, file_base::flags open_flags)
template<typename CharacterType = char>
void open(const CharacterType* path, file_base::flags open_flags)
{
asio::error_code ec;
impl_.get_service().open(impl_.get_implementation(), path, open_flags, ec);
Expand Down Expand Up @@ -389,7 +391,8 @@ class basic_file
* }
* @endcode
*/
ASIO_SYNC_OP_VOID open(const char* path,
template<typename CharacterType = char>
ASIO_SYNC_OP_VOID open(const CharacterType* path,
file_base::flags open_flags, asio::error_code& ec)
{
impl_.get_service().open(impl_.get_implementation(), path, open_flags, ec);
Expand Down
7 changes: 4 additions & 3 deletions asio/include/asio/basic_stream_file.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -130,8 +130,9 @@ class basic_stream_file
*
* @throws asio::system_error Thrown on failure.
*/
template<typename CharacterType = char>
basic_stream_file(const executor_type& ex,
const char* path, file_base::flags open_flags)
const CharacterType* path, file_base::flags open_flags)
: basic_file<Executor>(ex)
{
asio::error_code ec;
Expand All @@ -158,9 +159,9 @@ class basic_stream_file
*
* @throws asio::system_error Thrown on failure.
*/
template <typename ExecutionContext>
template <typename ExecutionContext, typename CharacterType = char>
basic_stream_file(ExecutionContext& context,
const char* path, file_base::flags open_flags,
const CharacterType* path, file_base::flags open_flags,
constraint_t<
is_convertible<ExecutionContext&, execution_context&>::value,
defaulted_constraint
Expand Down
14 changes: 12 additions & 2 deletions asio/include/asio/detail/impl/win_iocp_file_service.ipp
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,11 @@ void win_iocp_file_service::shutdown()
handle_service_.shutdown();
}

template<typename CharacterType,
std::enable_if_t<std::is_same_v<CharacterType, char> || std::is_same_v<CharacterType, wchar_t>, bool> = true>
asio::error_code win_iocp_file_service::open(
win_iocp_file_service::implementation_type& impl,
const char* path, file_base::flags open_flags,
const CharacterType* path, file_base::flags open_flags,
asio::error_code& ec)
{
if (is_open(impl))
Expand Down Expand Up @@ -95,7 +97,15 @@ asio::error_code win_iocp_file_service::open(
flags |= FILE_FLAG_WRITE_THROUGH;

impl.offset_ = 0;
HANDLE handle = ::CreateFileA(path, access, share, 0, disposition, flags, 0);
HANDLE handle = INVALID_HANDLE_VALUE;
if constexpr(std::is_same_v<CharacterType, char>)
{
handle = ::CreateFileA(path, access, share, 0, disposition, flags, 0);
}
if constexpr(std::is_same_v<CharacterType, wchar_t>)
{
handle = ::CreateFileW(path, access, share, 0, disposition, flags, 0);
}
if (handle != INVALID_HANDLE_VALUE)
{
if (disposition == OPEN_ALWAYS)
Expand Down
4 changes: 3 additions & 1 deletion asio/include/asio/detail/win_iocp_file_service.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ class win_iocp_file_service :
}

// Open the file using the specified path name.
template<typename CharacterType,
std::enable_if_t<std::is_same_v<CharacterType, char> || std::is_same_v<CharacterType, wchar_t>, bool> = true>
ASIO_DECL asio::error_code open(implementation_type& impl,
const char* path, file_base::flags open_flags,
const CharacterType* path, file_base::flags open_flags,
asio::error_code& ec);

// Assign a native handle to a file implementation.
Expand Down