blob: 14e49bb40db749f2174ca64bcb90c72d283c68ce [file] [log] [blame]
Elliott Hughes8cdfb162020-03-17 14:10:59 -07001/*
2 * Copyright (C) 2008 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 "zip_error.h"
18
19#include <android-base/macros.h>
20
21static const char* kErrorMessages[] = {
22 "Success",
23 "Iteration ended",
24 "Zlib error",
25 "Invalid file",
26 "Invalid handle",
27 "Duplicate entries in archive",
28 "Empty archive",
29 "Entry not found",
30 "Invalid offset",
31 "Inconsistent information",
32 "Invalid entry name",
33 "I/O error",
34 "File mapping failed",
35 "Allocation failed",
Tianjie26ee1db2020-04-01 23:08:34 -070036 "Unsupported zip entry size",
Elliott Hughes8cdfb162020-03-17 14:10:59 -070037};
38
39const char* ErrorCodeString(int32_t error_code) {
40 // Make sure that the number of entries in kErrorMessages and the ZipError
41 // enum match.
42 static_assert((-kLastErrorCode + 1) == arraysize(kErrorMessages),
43 "(-kLastErrorCode + 1) != arraysize(kErrorMessages)");
44
45 const uint32_t idx = -error_code;
46 if (idx < arraysize(kErrorMessages)) {
47 return kErrorMessages[idx];
48 }
49
50 return "Unknown return code";
51}