| 88 | } |
| 89 | |
| 90 | int Status::set_error(int c, const butil::StringPiece& error_msg) { |
| 91 | if (0 == c) { |
| 92 | free(_state); |
| 93 | _state = NULL; |
| 94 | return 0; |
| 95 | } |
| 96 | const size_t st_size = status_size(error_msg.size()); |
| 97 | if (_state == NULL || _state->state_size < st_size) { |
| 98 | State* new_state = reinterpret_cast<State*>(malloc(st_size)); |
| 99 | if (NULL == new_state) { |
| 100 | return -1; |
| 101 | } |
| 102 | new_state->state_size = st_size; |
| 103 | free(_state); |
| 104 | _state = new_state; |
| 105 | } |
| 106 | _state->code = c; |
| 107 | _state->size = error_msg.size(); |
| 108 | memcpy(_state->message, error_msg.data(), error_msg.size()); |
| 109 | _state->message[error_msg.size()] = '\0'; |
| 110 | return 0; |
| 111 | } |
| 112 | |
| 113 | Status::State* Status::copy_state(const State* s) { |
| 114 | const size_t n = status_size(s->size); |
nothing calls this directly
no test coverage detected