diff --git a/libziparchive/Android.bp b/libziparchive/Android.bp index 3d4e86e46..4081b21f4 100644 --- a/libziparchive/Android.bp +++ b/libziparchive/Android.bp @@ -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", ], diff --git a/libziparchive/zip_archive.cc b/libziparchive/zip_archive.cc index 2648c5948..b5a855a48 100644 --- a/libziparchive/zip_archive.cc +++ b/libziparchive/zip_archive.cc @@ -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(); } diff --git a/libziparchive/zip_error.cpp b/libziparchive/zip_error.cpp new file mode 100644 index 000000000..107ec4797 --- /dev/null +++ b/libziparchive/zip_error.cpp @@ -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 + +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"; +} diff --git a/libziparchive/zip_error.h b/libziparchive/zip_error.h index 44d7221c5..37fd55f38 100644 --- a/libziparchive/zip_error.h +++ b/libziparchive/zip_error.h @@ -18,23 +18,6 @@ #include -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,