1//===---------------------- system_error.cpp ------------------------------===// 2// 3// The LLVM Compiler Infrastructure 4// 5// This file is distributed under the University of Illinois Open Source 6// License. See LICENSE.TXT for details. 7// 8//===----------------------------------------------------------------------===// 9// 10// This was lifted from libc++ and modified for C++03. 11// 12//===----------------------------------------------------------------------===// 13 14#include "llvm/Support/system_error.h" 15#include "llvm/Support/Errno.h" 16#include <cstring> 17#include <string> 18 19namespace llvm { 20 21// class error_category 22 23error_category::error_category() { 24} 25 26error_category::~error_category() { 27} 28 29error_condition 30error_category::default_error_condition(int ev) const { 31 return error_condition(ev, *this); 32} 33 34bool 35error_category::equivalent(int code, const error_condition& condition) const { 36 return default_error_condition(code) == condition; 37} 38 39bool 40error_category::equivalent(const error_code& code, int condition) const { 41 return *this == code.category() && code.value() == condition; 42} 43 44std::string 45_do_message::message(int ev) const { 46 return std::string(sys::StrError(ev)); 47} 48 49class _generic_error_category : public _do_message { 50public: 51 virtual const char* name() const LLVM_OVERRIDE; 52 virtual std::string message(int ev) const LLVM_OVERRIDE; 53}; 54 55const char* 56_generic_error_category::name() const { 57 return "generic"; 58} 59 60std::string 61_generic_error_category::message(int ev) const { 62#ifdef ELAST 63 if (ev > ELAST) 64 return std::string("unspecified generic_category error"); 65#endif // ELAST 66 return _do_message::message(ev); 67} 68 69const error_category& 70generic_category() { 71 static _generic_error_category s; 72 return s; 73} 74 75class _system_error_category : public _do_message { 76public: 77 virtual const char* name() const LLVM_OVERRIDE; 78 virtual std::string message(int ev) const LLVM_OVERRIDE; 79 virtual error_condition default_error_condition(int ev) const LLVM_OVERRIDE; 80}; 81 82const char* 83_system_error_category::name() const { 84 return "system"; 85} 86 87// std::string _system_error_category::message(int ev) const { 88// Is in Platform/system_error.inc 89 90// error_condition _system_error_category::default_error_condition(int ev) const 91// Is in Platform/system_error.inc 92 93const error_category& 94system_category() { 95 static _system_error_category s; 96 return s; 97} 98 99const error_category& 100posix_category() { 101#ifdef LLVM_ON_WIN32 102 return generic_category(); 103#else 104 return system_category(); 105#endif 106} 107 108// error_condition 109 110std::string 111error_condition::message() const { 112 return _cat_->message(_val_); 113} 114 115// error_code 116 117std::string 118error_code::message() const { 119 return _cat_->message(_val_); 120} 121 122} // end namespace llvm 123 124// Include the truly platform-specific parts of this class. 125#if defined(LLVM_ON_UNIX) 126#include "Unix/system_error.inc" 127#endif 128#if defined(LLVM_ON_WIN32) 129#include "Windows/system_error.inc" 130#endif 131