1 /*
2  * Copyright (c) 2001, 2016, 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 #ifdef _ALLBSD_SOURCE
36 #include <machine/endian.h>
37 #endif
38 
39 #ifndef NO_ZLIB
40 #include <zconf.h>
41 #endif
42 
43 #ifndef FULL
44 #define FULL 1 /* Adds <500 bytes to the zipped final product. */
45 #endif
46 
47 #if FULL  // define this if you want debugging and/or compile-time attributes
48 #define IF_FULL(x) x
49 #else
50 #define IF_FULL(x) /*x*/
51 #endif
52 
53 #ifdef PRODUCT
54 #define IF_PRODUCT(xxx) xxx
55 #define NOT_PRODUCT(xxx)
56 #define assert(p)
57 #define PRINTCR(args)
58 #define VERSION_STRING "%s version %s\n"
59 #else
60 #define IF_PRODUCT(xxx)
61 #define NOT_PRODUCT(xxx) xxx
62 #define assert(p) ((p) || assert_failed(#p))
63 #define PRINTCR(args)  u->verbose && u->printcr_if_verbose args
64 #define VERSION_STRING "%s version non-product %s\n"
65 extern "C" void breakpoint();
66 extern int assert_failed(const char*);
67 #define BREAK (breakpoint())
68 #endif
69 
70 // Build-time control of some C++ inlining.
71 // To make a slightly faster smaller binary, say "CC -Dmaybe_inline=inline"
72 #ifndef maybe_inline
73 #define maybe_inline /*inline*/
74 #endif
75 // By marking larger member functions inline, we remove external linkage.
76 #ifndef local_inline
77 #define local_inline inline
78 #endif
79 
80 // Error messages that we have
81 #define ERROR_ENOMEM    "Native allocation failed"
82 #define ERROR_FORMAT    "Corrupted pack file"
83 #define ERROR_RESOURCE  "Cannot extract resource file"
84 #define ERROR_OVERFLOW  "Internal buffer overflow"
85 #define ERROR_INTERNAL  "Internal error"
86 #define ERROR_INIT      "cannot init class members"
87 
88 #define LOGFILE_STDOUT "-"
89 #define LOGFILE_STDERR ""
90 
91 #define lengthof(array) (sizeof(array)/sizeof(array[0]))
92 
93 #define NEW(T, n)    (T*) must_malloc((int)(scale_size(n, sizeof(T))))
94 #define U_NEW(T, n)  (T*) u->alloc(scale_size(n, sizeof(T)))
95 #define T_NEW(T, n)  (T*) u->temp_alloc(scale_size(n, sizeof(T)))
96 
97 // Dealing with big-endian arch
98 #if (defined(_ALLBSD_SOURCE) && (BYTE_ORDER == BIG_ENDIAN)) || (!defined(_ALLBSD_SOURCE) && defined(_BIG_ENDIAN))
99 #define SWAP_INT(a) (((a>>24)&0xff) | ((a<<8)&0xff0000) | ((a>>8)&0xff00) | ((a<<24)&0xff000000))
100 #else
101 #define SWAP_INT(a) (a)
102 #endif
103 
104 // bytes and byte arrays
105 
106 typedef unsigned int uint;
107 #if defined(NO_ZLIB)
108 #ifdef _LP64
109 typedef unsigned int uLong; // Historical zlib, should be 32-bit.
110 #else
111 typedef unsigned long uLong;
112 #endif
113 #endif
114 #ifdef _MSC_VER
115 typedef LONGLONG        jlong;
116 typedef DWORDLONG       julong;
117 #define MKDIR(dir)      mkdir(dir)
118 #define getpid()        _getpid()
119 #define PATH_MAX        MAX_PATH
120 #define dup2(a,b)       _dup2(a,b)
121 #define strcasecmp(s1, s2) _stricmp(s1,s2)
122 #define tempname        _tempname
123 #define sleep           Sleep
124 #define snprintf        _snprintf
125 #define PATH_SEPARATOR '\\'
126 #else
127 typedef signed char byte;
128 #ifdef _LP64
129 typedef long jlong;
130 typedef long unsigned julong;
131 #else
132 typedef long long jlong;
133 typedef long long unsigned julong;
134 #endif
135 #define MKDIR(dir) mkdir(dir, 0777);
136 #define PATH_SEPARATOR '/'
137 #endif
138 
139 #ifdef OLDCC
140 typedef int bool;
141 enum { false, true };
142 #endif
143 
144 #define null (0)
145 
146 /* Must cast to void *, then size_t, then int. */
147 #define ptrlowbits(x)  ((int)(size_t)(void*)(x))
148 
149 /* Back and forth from jlong to pointer */
150 #define ptr2jlong(x)  ((jlong)(size_t)(void*)(x))
151 #define jlong2ptr(x)  ((void*)(size_t)(x))
152 
153 // Keys used by Java:
154 #define UNPACK_DEFLATE_HINT             "unpack.deflate.hint"
155 
156 #define COM_PREFIX                      "com.sun.java.util.jar.pack."
157 #define UNPACK_MODIFICATION_TIME        COM_PREFIX"unpack.modification.time"
158 #define DEBUG_VERBOSE                   COM_PREFIX"verbose"
159 
160 #define ZIP_ARCHIVE_MARKER_COMMENT      "PACK200"
161 
162 // The following are not known to the Java classes:
163 #define UNPACK_LOG_FILE                 COM_PREFIX"unpack.log.file"
164 #define UNPACK_REMOVE_PACKFILE          COM_PREFIX"unpack.remove.packfile"
165 
166 
167 // Called from unpacker layers
168 #define _CHECK_DO(t,x)          { if (t) {x;} }
169 
170 #define CHECK                   _CHECK_DO(aborting(), return)
171 #define CHECK_(y)               _CHECK_DO(aborting(), return y)
172 #define CHECK_0                 _CHECK_DO(aborting(), return 0)
173 
174 #define CHECK_COUNT(t)          if (t < 0){abort("bad value count");} CHECK
175 
176 #define STR_TRUE   "true"
177 #define STR_FALSE  "false"
178 
179 #define STR_TF(x)  ((x) ?  STR_TRUE : STR_FALSE)
180 #define BOOL_TF(x) (((x) != null && strcmp((x),STR_TRUE) == 0) ? true : false)
181 
182 #define DEFAULT_ARCHIVE_MODTIME 1060000000 // Aug 04, 2003 5:26 PM PDT
183