1 /*
2  * Copyright (C) 2019 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 #include <utils/Errors.h>
17 
18 namespace android {
19 
statusToString(status_t s)20 std::string statusToString(status_t s) {
21 #define STATUS_CASE(STATUS) \
22     case STATUS:            \
23         return #STATUS
24 
25     switch (s) {
26         STATUS_CASE(OK);
27         STATUS_CASE(UNKNOWN_ERROR);
28         STATUS_CASE(NO_MEMORY);
29         STATUS_CASE(INVALID_OPERATION);
30         STATUS_CASE(BAD_VALUE);
31         STATUS_CASE(BAD_TYPE);
32         STATUS_CASE(NAME_NOT_FOUND);
33         STATUS_CASE(PERMISSION_DENIED);
34         STATUS_CASE(NO_INIT);
35         STATUS_CASE(ALREADY_EXISTS);
36         STATUS_CASE(DEAD_OBJECT);
37         STATUS_CASE(FAILED_TRANSACTION);
38         STATUS_CASE(BAD_INDEX);
39         STATUS_CASE(NOT_ENOUGH_DATA);
40         STATUS_CASE(WOULD_BLOCK);
41         STATUS_CASE(TIMED_OUT);
42         STATUS_CASE(UNKNOWN_TRANSACTION);
43         STATUS_CASE(FDS_NOT_ALLOWED);
44         STATUS_CASE(UNEXPECTED_NULL);
45 #undef STATUS_CASE
46     }
47 
48     return std::to_string(s) + " (" + strerror(-s) + ")";
49 }
50 
51 }  // namespace android
52