Merge "libziparchive: move the array of error strings into the implementation." am: b962d6bee5

Change-Id: I459ee083a27c8c2d14079376dc9fc70b35a68007
This commit is contained in:
Treehugger Robot 2020-03-17 23:42:22 +00:00 committed by Automerger Merge Worker
commit 8289cce4e1
4 changed files with 51 additions and 31 deletions

View file

@ -61,6 +61,7 @@ cc_defaults {
"zip_archive.cc",
"zip_archive_stream_entry.cc",
"zip_cd_entry_map.cc",
"zip_error.cpp",
"zip_writer.cc",
],

View file

@ -1026,20 +1026,6 @@ int32_t ExtractEntryToFile(ZipArchiveHandle archive, ZipEntry* entry, int fd) {
return ExtractToWriter(archive, entry, &writer);
}
const char* ErrorCodeString(int32_t error_code) {
// Make sure that the number of entries in kErrorMessages and ErrorCodes
// match.
static_assert((-kLastErrorCode + 1) == arraysize(kErrorMessages),
"(-kLastErrorCode + 1) != arraysize(kErrorMessages)");
const uint32_t idx = -error_code;
if (idx < arraysize(kErrorMessages)) {
return kErrorMessages[idx];
}
return "Unknown return code";
}
int GetFileDescriptor(const ZipArchiveHandle archive) {
return archive->mapped_zip.GetFileDescriptor();
}

View file

@ -0,0 +1,50 @@
/*
* Copyright (C) 2008 The Android Open Source Project
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "zip_error.h"
#include <android-base/macros.h>
static const char* kErrorMessages[] = {
"Success",
"Iteration ended",
"Zlib error",
"Invalid file",
"Invalid handle",
"Duplicate entries in archive",
"Empty archive",
"Entry not found",
"Invalid offset",
"Inconsistent information",
"Invalid entry name",
"I/O error",
"File mapping failed",
"Allocation failed",
};
const char* ErrorCodeString(int32_t error_code) {
// Make sure that the number of entries in kErrorMessages and the ZipError
// enum match.
static_assert((-kLastErrorCode + 1) == arraysize(kErrorMessages),
"(-kLastErrorCode + 1) != arraysize(kErrorMessages)");
const uint32_t idx = -error_code;
if (idx < arraysize(kErrorMessages)) {
return kErrorMessages[idx];
}
return "Unknown return code";
}

View file

@ -18,23 +18,6 @@
#include <stdint.h>
static const char* kErrorMessages[] = {
"Success",
"Iteration ended",
"Zlib error",
"Invalid file",
"Invalid handle",
"Duplicate entries in archive",
"Empty archive",
"Entry not found",
"Invalid offset",
"Inconsistent information",
"Invalid entry name",
"I/O error",
"File mapping failed",
"Allocation failed",
};
enum ZipError : int32_t {
kSuccess = 0,