| OLD | NEW |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a | 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. | 3 // BSD-style license that can be found in the LICENSE file. |
| 4 | 4 |
| 5 #ifndef BIN_UTILS_H_ | 5 #ifndef BIN_UTILS_H_ |
| 6 #define BIN_UTILS_H_ | 6 #define BIN_UTILS_H_ |
| 7 | 7 |
| 8 #include <stdlib.h> | 8 #include <stdlib.h> |
| 9 #include <string.h> | 9 #include <string.h> |
| 10 | 10 |
| 11 #include "include/dart_api.h" | 11 #include "include/dart_api.h" |
| 12 #include "platform/globals.h" | 12 #include "platform/globals.h" |
| 13 | 13 |
| 14 class OSError { | 14 class OSError { |
| 15 public: | 15 public: |
| 16 enum SubSystem { |
| 17 kSystem, |
| 18 kGetAddressInfo, |
| 19 kUnknown = -1 |
| 20 }; |
| 21 |
| 16 OSError(); | 22 OSError(); |
| 17 OSError(int code, char* message) { | 23 OSError(int code, const char* message, SubSystem sub_system) { |
| 24 sub_system_ = sub_system; |
| 18 code_ = code; | 25 code_ = code; |
| 19 SetMessage(message); | 26 SetMessage(message); |
| 20 } | 27 } |
| 21 virtual ~OSError() { free(message_); } | 28 virtual ~OSError() { free(message_); } |
| 22 | 29 |
| 30 SubSystem sub_system() { return sub_system_; } |
| 31 void set_sub_system(SubSystem sub_system) { sub_system_ = sub_system; } |
| 23 int code() { return code_; } | 32 int code() { return code_; } |
| 24 void set_code(int code) { code_ = code; } | 33 void set_code(int code) { code_ = code; } |
| 25 char* message() { return message_; } | 34 char* message() { return message_; } |
| 26 void SetMessage(char* message) { | 35 void SetMessage(const char* message) { |
| 27 free(message_); | 36 free(message_); |
| 28 if (message == NULL) { | 37 if (message == NULL) { |
| 29 message_ = NULL; | 38 message_ = NULL; |
| 30 } else { | 39 } else { |
| 31 message_ = strdup(message); | 40 message_ = strdup(message); |
| 32 } | 41 } |
| 33 } | 42 } |
| 34 | 43 |
| 35 private: | 44 private: |
| 45 SubSystem sub_system_; |
| 36 int code_; | 46 int code_; |
| 37 char* message_; | 47 char* message_; |
| 38 | 48 |
| 39 DISALLOW_COPY_AND_ASSIGN(OSError); | 49 DISALLOW_COPY_AND_ASSIGN(OSError); |
| 40 }; | 50 }; |
| 41 | 51 |
| 42 #endif // BIN_UTILS_H_ | 52 #endif // BIN_UTILS_H_ |
| OLD | NEW |