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