Add a function for profiling to run at shutdown. Unlike the existing API, this
[llvm/stm8.git] / lib / Support / system_error.cpp
blob56898de31520b71882e9d58fe5fafa44443e6734
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.
12 //===----------------------------------------------------------------------===//
14 #include "llvm/Support/system_error.h"
15 #include "llvm/Support/Errno.h"
16 #include <string>
17 #include <cstring>
19 namespace llvm {
21 // class error_category
23 error_category::error_category() {
26 error_category::~error_category() {
29 error_condition
30 error_category::default_error_condition(int ev) const {
31 return error_condition(ev, *this);
34 bool
35 error_category::equivalent(int code, const error_condition& condition) const {
36 return default_error_condition(code) == condition;
39 bool
40 error_category::equivalent(const error_code& code, int condition) const {
41 return *this == code.category() && code.value() == condition;
44 std::string
45 _do_message::message(int ev) const {
46 return std::string(sys::StrError(ev));
49 class _generic_error_category : public _do_message {
50 public:
51 virtual const char* name() const;
52 virtual std::string message(int ev) const;
55 const char*
56 _generic_error_category::name() const {
57 return "generic";
60 std::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);
69 const error_category&
70 generic_category() {
71 static _generic_error_category s;
72 return s;
75 class _system_error_category : public _do_message {
76 public:
77 virtual const char* name() const;
78 virtual std::string message(int ev) const;
79 virtual error_condition default_error_condition(int ev) const;
82 const char*
83 _system_error_category::name() const {
84 return "system";
87 // std::string _system_error_category::message(int ev) const {
88 // Is in Platform/system_error.inc
90 // error_condition _system_error_category::default_error_condition(int ev) const
91 // Is in Platform/system_error.inc
93 const error_category&
94 system_category() {
95 static _system_error_category s;
96 return s;
99 const error_category&
100 posix_category() {
101 #ifdef LLVM_ON_WIN32
102 return generic_category();
103 #else
104 return system_category();
105 #endif
108 // error_condition
110 std::string
111 error_condition::message() const {
112 return _cat_->message(_val_);
115 // error_code
117 std::string
118 error_code::message() const {
119 return _cat_->message(_val_);
122 } // end namespace llvm
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