BVB Source Codes

mars Show system_failure.hpp Source code

Return Download mars: download system_failure.hpp Source code - Download mars Source code - Type:.hpp
  1. // (C) Copyright 2008 CodeRage, LLC (turkanis at coderage dot com)
  2. // (C) Copyright 2005-2007 Jonathan Turkanis
  3. // (C) Copyright Jonathan Graehl 2004.
  4. // Distributed under the Boost Software License, Version 1.0. (See accompanying
  5. // file LICENSE_1_0.txt or copy at http://www.boost.org/LICENSE_1_0.txt.)
  6.  
  7. // See http://www.boost.org/libs/iostreams for documentation.
  8.  
  9. // Used by mapped_file.cpp.
  10.  
  11. #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
  12. #define BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
  13.  
  14. #if defined(_MSC_VER) && (_MSC_VER >= 1020)
  15. # pragma once
  16. #endif
  17.  
  18. #include <cstring>
  19. #include <string>
  20. #include <boost/config.hpp>
  21. #include <boost/throw_exception.hpp>
  22. #include <boost/iostreams/detail/config/windows_posix.hpp>
  23. #include <boost/iostreams/detail/ios.hpp>  // failure.
  24.  
  25. #if defined(BOOST_NO_STDC_NAMESPACE) && !defined(__LIBCOMO__)
  26. namespace std { using ::strlen; }
  27. #endif
  28.  
  29. #ifdef BOOST_IOSTREAMS_WINDOWS
  30. # define WIN32_LEAN_AND_MEAN  // Exclude rarely-used stuff from Windows headers
  31. # include <windows.h>
  32. #else
  33. # include <errno.h>
  34. # include <string.h>
  35. #endif
  36.  
  37. namespace mars_boost {} namespace boost = mars_boost; namespace mars_boost { namespace iostreams { namespace detail {
  38.  
  39. inline BOOST_IOSTREAMS_FAILURE system_failure(const char* msg)
  40. {
  41.     std::string result;
  42. #ifdef BOOST_IOSTREAMS_WINDOWS
  43. #if UWP
  44.     DWORD err;
  45.     LPVOID lpMsgBuf;
  46.     if ( (err = ::GetLastError()) != NO_ERROR &&
  47.          ::FormatMessageA(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.  
  60.                 ::HeapFree(::GetProcessHeap(), NULL, lpMsgBuf);
  61. #else
  62.         DWORD err;
  63.     LPVOID lpMsgBuf;
  64.     if ( (err = ::GetLastError()) != NO_ERROR &&
  65.          ::FormatMessageA( FORMAT_MESSAGE_ALLOCATE_BUFFER |
  66.                            FORMAT_MESSAGE_FROM_SYSTEM,
  67.                            NULL,
  68.                            err,
  69.                            MAKELANGID(LANG_NEUTRAL, SUBLANG_DEFAULT),
  70.                            (LPSTR) &lpMsgBuf,
  71.                            0,
  72.                            NULL ) != 0 )
  73.     {
  74.         result.reserve(std::strlen(msg) + 2 + std::strlen((LPSTR)lpMsgBuf));
  75.         result.append(msg);
  76.         result.append(": ");
  77.         result.append((LPSTR) lpMsgBuf);
  78.         ::LocalFree(lpMsgBuf);
  79. #endif
  80.     } else {
  81.         result += msg;
  82.     }
  83. #else
  84.     const char* system_msg = errno ? strerror(errno) : "";
  85.     result.reserve(std::strlen(msg) + 2 + std::strlen(system_msg));
  86.     result.append(msg);
  87.     result.append(": ");
  88.     result.append(system_msg);
  89. #endif
  90.     return BOOST_IOSTREAMS_FAILURE(result);
  91. }
  92.  
  93. inline BOOST_IOSTREAMS_FAILURE system_failure(const std::string& msg)
  94. { return system_failure(msg.c_str()); }
  95.  
  96. inline void throw_system_failure(const char* msg)
  97. { mars_boost::throw_exception(system_failure(msg)); }
  98.  
  99. inline void throw_system_failure(const std::string& msg)
  100. { mars_boost::throw_exception(system_failure(msg)); }
  101.  
  102. } } } // End namespaces detail, iostreams, boost.
  103.  
  104. #endif // #ifndef BOOST_IOSTREAMS_DETAIL_SYSTEM_FAILURE_HPP_INCLUDED
  105.  
downloadsystem_failure.hpp Source code - Download mars Source code
Related Source Codes/Software:
Hero - Elegant transition library for iOS & tvOS 2017-06-09
deep-photo-styletransfer - Code and data for paper "Deep Photo Style Transfer... 2017-06-09
mastodon - A GNU Social-compatible microblogging server ... 2017-06-09
plyr - A simple HTML5, YouTube and Vimeo player ... 2017-06-08
prepack - Prepack is a partial evaluator for JavaScript. Pre... 2017-06-08
Public-APIs - 2017-06-09
lottie-ios - An iOS library to natively render After Effects ve... 2017-06-09
Awesome-Hacking - A collection of various awesome lists for hackers,... 2017-06-09
algorithms - Minimal examples of data structures and algorithms... 2017-06-10
lectures - Oxford Deep NLP 2017 course 2017-06-10
CRYENGINE - CRYENGINE is a powerful real-time game development... 2017-06-11
postal - 2017-06-11
reactide - Reactide is the first dedicated IDE for React web ... 2017-06-11
rkt - rkt is a pod-native container engine for Linux. It... 2017-06-11
uWebSockets - Tiny WebSockets https://for... 2017-06-11
realworld - TodoMVC for the RealWorld - Exemplary fullstack Me... 2017-06-11
goreplay - GoReplay is an open-source tool for capturing and ... 2017-06-10
pyenv - Simple Python version management 2017-06-10
redux-saga - An alternative side effect model for Redux apps ... 2017-06-10
angular-starter - 2017-06-10

 Back to top