Ticket #12312: boost_WIN32_error_in_UTF8.diff

File boost_WIN32_error_in_UTF8.diff, 3.0 KB (added by anonymous, 6 years ago)
  • boost_1_61_0/boost/iostreams/detail/system_failure.hpp

    diff --git a/boost_1_61_0/boost/iostreams/detail/system_failure.hpp b/boost_1_61_0/boost/iostreams/detail/system_failure.hpp
    index 7d86eaf..e658016 100644
    a b  
    2121#include <boost/throw_exception.hpp>
    2222#include <boost/iostreams/detail/config/windows_posix.hpp>
    2323#include <boost/iostreams/detail/ios.hpp>  // failure.
     24#include <boost/system/error_code.hpp>
    2425
    2526#if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__LIBCOMO__)
    2627namespace std { using ::strlen; }
     
    3940inline BOOST_IOSTREAMS_FAILURE system_failure(const char* msg)
    4041{
    4142    std::string result;
     43                result += msg;
    4244#ifdef BOOST_IOSTREAMS_WINDOWS
    4345    DWORD err;
    44     LPVOID lpMsgBuf;
    45     if ( (err = ::GetLastError()) != NO_ERROR &&
    46          ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
    47                            FORMAT_MESSAGE_FROM_SYSTEM,
    48                            NULL,
    49                            err,
    50                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
    51                            (LPSTR) &lpMsgBuf,
    52                            0,
    53                            NULL ) != 0 )
    54     {
    55         result.reserve(std::strlen(msg) + 2 + std::strlen((LPSTR)lpMsgBuf));
    56         result.append(msg);
    57         result.append(": ");
    58         result.append((LPSTR) lpMsgBuf);
    59         ::LocalFree(lpMsgBuf);
    60     } else {
    61         result += msg;
    62     }
     46                if ( (err = ::GetLastError()) != NO_ERROR )
    6347#else
    64     const char* system_msg = errno ? strerror(errno) : "";
    65     result.reserve(std::strlen(msg) + 2 + std::strlen(system_msg));
    66     result.append(msg);
    67     result.append(": ");
    68     result.append(system_msg);
    69 #endif
     48                int err = errno;
     49                if ( err )
     50#endif         
     51    {
     52      result.append(": ");
     53                        result.append(boost::system::get_system_category().message(err));
     54    }
    7055    return BOOST_IOSTREAMS_FAILURE(result);
    7156}
    7257
  • boost_1_61_0/boost/system/detail/error_code.ipp

    diff --git a/boost_1_61_0/boost/system/detail/error_code.ipp b/boost_1_61_0/boost/system/detail/error_code.ipp
    index 71c60f6..64b4451 100644
    a b  
    368368
    369369  std::string system_error_category::message( int ev ) const
    370370  {
    371 #if defined(UNDER_CE) || BOOST_PLAT_WINDOWS_RUNTIME || defined(BOOST_NO_ANSI_APIS)
     371#if defined(UNDER_CE) || BOOST_PLAT_WINDOWS_RUNTIME || defined(BOOST_NO_ANSI_APIS) || defined(BOOST_WINDOWS_ERRORS_IN_UTF8)
    372372    std::wstring buf(128, wchar_t());
    373373    for (;;)
    374374    {
     
    398398        }
    399399    }
    400400   
     401#  ifdef BOOST_WINDOWS_ERRORS_IN_UTF8
     402                UINT cp = CP_UTF8;
     403#  else
     404                UINT cp = CP_ACP;
     405#  endif               
    401406    int num_chars = (buf.size() + 1) * 2;
    402407    LPSTR narrow_buffer = (LPSTR)_alloca( num_chars );
    403     if (::WideCharToMultiByte(CP_ACP, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
     408    if (::WideCharToMultiByte(cp, 0, buf.c_str(), -1, narrow_buffer, num_chars, NULL, NULL) == 0)
    404409    {
    405410        return std::string("Unknown error");
    406411    }