Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 09:38:50

0001 // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
0002 // (C) Copyright 2005-2007 Jonathan Turkanis
0003 // (C) Copyright Jonathan Graehl 2004.
0004 // Distributed under the Boost Software License, Version 1.0. (See accompanying
0005 // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
0006 
0007 // See http://www.boost.org/libs/iostreams for documentation.
0008 
0009 // Used by mapped_file.cpp.
0010 
0011 #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
0012 #define BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
0013 
0014 #if defined(_MSC_VER)
0015 # pragma once
0016 #endif
0017 
0018 #include <cstring>
0019 #include <string>
0020 #include <boost/config.hpp>
0021 #include <boost/throw_exception.hpp>
0022 #include <boost/iostreams/detail/config/windows_posix.hpp>
0023 #include <boost/iostreams/detail/ios.hpp>  // failure.
0024 
0025 #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__LIBCOMO__)
0026 namespace std { using ::strlen; }
0027 #endif
0028 
0029 #ifdef BOOST_IOSTREAMS_WINDOWS
0030 # define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
0031 # include <windows.h>
0032 #else
0033 # include <errno.h>
0034 # include <string.h>
0035 #endif
0036 
0037 namespace boost { namespace iostreams { namespace detail {
0038 
0039 inline BOOST_IOSTREAMS_FAILURE system_failure(const char* msg)
0040 {
0041     std::string result;
0042 #ifdef BOOST_IOSTREAMS_WINDOWS
0043     DWORD err;
0044     LPVOID lpMsgBuf;
0045     if ( (err = ::GetLastError()) != NO_ERROR &&
0046          ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
0047                            FORMAT_MESSAGE_FROM_SYSTEM,
0048                            NULL,
0049                            err,
0050                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
0051                            (LPSTR) &lpMsgBuf,
0052                            0,
0053                            NULL ) != 0 )
0054     {
0055         result.reserve(std::strlen(msg) + 2 + std::strlen((LPSTR)lpMsgBuf));
0056         result.append(msg);
0057         result.append(": ");
0058         result.append((LPSTR) lpMsgBuf);
0059         ::LocalFree(lpMsgBuf);
0060     } else {
0061         result += msg;
0062     }
0063 #else
0064     const char* system_msg = errno ? strerror(errno) : "";
0065     result.reserve(std::strlen(msg) + 2 + std::strlen(system_msg));
0066     result.append(msg);
0067     result.append(": ");
0068     result.append(system_msg);
0069 #endif
0070     return BOOST_IOSTREAMS_FAILURE(result);
0071 }
0072 
0073 inline BOOST_IOSTREAMS_FAILURE system_failure(const std::string& msg)
0074 { return system_failure(msg.c_str()); }
0075 
0076 inline void throw_system_failure(const char* msg)
0077 { boost::throw_exception(system_failure(msg)); }
0078 
0079 inline void throw_system_failure(const std::string& msg)
0080 { boost::throw_exception(system_failure(msg)); }
0081 
0082 } } } // End namespaces detail, iostreams, boost.
0083 
0084 #endif // #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED