From 4736079b2e57124e9ffeea007d183db4973f5697 Mon Sep 17 00:00:00 2001 From: Beman Date: Sun, 4 Jun 2017 11:01:08 -0400 Subject: [PATCH] Fix boost::detail::winapi::ERROR_INSUFFICIENT_BUFFER_ in error_code.ipp (Thanks to Lastique). Use in windows_error.hpp. Add msvc project to build header-only version of error_code_test. --- include/boost/system/detail/error_code.ipp | 2 +- include/boost/system/windows_error.hpp | 116 +++++++------- .../header_only_error_code_test.vcxproj | 151 ++++++++++++++++++ test/msvc/system.sln | 10 ++ 4 files changed, 221 insertions(+), 58 deletions(-) create mode 100644 test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj diff --git a/include/boost/system/detail/error_code.ipp b/include/boost/system/detail/error_code.ipp index 7c29076..e686fd3 100644 --- a/include/boost/system/detail/error_code.ipp +++ b/include/boost/system/detail/error_code.ipp @@ -389,7 +389,7 @@ namespace buf.resize(retval); break; } - else if (boost::detail::winapi::GetLastError() != ERROR_INSUFFICIENT_BUFFER) + else if (boost::detail::winapi::GetLastError() != boost::detail::winapi::ERROR_INSUFFICIENT_BUFFER_) { return std::string("Unknown error"); } diff --git a/include/boost/system/windows_error.hpp b/include/boost/system/windows_error.hpp index 38d6284..0fb7ea6 100644 --- a/include/boost/system/windows_error.hpp +++ b/include/boost/system/windows_error.hpp @@ -19,14 +19,16 @@ #include -// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on -// either of those platforms include the full windows.h +//// Neither MinGW or Cygwin versions of winerror.h work if used alone, so on +//// either of those platforms include the full windows.h +// +//#if defined(__MINGW32__) || defined(__CYGWIN__) +//#include +//#else +//#include +//#endif -#if defined(__MINGW32__) || defined(__CYGWIN__) -#include -#else -#include -#endif +#include namespace boost { @@ -45,59 +47,59 @@ namespace boost { success = 0, // These names and values are based on Windows winerror.h - invalid_function = ERROR_INVALID_FUNCTION, - file_not_found = ERROR_FILE_NOT_FOUND, - path_not_found = ERROR_PATH_NOT_FOUND, - too_many_open_files = ERROR_TOO_MANY_OPEN_FILES, - access_denied = ERROR_ACCESS_DENIED, - invalid_handle = ERROR_INVALID_HANDLE, - arena_trashed = ERROR_ARENA_TRASHED, - not_enough_memory = ERROR_NOT_ENOUGH_MEMORY, - invalid_block = ERROR_INVALID_BLOCK, - bad_environment = ERROR_BAD_ENVIRONMENT, - bad_format = ERROR_BAD_FORMAT, - invalid_access = ERROR_INVALID_ACCESS, - outofmemory = ERROR_OUTOFMEMORY, - invalid_drive = ERROR_INVALID_DRIVE, - current_directory = ERROR_CURRENT_DIRECTORY, - not_same_device = ERROR_NOT_SAME_DEVICE, - no_more_files = ERROR_NO_MORE_FILES, - write_protect = ERROR_WRITE_PROTECT, - bad_unit = ERROR_BAD_UNIT, - not_ready = ERROR_NOT_READY, - bad_command = ERROR_BAD_COMMAND, - crc = ERROR_CRC, - bad_length = ERROR_BAD_LENGTH, - seek = ERROR_SEEK, - not_dos_disk = ERROR_NOT_DOS_DISK, - sector_not_found = ERROR_SECTOR_NOT_FOUND, - out_of_paper = ERROR_OUT_OF_PAPER, - write_fault = ERROR_WRITE_FAULT, - read_fault = ERROR_READ_FAULT, - gen_failure = ERROR_GEN_FAILURE, - sharing_violation = ERROR_SHARING_VIOLATION, - lock_violation = ERROR_LOCK_VIOLATION, - wrong_disk = ERROR_WRONG_DISK, - sharing_buffer_exceeded = ERROR_SHARING_BUFFER_EXCEEDED, - handle_eof = ERROR_HANDLE_EOF, - handle_disk_full= ERROR_HANDLE_DISK_FULL, - rem_not_list = ERROR_REM_NOT_LIST, - dup_name = ERROR_DUP_NAME, - bad_net_path = ERROR_BAD_NETPATH, - network_busy = ERROR_NETWORK_BUSY, + invalid_function = boost::detail::winapi::ERROR_INVALID_FUNCTION_, + file_not_found = boost::detail::winapi::ERROR_FILE_NOT_FOUND_, + path_not_found = boost::detail::winapi::ERROR_PATH_NOT_FOUND_, + too_many_open_files = boost::detail::winapi::ERROR_TOO_MANY_OPEN_FILES_, + access_denied = boost::detail::winapi::ERROR_ACCESS_DENIED_, + invalid_handle = boost::detail::winapi::ERROR_INVALID_HANDLE_, + arena_trashed = boost::detail::winapi::ERROR_ARENA_TRASHED_, + not_enough_memory = boost::detail::winapi::ERROR_NOT_ENOUGH_MEMORY_, + invalid_block = boost::detail::winapi::ERROR_INVALID_BLOCK_, + bad_environment = boost::detail::winapi::ERROR_BAD_ENVIRONMENT_, + bad_format = boost::detail::winapi::ERROR_BAD_FORMAT_, + invalid_access = boost::detail::winapi::ERROR_INVALID_ACCESS_, + outofmemory = boost::detail::winapi::ERROR_OUTOFMEMORY_, + invalid_drive = boost::detail::winapi::ERROR_INVALID_DRIVE_, + current_directory = boost::detail::winapi::ERROR_CURRENT_DIRECTORY_, + not_same_device = boost::detail::winapi::ERROR_NOT_SAME_DEVICE_, + no_more_files = boost::detail::winapi::ERROR_NO_MORE_FILES_, + write_protect = boost::detail::winapi::ERROR_WRITE_PROTECT_, + bad_unit = boost::detail::winapi::ERROR_BAD_UNIT_, + not_ready = boost::detail::winapi::ERROR_NOT_READY_, + bad_command = boost::detail::winapi::ERROR_BAD_COMMAND_, + crc = boost::detail::winapi::ERROR_CRC_, + bad_length = boost::detail::winapi::ERROR_BAD_LENGTH_, + seek = boost::detail::winapi::ERROR_SEEK_, + not_dos_disk = boost::detail::winapi::ERROR_NOT_DOS_DISK_, + sector_not_found = boost::detail::winapi::ERROR_SECTOR_NOT_FOUND_, + out_of_paper = boost::detail::winapi::ERROR_OUT_OF_PAPER_, + write_fault = boost::detail::winapi::ERROR_WRITE_FAULT_, + read_fault = boost::detail::winapi::ERROR_READ_FAULT_, + gen_failure = boost::detail::winapi::ERROR_GEN_FAILURE_, + sharing_violation = boost::detail::winapi::ERROR_SHARING_VIOLATION_, + lock_violation = boost::detail::winapi::ERROR_LOCK_VIOLATION_, + wrong_disk = boost::detail::winapi::ERROR_WRONG_DISK_, + sharing_buffer_exceeded = boost::detail::winapi::ERROR_SHARING_BUFFER_EXCEEDED_, + handle_eof = boost::detail::winapi::ERROR_HANDLE_EOF_, + handle_disk_full= boost::detail::winapi::ERROR_HANDLE_DISK_FULL_, + rem_not_list = boost::detail::winapi::ERROR_REM_NOT_LIST_, + dup_name = boost::detail::winapi::ERROR_DUP_NAME_, + bad_net_path = boost::detail::winapi::ERROR_BAD_NETPATH_, + network_busy = boost::detail::winapi::ERROR_NETWORK_BUSY_, // ... - file_exists = ERROR_FILE_EXISTS, - cannot_make = ERROR_CANNOT_MAKE, + file_exists = boost::detail::winapi::ERROR_FILE_EXISTS_, + cannot_make = boost::detail::winapi::ERROR_CANNOT_MAKE_, // ... - broken_pipe = ERROR_BROKEN_PIPE, - open_failed = ERROR_OPEN_FAILED, - buffer_overflow = ERROR_BUFFER_OVERFLOW, - disk_full= ERROR_DISK_FULL, + broken_pipe = boost::detail::winapi::ERROR_BROKEN_PIPE_, + open_failed = boost::detail::winapi::ERROR_OPEN_FAILED_, + buffer_overflow = boost::detail::winapi::ERROR_BUFFER_OVERFLOW_, + disk_full= boost::detail::winapi::ERROR_DISK_FULL_, // ... - lock_failed = ERROR_LOCK_FAILED, - busy = ERROR_BUSY, - cancel_violation = ERROR_CANCEL_VIOLATION, - already_exists = ERROR_ALREADY_EXISTS + lock_failed = boost::detail::winapi::ERROR_LOCK_FAILED_, + busy = boost::detail::winapi::ERROR_BUSY_, + cancel_violation = boost::detail::winapi::ERROR_CANCEL_VIOLATION_, + already_exists = boost::detail::winapi::ERROR_ALREADY_EXISTS_ // ... // TODO: add more Windows errors diff --git a/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj b/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj new file mode 100644 index 0000000..2649e3a --- /dev/null +++ b/test/msvc/header_only_error_code_test/header_only_error_code_test.vcxproj @@ -0,0 +1,151 @@ + + + + + Debug + Win32 + + + Release + Win32 + + + Debug + x64 + + + Release + x64 + + + + 15.0 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7} + Win32Proj + header_only_error_code_test + 10.0.14393.0 + + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + Application + true + v141 + Unicode + + + Application + false + v141 + true + Unicode + + + + + + + + + + + + + + + + + + + + + + + + + true + + + true + + + false + + + false + + + + + + Level3 + Disabled + WIN32;_DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + + + + + + + Level3 + Disabled + _DEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + + + + + Level3 + + + MaxSpeed + true + true + WIN32;NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + true + true + + + + + Level3 + + + MaxSpeed + true + true + NDEBUG;_CONSOLE;%(PreprocessorDefinitions);BOOST_ERROR_CODE_HEADER_ONLY + + + Console + true + true + + + + + + + + + \ No newline at end of file diff --git a/test/msvc/system.sln b/test/msvc/system.sln index 186bdc3..25b44db 100644 --- a/test/msvc/system.sln +++ b/test/msvc/system.sln @@ -18,6 +18,8 @@ Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "std_interop_test", "std_int {419402D4-F990-4B05-A459-655E2DC33DC2} = {419402D4-F990-4B05-A459-655E2DC33DC2} EndProjectSection EndProject +Project("{8BC9CEB8-8B4A-11D0-8D11-00A0C91BC942}") = "header_only_error_code_test", "header_only_error_code_test\header_only_error_code_test.vcxproj", "{C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Win32 = Debug|Win32 @@ -66,6 +68,14 @@ Global {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|Win32.Build.0 = Release|Win32 {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.ActiveCfg = Release|x64 {47B0A041-1EB5-4842-BD17-BA0DCC5E0313}.Release|x64.Build.0 = Release|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.ActiveCfg = Debug|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|Win32.Build.0 = Debug|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.ActiveCfg = Debug|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Debug|x64.Build.0 = Debug|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.ActiveCfg = Release|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|Win32.Build.0 = Release|Win32 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.ActiveCfg = Release|x64 + {C25D7BD7-1B99-4DA9-A1A5-3034410CBEF7}.Release|x64.Build.0 = Release|x64 EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE