1 /*
 2  * Copyright (c) 2023, Oracle and/or its affiliates. All rights reserved.
 3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
 4  *
 5  * This code is free software; you can redistribute it and/or modify it
 6  * under the terms of the GNU General Public License version 2 only, as
 7  * published by the Free Software Foundation.
 8  *
 9  * This code is distributed in the hope that it will be useful, but WITHOUT
10  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
12  * version 2 for more details (a copy is included in the LICENSE file that
13  * accompanied this code).
14  *
15  * You should have received a copy of the GNU General Public License version
16  * 2 along with this work; if not, write to the Free Software Foundation,
17  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
18  *
19  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
20  * or visit www.oracle.com if you need additional information or have any
21  * questions.
22  *
23  */
24 
25 #ifndef SHARE_UTILITIES_ZIPLIBRARY_HPP
26 #define SHARE_UTILITIES_ZIPLIBRARY_HPP
27 
28 #include "memory/allocation.hpp"
29 
30  // Type definitions for zip file and zip file entry
31 typedef void* jzfile;
32 typedef struct {
33   char* name;                   /* entry name */
34   jlong time;                   /* modification time */
35   jlong size;                   /* size of uncompressed data */
36   jlong csize;                  /* size of compressed data (zero if uncompressed) */
37   jint crc;                     /* crc of uncompressed data */
38   char* comment;                /* optional zip file comment */
39   jbyte* extra;                 /* optional extra data */
40   jlong pos;                    /* position of LOC header (if negative) or data */
41 } jzentry;
42 
43 class ZipLibrary : AllStatic {
44  public:
45   static void** open(const char* name, char** pmsg);
46   static void close(jzfile* zip);
47   static jzentry* find_entry(jzfile* zip, const char* name, jint* sizeP, jint* nameLen);
48   static jboolean read_entry(jzfile* zip, jzentry* entry, unsigned char* buf, char* namebuf);
49   static void free_entry(jzfile* zip, jzentry* entry);
50   static jint crc32(jint crc, const jbyte* buf, jint len);
51   static const char* init_params(size_t block_size, size_t* needed_out_size, size_t* needed_tmp_size, int level);
52   static size_t compress(char* in, size_t in_size, char* out, size_t out_size, char* tmp, size_t tmp_size, int level, char* buf, const char** pmsg);
53   static void* handle();
54 };
55 
56 #endif // SHARE_UTILITIES_ZIPLIBRARY_HPP