From 0082811090b5eecb68af16684dfa6278f9925c22 Mon Sep 17 00:00:00 2001 From: Greg Beard Date: Thu, 18 Oct 2018 13:01:55 +0100 Subject: [PATCH 1/2] Changes Windows version to directly use `CreateFileA` `CreateFile` is `#define`d as `CreateFileW` in unicode builds (when `/D UNICODE` is defined). This is probably more likely to be a issue when integrating into GUI projects. This commit allows compilation to succeed when `UNICODE` has been defined and adds a note to the README, explicitly stating that mio doesn't support wide char string types as parameters. --- README.md | 4 ++++ include/mio/detail/basic_mmap.ipp | 2 +- test/CMakeLists.txt | 14 +++++++++++--- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 65b0fc7..c3287a0 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,9 @@ int main() ``` However, mio does not check whether the provided file descriptor has the same access permissions as the desired mapping, so the mapping may fail. Such errors are reported via the `std::error_code` out parameter that is passed to the mapping function. +**WINDOWS USERS**: This library doesn't support the use of wide character +types for functions where character strings are expected (e.g. path parameters). + ### Example ```c++ @@ -249,6 +252,7 @@ cmake --build . --config Release --target install ``` Note that the last command of the installation sequence may require administrator privileges (e.g. `sudo`) if the installation root directory lies outside your home directory. + This installation + copies the mio header files to the `include/mio` subdirectory of the installation root + generates and copies several CMake configuration files to the `share/cmake/mio` subdirectory of the installation root diff --git a/include/mio/detail/basic_mmap.ipp b/include/mio/detail/basic_mmap.ipp index cfd5c50..08e4bd4 100644 --- a/include/mio/detail/basic_mmap.ipp +++ b/include/mio/detail/basic_mmap.ipp @@ -72,7 +72,7 @@ file_handle_type open_file(const String& path, return INVALID_HANDLE_VALUE; } #ifdef _WIN32 - const auto handle = ::CreateFile(c_str(path), + const auto handle = ::CreateFileA(c_str(path), mode == access_mode::read ? GENERIC_READ : GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index 6985390..b303dec 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -2,6 +2,14 @@ add_executable(mio.test test.cpp) target_link_libraries(mio.test PRIVATE mio::mio) add_test(NAME mio.test COMMAND mio.test) -add_executable(mio.example example.cpp) -target_link_libraries(mio.example PRIVATE mio::mio) -add_test(NAME mio.example COMMAND mio.example) +if(WIN32) + add_executable(mio.unicode.test unicode_test.cpp) + target_link_libraries(mio.unicode.test PRIVATE mio::mio) + target_compile_options( + mio.unicode.test + PRIVATE + $<$:/Zc:wchar_t> + ) + target_compile_definitions(mio.unicode.test PRIVATE UNICODE) + add_test(NAME mio.unicode.test COMMAND mio.test) +endif() From 5655910e73cbed065c21b4ce6e7b58e0f2bfb140 Mon Sep 17 00:00:00 2001 From: Greg Beard Date: Thu, 18 Oct 2018 13:17:47 +0100 Subject: [PATCH 2/2] Removes superfluous compile flags --- test/CMakeLists.txt | 5 ----- 1 file changed, 5 deletions(-) diff --git a/test/CMakeLists.txt b/test/CMakeLists.txt index b303dec..f174498 100644 --- a/test/CMakeLists.txt +++ b/test/CMakeLists.txt @@ -5,11 +5,6 @@ add_test(NAME mio.test COMMAND mio.test) if(WIN32) add_executable(mio.unicode.test unicode_test.cpp) target_link_libraries(mio.unicode.test PRIVATE mio::mio) - target_compile_options( - mio.unicode.test - PRIVATE - $<$:/Zc:wchar_t> - ) target_compile_definitions(mio.unicode.test PRIVATE UNICODE) add_test(NAME mio.unicode.test COMMAND mio.test) endif()