vfs: check userland buffers before reading them.
[haiku.git] / src / bin / unzip / globalsf.c
blob39956a52903ff041d162c5bf497cc195a97a548d
1 /*
2 Copyright (c) 1990-2000 Info-ZIP. All rights reserved.
4 See the accompanying file LICENSE, version 2000-Apr-09 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 /*---------------------------------------------------------------------------
11 globalsf.c
12 *** This is only needed to build funzip correctly and is a direct copy
13 of globals.c. Don't forget to update here if you update globals.c!! ***
15 ---------------------------------------------------------------------------*/
18 #define FUNZIP
19 #define UNZIP_INTERNAL
20 #include "unzip.h"
22 #ifndef FUNZIP
23 /* initialization of sigs is completed at runtime so unzip(sfx) executable
24 * won't look like a zipfile
26 char central_hdr_sig[4] = {0, 0, 0x01, 0x02};
27 char local_hdr_sig[4] = {0, 0, 0x03, 0x04};
28 char end_central_sig[4] = {0, 0, 0x05, 0x06};
29 /* extern char extd_local_sig[4] = {0, 0, 0x07, 0x08}; NOT USED YET */
31 ZCONST char *fnames[2] = {"*", NULL}; /* default filenames vector */
32 #endif
35 #ifndef REENTRANT
36 Uz_Globs G;
37 #else /* REENTRANT */
39 # ifndef USETHREADID
40 Uz_Globs *GG;
41 # else /* USETHREADID */
42 # define THREADID_ENTRIES 0x40
44 int lastScan;
45 Uz_Globs *threadPtrTable[THREADID_ENTRIES];
46 ulg threadIdTable [THREADID_ENTRIES] = {
47 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0,
48 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* Make sure there are */
49 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0, /* THREADID_ENTRIES 0s */
50 0,0,0,0, 0,0,0,0, 0,0,0,0, 0,0,0,0
53 static ZCONST char Far TooManyThreads[] =
54 "error: more than %d simultaneous threads.\n\
55 Some threads are probably not calling DESTROYTHREAD()\n";
56 static ZCONST char Far EntryNotFound[] =
57 "error: couldn't find global pointer in table.\n\
58 Maybe somebody accidentally called DESTROYTHREAD() twice.\n";
59 static ZCONST char Far GlobalPointerMismatch[] =
60 "error: global pointer in table does not match pointer passed as\
61 parameter\n";
63 static void registerGlobalPointer OF((__GPRO));
67 static void registerGlobalPointer(__G)
68 __GDEF
70 int scan=0;
71 ulg tid = GetThreadId();
73 while (threadIdTable[scan] && scan < THREADID_ENTRIES)
74 scan++;
76 if (scan == THREADID_ENTRIES) {
77 ZCONST char *tooMany = LoadFarString(TooManyThreads);
78 Info(slide, 0x421, ((char *)slide, tooMany, THREADID_ENTRIES));
79 free(pG);
80 EXIT(PK_MEM); /* essentially memory error before we've started */
83 threadIdTable [scan] = tid;
84 threadPtrTable[scan] = pG;
85 lastScan = scan;
90 void deregisterGlobalPointer(__G)
91 __GDEF
93 int scan=0;
94 ulg tid = GetThreadId();
97 while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
98 scan++;
100 /*---------------------------------------------------------------------------
101 There are two things we can do if we can't find the entry: ignore it or
102 scream. The most likely reason for it not to be here is the user calling
103 this routine twice. Since this could cause BIG problems if any globals
104 are accessed after the first call, we'd better scream.
105 ---------------------------------------------------------------------------*/
107 if (scan == THREADID_ENTRIES || threadPtrTable[scan] != pG) {
108 ZCONST char *noEntry;
109 if (scan == THREADID_ENTRIES)
110 noEntry = LoadFarString(EntryNotFound);
111 else
112 noEntry = LoadFarString(GlobalPointerMismatch);
113 Info(slide, 0x421, ((char *)slide, noEntry));
114 EXIT(PK_WARN); /* programming error, but after we're all done */
117 threadIdTable [scan] = 0;
118 lastScan = scan;
119 free(threadPtrTable[scan]);
124 Uz_Globs *getGlobalPointer()
126 int scan=0;
127 ulg tid = GetThreadId();
129 while (threadIdTable[scan] != tid && scan < THREADID_ENTRIES)
130 scan++;
132 /*---------------------------------------------------------------------------
133 There are two things we can do if we can't find the entry: ignore it or
134 scream. The most likely reason for it not to be here is the user calling
135 this routine twice. Since this could cause BIG problems if any globals
136 are accessed after the first call, we'd better scream.
137 ---------------------------------------------------------------------------*/
139 if (scan == THREADID_ENTRIES) {
140 ZCONST char *noEntry = LoadFarString(EntryNotFound);
141 fprintf(stderr, noEntry); /* can't use Info w/o a global pointer */
142 EXIT(PK_ERR); /* programming error while still working */
145 return threadPtrTable[scan];
148 # endif /* ?USETHREADID */
149 #endif /* ?REENTRANT */
153 Uz_Globs *globalsCtor()
155 #ifdef REENTRANT
156 Uz_Globs *pG = (Uz_Globs *)malloc(sizeof(Uz_Globs));
158 if (!pG)
159 return (Uz_Globs *)NULL;
160 #endif /* REENTRANT */
162 /* for REENTRANT version, G is defined as (*pG) */
164 memzero(&G, sizeof(Uz_Globs));
166 #ifndef FUNZIP
167 #ifdef CMS_MVS
168 uO.aflag=1;
169 uO.C_flag=1;
170 #endif
171 #ifdef TANDEM
172 uO.aflag=1; /* default to '-a' auto create Text Files as type 101 */
173 #endif
175 uO.lflag=(-1);
176 G.wildzipfn = "";
177 G.pfnames = (char **)fnames;
178 G.pxnames = (char **)&fnames[1];
179 G.pInfo = G.info;
180 G.sol = TRUE; /* at start of line */
182 G.message = UzpMessagePrnt;
183 G.input = UzpInput; /* not used by anyone at the moment... */
184 #if defined(WINDLL) || defined(MACOS)
185 G.mpause = NULL; /* has scrollbars: no need for pausing */
186 #else
187 G.mpause = UzpMorePause;
188 #endif
189 G.decr_passwd = UzpPassword;
190 #endif /* !FUNZIP */
192 #if (!defined(DOS_FLX_H68_NLM_OS2_W32) && !defined(AMIGA) && !defined(RISCOS))
193 #if (!defined(MACOS) && !defined(ATARI) && !defined(VMS))
194 G.echofd = -1;
195 #endif /* !(MACOS || ATARI || VMS) */
196 #endif /* !(DOS_FLX_H68_NLM_OS2_W32 || AMIGA || RISCOS) */
198 #ifdef SYSTEM_SPECIFIC_CTOR
199 SYSTEM_SPECIFIC_CTOR(__G);
200 #endif
202 #ifdef REENTRANT
203 #ifdef USETHREADID
204 registerGlobalPointer(__G);
205 #else
206 GG = &G;
207 #endif /* ?USETHREADID */
208 #endif /* REENTRANT */
210 return &G;