jdk/src/share/native/com/sun/java/util/jar/pack/zip.h
author ksrini
Wed, 09 May 2012 07:28:12 -0700
changeset 12680 289f842c0175
parent 5506 202f599c92aa
child 22575 0c2768190cf4
permissions -rw-r--r--
7166955: (pack200) JNI_GetCreatedJavaVMs needs additional checking Reviewed-by: alanb, dholmes, ksrini Contributed-by: youdwei@linux.vnet.ibm.com
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
     2
 * Copyright (c) 2001, 2008, Oracle and/or its affiliates. All rights reserved.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
     7
 * published by the Free Software Foundation.  Oracle designates this
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
     9
 * by Oracle in the LICENSE file that accompanied this code.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
5506
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    21
 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    22
 * or visit www.oracle.com if you need additional information or have any
202f599c92aa 6943119: Rebrand source copyright notices
ohair
parents: 1082
diff changeset
    23
 * questions.
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
#define ushort unsigned short
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
#define uint   unsigned int
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
#define uchar  unsigned char
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
struct unpacker;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
struct jar {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
  // JAR file writer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
  FILE*       jarfp;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
  int         default_modtime;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
  // Used by unix2dostime:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
  int         modtime_cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
  uLong       dostime_cache;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
  // Private members
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
  fillbytes   central_directory;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
  ushort      central_directory_count;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
  uint        output_file_offset;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
  fillbytes   deflated;  // temporary buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
  // pointer to outer unpacker, for error checks etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
  unpacker* u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
  // Public Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
  void openJarFile(const char* fname);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
  void addJarEntry(const char* fname,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
                   bool deflate_hint, int modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
                   bytes& head, bytes& tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
  void addDirectoryToJarFile(const char* dir_name);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
  void closeJarFile(bool central);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
  void init(unpacker* u_);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
  void free() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
    central_directory.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
    deflated.free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
  void reset() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
    free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
    init(u);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
  }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
  // Private Methods
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
  void write_data(void* ptr, int len);
1082
53833ff90c45 6496269: Many warnings generated from com/sun/java/util/jar/pack/*.cpp when compiled on Linux
ohair
parents: 2
diff changeset
    72
  void write_data(bytes& b) { write_data(b.ptr, (int)b.len); }
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
  void add_to_jar_directory(const char* fname, bool store, int modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
                            int len, int clen, uLong crc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
  void write_jar_header(const char* fname, bool store, int modtime,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
                        int len, int clen, unsigned int crc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
  void write_central_directory();
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
  uLong dostime(int y, int n, int d, int h, int m, int s);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
  uLong get_dostime(int modtime);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
  // The definitions of these depend on the NO_ZLIB option:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
  bool deflate_bytes(bytes& head, bytes& tail);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
  static uint get_crc32(uint c, unsigned char *ptr, uint len);
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
  // error handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
  void abort(const char* msg) { unpack_abort(msg, u); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
  bool aborting()             { return unpack_aborting(u); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
};
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
struct gunzip {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
  // optional gzip input stream control block
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
  // pointer to outer unpacker, for error checks etc.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
  unpacker* u;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
  void* read_input_fn;  // underlying byte stream
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
  void* zstream;        // inflater state
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
  char inbuf[1 << 14];   // input buffer
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
  void init(unpacker* u_);  // pushes new value on u->read_input_fn
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
  void free();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
  void start(int magic);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
  // private stuff
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
  void read_fixed_field(char* buf, size_t buflen);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
  // error handling
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
  void abort(const char* msg) { unpack_abort(msg, u); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
  bool aborting()             { return unpack_aborting(u); }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
};