1 // Copyright (c) 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
5 #ifndef CRAZY_LINKER_ERROR_H
6 #define CRAZY_LINKER_ERROR_H
7 
8 namespace crazy {
9 
10 // A class used to hold a fixed-size buffer to hold error messages
11 // as well as perform assignment and formatting.
12 //
13 // Usage examples:
14 //     Error error;
15 //     error = "Unimplemented feature";
16 //     error->Set("Unimplemented feature");
17 //     error->Format("Feature %s is not implemented", feature_name);
18 //     error->Append(strerror(errno));
19 //     error->AppendFormat("Error: %s", strerror(errno));
20 //
21 class Error {
22  public:
Error()23   Error() { buff_[0] = '\0'; }
24 
Error(const char * message)25   Error(const char* message) { Set(message); }
26 
Error(const Error & other)27   Error(const Error& other) { Set(other.buff_); }
28 
c_str()29   const char* c_str() const { return buff_; }
30 
31   void Set(const char* message);
32 
33   void Format(const char* fmt, ...);
34 
35   void Append(const char* message);
36 
37   void AppendFormat(const char* fmt, ...);
38 
39  private:
40   char buff_[512];
41 };
42 
43 }  // namespace crazy
44 
45 #endif  // CRAZY_LINKER_ERROR_H
46