forked from sskaje/unzip-lzfse
-
Notifications
You must be signed in to change notification settings - Fork 0
/
globals.c
222 lines (172 loc) · 6.34 KB
/
globals.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
/*
Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
See the accompanying file LICENSE, version 2003-May-08 or later
(the contents of which are also included in unzip.h) for terms of use.
If, for some reason, all these files are missing, the Info-ZIP license
also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
*/
/*---------------------------------------------------------------------------
globals.c
Routines to allocate and initialize globals, with or without threads.
Contents: registerGlobalPointer()
deregisterGlobalPointer()
getGlobalPointer()
globalsCtor()
---------------------------------------------------------------------------*/
#define UNZIP_INTERNAL
#include "unzip.h"
#ifndef FUNZIP
/* initialization of sigs is completed at runtime so unzip(sfx) executable
* won't look like a zipfile
*/
char central_hdr_sig[4] = {0, 0, 0x01, 0x02};
char local_hdr_sig[4] = {0, 0, 0x03, 0x04};
char end_central_sig[4] = {0, 0, 0x05, 0x06};
char end_central64_sig[4] = {0, 0, 0x06, 0x06};
char end_centloc64_sig[4] = {0, 0, 0x06, 0x07};
/* extern char extd_local_sig[4] = {0, 0, 0x07, 0x08}; NOT USED YET */
ZCONST char *fnames[2] = {"*", NULL}; /* default filenames vector */
#endif
#ifndef REENTRANT
Uz_Globs G;
#else /* REENTRANT */
# ifndef USETHREADID
Uz_Globs *GG;
# else /* USETHREADID */
# define THREADID_ENTRIES 0x40
int lastScan;
Uz_Globs *threadPtrTable[THREADID_ENTRIES];
ulg threadIdTable [THREADID_ENTRIES] = {
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* Make sure there are */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* THREADID_ENTRIES 0s */
0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
};
static ZCONST char Far TooManyThreads[] =
"error: more than %d simultaneous threads.\n\
Some threads are probably not calling DESTROYTHREAD()\n";
static ZCONST char Far EntryNotFound[] =
"error: couldn't find global pointer in table.\n\
Maybe somebody accidentally called DESTROYTHREAD() twice.\n";
static ZCONST char Far GlobalPointerMismatch[] =
"error: global pointer in table does not match pointer passed as\
parameter\n";
static void registerGlobalPointer OF((__GPRO));
static void registerGlobalPointer(__G)
__GDEF
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] && scan < THREADID_ENTRIES)
scan++;
if (scan == THREADID_ENTRIES) {
ZCONST char *tooMany = LoadFarString(TooManyThreads);
Info(slide, 0x421, ((char *)slide, tooMany, THREADID_ENTRIES));
free(pG);
EXIT(PK_MEM); /* essentially memory error before we've started */
}
threadIdTable [scan] = tid;
threadPtrTable[scan] = pG;
lastScan = scan;
}
void deregisterGlobalPointer(__G)
__GDEF
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
scan++;
/*---------------------------------------------------------------------------
There are two things we can do if we can't find the entry: ignore it or
scream. The most likely reason for it not to be here is the user calling
this routine twice. Since this could cause BIG problems if any globals
are accessed after the first call, we'd better scream.
---------------------------------------------------------------------------*/
if (scan == THREADID_ENTRIES || threadPtrTable[scan] != pG) {
ZCONST char *noEntry;
if (scan == THREADID_ENTRIES)
noEntry = LoadFarString(EntryNotFound);
else
noEntry = LoadFarString(GlobalPointerMismatch);
Info(slide, 0x421, ((char *)slide, noEntry));
EXIT(PK_WARN); /* programming error, but after we're all done */
}
threadIdTable [scan] = 0;
lastScan = scan;
free(threadPtrTable[scan]);
}
Uz_Globs *getGlobalPointer()
{
int scan=0;
ulg tid = GetThreadId();
while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
scan++;
/*---------------------------------------------------------------------------
There are two things we can do if we can't find the entry: ignore it or
scream. The most likely reason for it not to be here is the user calling
this routine twice. Since this could cause BIG problems if any globals
are accessed after the first call, we'd better scream.
---------------------------------------------------------------------------*/
if (scan == THREADID_ENTRIES) {
ZCONST char *noEntry = LoadFarString(EntryNotFound);
fprintf(stderr, noEntry); /* can't use Info w/o a global pointer */
EXIT(PK_ERR); /* programming error while still working */
}
return threadPtrTable[scan];
}
# endif /* ?USETHREADID */
#endif /* ?REENTRANT */
Uz_Globs *globalsCtor()
{
#ifdef REENTRANT
Uz_Globs *pG = (Uz_Globs *)malloc(sizeof(Uz_Globs));
if (!pG)
return (Uz_Globs *)NULL;
#endif /* REENTRANT */
/* for REENTRANT version, G is defined as (*pG) */
memzero(&G, sizeof(Uz_Globs));
#ifndef FUNZIP
#ifdef CMS_MVS
uO.aflag=1;
uO.C_flag=1;
#endif
#ifdef TANDEM
uO.aflag=1; /* default to '-a' auto create Text Files as type 101 */
#endif
#ifdef VMS
# if (!defined(NO_TIMESTAMPS))
uO.D_flag=1; /* default to '-D', no restoration of dir timestamps */
# endif
#endif
uO.lflag=(-1);
G.wildzipfn = "";
G.pfnames = (char **)fnames;
G.pxnames = (char **)&fnames[1];
G.pInfo = G.info;
G.sol = TRUE; /* at start of line */
G.message = UzpMessagePrnt;
G.input = UzpInput; /* not used by anyone at the moment... */
#if defined(WINDLL) || defined(MACOS)
G.mpause = NULL; /* has scrollbars: no need for pausing */
#else
G.mpause = UzpMorePause;
#endif
G.decr_passwd = UzpPassword;
#endif /* !FUNZIP */
#if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
#if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
G.echofd = -1;
#endif /* !(MACOS || ATARI || VMS) */
#endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
#ifdef SYSTEM_SPECIFIC_CTOR
SYSTEM_SPECIFIC_CTOR(__G);
#endif
#ifdef REENTRANT
#ifdef USETHREADID
registerGlobalPointer(__G);
#else
GG = &G;
#endif /* ?USETHREADID */
#endif /* REENTRANT */
return &G;
}