• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 
17 #include <libfiemap/fiemap_status.h>
18 
19 namespace android::fiemap {
20 
21 // FiemapStatus -> string
string() const22 std::string FiemapStatus::string() const {
23     if (error_code() == ErrorCode::ERROR) {
24         return "Error";
25     }
26     return strerror(-static_cast<int>(error_code()));
27 }
28 
29 // -errno -> known ErrorCode
30 // unknown ErrorCode -> known ErrorCode
CastErrorCode(int error_code)31 FiemapStatus::ErrorCode FiemapStatus::CastErrorCode(int error_code) {
32     switch (error_code) {
33         case static_cast<int32_t>(ErrorCode::SUCCESS):
34         case static_cast<int32_t>(ErrorCode::NO_SPACE):
35             return static_cast<ErrorCode>(error_code);
36         case static_cast<int32_t>(ErrorCode::ERROR):
37         default:
38             return ErrorCode::ERROR;
39     }
40 }
41 
42 }  // namespace android::fiemap
43