J. Duke | 319a3b9 | 2007-12-01 00:00:00 +0000 | [diff] [blame^] | 1 | /* |
| 2 | * Copyright 2001-2004 Sun Microsystems, Inc. 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. Sun designates this |
| 8 | * particular file as subject to the "Classpath" exception as provided |
| 9 | * by Sun in the LICENSE file that accompanied this code. |
| 10 | * |
| 11 | * This code is distributed in the hope that it will be useful, but WITHOUT |
| 12 | * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
| 14 | * version 2 for more details (a copy is included in the LICENSE file that |
| 15 | * accompanied this code). |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License version |
| 18 | * 2 along with this work; if not, write to the Free Software Foundation, |
| 19 | * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
| 20 | * |
| 21 | * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 22 | * CA 95054 USA or visit www.sun.com if you need additional information or |
| 23 | * have any questions. |
| 24 | */ |
| 25 | |
| 26 | // random definitions |
| 27 | |
| 28 | #ifdef _MSC_VER |
| 29 | #include <windows.h> |
| 30 | #include <winuser.h> |
| 31 | #else |
| 32 | #include <unistd.h> |
| 33 | #endif |
| 34 | |
| 35 | #ifndef FULL |
| 36 | #define FULL 1 /* Adds <500 bytes to the zipped final product. */ |
| 37 | #endif |
| 38 | |
| 39 | #if FULL // define this if you want debugging and/or compile-time attributes |
| 40 | #define IF_FULL(x) x |
| 41 | #else |
| 42 | #define IF_FULL(x) /*x*/ |
| 43 | #endif |
| 44 | |
| 45 | #ifdef PRODUCT |
| 46 | #define IF_PRODUCT(xxx) xxx |
| 47 | #define NOT_PRODUCT(xxx) |
| 48 | #define assert(p) (0) |
| 49 | #define printcr false && |
| 50 | #else |
| 51 | #define IF_PRODUCT(xxx) |
| 52 | #define NOT_PRODUCT(xxx) xxx |
| 53 | #define assert(p) ((p) || (assert_failed(#p), 1)) |
| 54 | #define printcr u->verbose && u->printcr_if_verbose |
| 55 | extern "C" void breakpoint(); |
| 56 | extern void assert_failed(const char*); |
| 57 | #define BREAK (breakpoint()) |
| 58 | #endif |
| 59 | |
| 60 | // Build-time control of some C++ inlining. |
| 61 | // To make a slightly faster smaller binary, say "CC -Dmaybe_inline=inline" |
| 62 | #ifndef maybe_inline |
| 63 | #define maybe_inline /*inline*/ |
| 64 | #endif |
| 65 | // By marking larger member functions inline, we remove external linkage. |
| 66 | #ifndef local_inline |
| 67 | #define local_inline inline |
| 68 | #endif |
| 69 | |
| 70 | // Error messages that we have |
| 71 | #define ERROR_ENOMEM "Native allocation failed" |
| 72 | #define ERROR_FORMAT "Corrupted pack file" |
| 73 | #define ERROR_RESOURCE "Cannot extract resource file" |
| 74 | #define ERROR_OVERFLOW "Internal buffer overflow" |
| 75 | #define ERROR_INTERNAL "Internal error" |
| 76 | |
| 77 | #define LOGFILE_STDOUT "-" |
| 78 | #define LOGFILE_STDERR "" |
| 79 | |
| 80 | #define lengthof(array) (sizeof(array)/sizeof(array[0])) |
| 81 | |
| 82 | #define NEW(T, n) (T*) must_malloc(sizeof(T)*(n)) |
| 83 | #define U_NEW(T, n) (T*) u->alloc(sizeof(T)*(n)) |
| 84 | #define T_NEW(T, n) (T*) u->temp_alloc(sizeof(T)*(n)) |
| 85 | |
| 86 | |
| 87 | // bytes and byte arrays |
| 88 | |
| 89 | typedef unsigned int uint; |
| 90 | #ifdef _LP64 |
| 91 | typedef unsigned int uLong; // Historical zlib, should be 32-bit. |
| 92 | #else |
| 93 | typedef unsigned long uLong; |
| 94 | #endif |
| 95 | #ifdef _MSC_VER |
| 96 | typedef LONGLONG jlong; |
| 97 | typedef DWORDLONG julong; |
| 98 | #define MKDIR(dir) mkdir(dir) |
| 99 | #define getpid() _getpid() |
| 100 | #define PATH_MAX MAX_PATH |
| 101 | #define dup2(a,b) _dup2(a,b) |
| 102 | #define strcasecmp(s1, s2) _stricmp(s1,s2) |
| 103 | #define tempname _tempname |
| 104 | #define sleep Sleep |
| 105 | #else |
| 106 | typedef signed char byte; |
| 107 | #ifdef _LP64 |
| 108 | typedef long jlong; |
| 109 | typedef long unsigned julong; |
| 110 | #else |
| 111 | typedef long long jlong; |
| 112 | typedef long long unsigned julong; |
| 113 | #endif |
| 114 | #define MKDIR(dir) mkdir(dir, 0777); |
| 115 | #endif |
| 116 | |
| 117 | #ifdef OLDCC |
| 118 | typedef int bool; |
| 119 | enum { false, true }; |
| 120 | #endif |
| 121 | |
| 122 | #define null (0) |
| 123 | |
| 124 | #ifndef __sparc |
| 125 | #define intptr_t jlong |
| 126 | #endif |
| 127 | |
| 128 | #define ptrlowbits(x) ((int) (intptr_t)(x)) |
| 129 | |
| 130 | |
| 131 | // Keys used by Java: |
| 132 | #define UNPACK_DEFLATE_HINT "unpack.deflate.hint" |
| 133 | |
| 134 | #define COM_PREFIX "com.sun.java.util.jar.pack." |
| 135 | #define UNPACK_MODIFICATION_TIME COM_PREFIX"unpack.modification.time" |
| 136 | #define DEBUG_VERBOSE COM_PREFIX"verbose" |
| 137 | |
| 138 | #define ZIP_ARCHIVE_MARKER_COMMENT "PACK200" |
| 139 | |
| 140 | // The following are not known to the Java classes: |
| 141 | #define UNPACK_LOG_FILE COM_PREFIX"unpack.log.file" |
| 142 | #define UNPACK_REMOVE_PACKFILE COM_PREFIX"unpack.remove.packfile" |
| 143 | |
| 144 | |
| 145 | // Called from unpacker layers |
| 146 | #define _CHECK_DO(t,x) { if (t) {x;} } |
| 147 | |
| 148 | #define CHECK _CHECK_DO(aborting(), return) |
| 149 | #define CHECK_(y) _CHECK_DO(aborting(), return y) |
| 150 | #define CHECK_0 _CHECK_DO(aborting(), return 0) |
| 151 | |
| 152 | #define CHECK_NULL(p) _CHECK_DO((p)==null, return) |
| 153 | #define CHECK_NULL_(y,p) _CHECK_DO((p)==null, return y) |
| 154 | #define CHECK_NULL_0(p) _CHECK_DO((p)==null, return 0) |
| 155 | |
| 156 | #define STR_TRUE "true" |
| 157 | #define STR_FALSE "false" |
| 158 | |
| 159 | #define STR_TF(x) ((x) ? STR_TRUE : STR_FALSE) |
| 160 | #define BOOL_TF(x) (((x) != null && strcmp((x),STR_TRUE) == 0) ? true : false) |
| 161 | |
| 162 | #define DEFAULT_ARCHIVE_MODTIME 1060000000 // Aug 04, 2003 5:26 PM PDT |