1 /* 2 * Copyright (c) 2003, 2013, 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. Oracle designates this 8 * particular file as subject to the "Classpath" exception as provided 9 * by Oracle 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 Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA 22 * or visit www.oracle.com if you need additional information or have any 23 * 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 #define VERSION_STRING "%s version %s\n" 51 #else 52 #define IF_PRODUCT(xxx) 53 #define NOT_PRODUCT(xxx) xxx 54 #define assert(p) ((p) || (assert_failed(#p), 1)) 55 #define printcr u->verbose && u->printcr_if_verbose 56 #define VERSION_STRING "%s version non-product %s\n" 57 extern "C" void breakpoint(); 58 extern void assert_failed(const char*); 59 #define BREAK (breakpoint()) 60 #endif 61 62 // Build-time control of some C++ inlining. 63 // To make a slightly faster smaller binary, say "CC -Dmaybe_inline=inline" 64 #ifndef maybe_inline 65 #define maybe_inline /*inline*/ 66 #endif 67 // By marking larger member functions inline, we remove external linkage. 68 #ifndef local_inline 69 #define local_inline inline 70 #endif 71 72 // Error messages that we have 73 #define ERROR_ENOMEM "Native allocation failed" 74 #define ERROR_FORMAT "Corrupted pack file" 75 #define ERROR_RESOURCE "Cannot extract resource file" 76 #define ERROR_OVERFLOW "Internal buffer overflow" 77 #define ERROR_INTERNAL "Internal error" 78 79 #define LOGFILE_STDOUT "-" 80 #define LOGFILE_STDERR "" 81 82 #define lengthof(array) (sizeof(array)/sizeof(array[0])) 83 84 #define NEW(T, n) (T*) must_malloc(scale_size(n, sizeof(T))) 85 #define U_NEW(T, n) (T*) u->alloc(scale_size(n, sizeof(T))) 86 #define T_NEW(T, n) (T*) u->temp_alloc(scale_size(n, sizeof(T))) 87 88 89 // bytes and byte arrays 90 91 typedef unsigned int uint; 92 #ifdef _LP64 93 typedef unsigned int uLong; // Historical zlib, should be 32-bit. 94 #else 95 typedef unsigned long uLong; 96 #endif 97 #ifdef _MSC_VER 98 typedef LONGLONG jlong; 99 typedef DWORDLONG julong; 100 #define MKDIR(dir) mkdir(dir) 101 #define getpid() _getpid() 102 #define PATH_MAX MAX_PATH 103 #define dup2(a,b) _dup2(a,b) 104 #define strcasecmp(s1, s2) _stricmp(s1,s2) 105 #define tempname _tempname 106 #define sleep Sleep 107 #else 108 typedef signed char byte; 109 #ifdef _LP64 110 typedef long jlong; 111 typedef long unsigned julong; 112 #else 113 typedef long long jlong; 114 typedef long long unsigned julong; 115 #endif 116 #define MKDIR(dir) mkdir(dir, 0777); 117 #endif 118 119 #ifdef OLDCC 120 typedef int bool; 121 enum { false, true }; 122 #endif 123 124 #define null (0) 125 126 #ifndef __sparc 127 #define intptr_t jlong 128 #endif 129 130 #define ptrlowbits(x) ((int) (intptr_t)(x)) 131 132 /* Back and forth from jlong to pointer */ 133 #define ptr2jlong(x) ((jlong)(size_t)(void*)(x)) 134 #define jlong2ptr(x) ((void*)(size_t)(x)) 135 136 // Keys used by Java: 137 #define UNPACK_DEFLATE_HINT "unpack.deflate.hint" 138 139 #define COM_PREFIX "com.sun.java.util.jar.pack." 140 #define UNPACK_MODIFICATION_TIME COM_PREFIX"unpack.modification.time" 141 #define DEBUG_VERBOSE COM_PREFIX"verbose" 142 143 #define ZIP_ARCHIVE_MARKER_COMMENT "PACK200" 144 145 // The following are not known to the Java classes: 146 #define UNPACK_LOG_FILE COM_PREFIX"unpack.log.file" 147 #define UNPACK_REMOVE_PACKFILE COM_PREFIX"unpack.remove.packfile" 148 149 150 // Called from unpacker layers 151 #define _CHECK_DO(t,x) { if (t) {x;} } 152 153 #define CHECK _CHECK_DO(aborting(), return) 154 #define CHECK_(y) _CHECK_DO(aborting(), return y) 155 #define CHECK_0 _CHECK_DO(aborting(), return 0) 156 157 #define CHECK_NULL(p) _CHECK_DO((p)==null, return) 158 #define CHECK_NULL_(y,p) _CHECK_DO((p)==null, return y) 159 #define CHECK_NULL_0(p) _CHECK_DO((p)==null, return 0) 160 161 #define CHECK_COUNT(t) if (t < 0){abort("bad value count");} CHECK 162 163 #define STR_TRUE "true" 164 #define STR_FALSE "false" 165 166 #define STR_TF(x) ((x) ? STR_TRUE : STR_FALSE) 167 #define BOOL_TF(x) (((x) != null && strcmp((x),STR_TRUE) == 0) ? true : false) 168 169 #define DEFAULT_ARCHIVE_MODTIME 1060000000 // Aug 04, 2003 5:26 PM PDT