staticvoid usage() {
fprintf(stderr, "usage: bionic_tests_zipalign ALIGNMENT INPUT_ZIP_FILE OUTPUT_ZIP_FILE\n");
fprintf(stderr, " ALIGNMENT:\n");
fprintf(stderr, " The new alignment of all entries in the new zip file.\n");
fprintf(stderr, " INPUT_ZIP_FILE:\n");
fprintf(stderr, " The input zip file that will be read but left unmodified.\n");
fprintf(stderr, " OUTPUT_ZIP_FILE:\n");
fprintf(stderr, " The output zip file that will be created from the input file.\n");
}
using ZipData = std::pair<std::unique_ptr<ZipEntry>, std::string>;
staticbool GetEntries(ZipArchiveHandle handle, std::vector<ZipData>* entries) { void* cookie;
int32_t return_value = StartIteration(handle, &cookie); if (return_value != 0) {
fprintf(stderr, "Unable to iterate over entries: %s\n", ErrorCodeString(return_value)); returnfalse;
}
ZipEntry entry;
std::string name; while ((return_value = Next(cookie, &entry, &name)) == 0) {
entries->emplace_back(std::make_pair(std::make_unique<ZipEntry>(entry), name));
} if (return_value != -1) {
fprintf(stderr, "Error while iterating over zip entries: %s\n", ErrorCodeString(return_value));
} else { // Sort by offset.
std::sort(entries->begin(), entries->end(),
[](ZipData& a, ZipData& b) { return a.first->offset < b.first->offset; });
}
staticbool CreateAlignedZip(ZipArchiveHandle& handle, FILE* zip_dst, uint32_t alignment) {
std::vector<ZipData> entries; // We will not free the memory created in entries since the program // terminates right after this function is called. if (!GetEntries(handle, &entries)) { returnfalse;
}
int main(int argc, char* argv[]) { if (argc != 4) {
usage(); return1;
}
char* end; unsignedlongint alignment = strtoul(argv[1], &end, 10); if ((alignment == ULONG_MAX && errno == ERANGE) || *end != '\0') {
fprintf(stderr, "ALIGNMENT value is not a valid number: %s\n", argv[1]);
usage(); return1;
} if (!powerof2(alignment)) {
fprintf(stderr, "ALIGNMENT value is not a power of 2: %s\n", argv[1]); return1;
}
ZipArchiveHandle handle;
int32_t return_value = OpenArchive(argv[2], &handle); if (return_value != 0) {
CloseArchive(handle);
fprintf(stderr, "Unable to open '%s': %s\n", argv[2], ErrorCodeString(return_value)); return1;
}
FILE* zip_dst = fopen(argv[3], "we"); if (zip_dst == nullptr) {
fprintf(stderr, "Unable to create '%s': %m\n", argv[3]); return1;
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.