1 /*
2 * @(#)sys_support.c 1.7 01/01/18
3 *
4 * Copyright 1995-1999 by Sun Microsystems, Inc.,
5 * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
6 * All rights reserved.
7 *
8 * This software is the confidential and proprietary information
9 * of Sun Microsystems, Inc. ("Confidential Information"). You
10 * shall not disclose such Confidential Information and shall use
11 * it only in accordance with the terms of the license agreement
12 * you entered into with Sun.
13 * Use is subject to license terms.
14 */
16 /*=========================================================================
17 * SYSTEM: Verifier
18 * SUBSYSTEM: System support functions
19 * FILE: sys_support.c
20 * OVERVIEW: Routines for system support functions. The routines
21 * are for retrieving system class path and for certain
22 * Windows specific file parsing functions.
23 *
24 * AUTHOR: Sheng Liang, Sun Microsystems, Inc.
25 * Modifications for JAR support and comments,
26 * Tasneem Sayeed, Sun Microsystems, Inc.
27 *=======================================================================*/
29 /*=========================================================================
30 * Include files
31 *=======================================================================*/
33 #include <stdio.h>
34 #include <stdlib.h>
35 #include <string.h>
36 //#include <errno.h>
44 /*=========================================================================
45 * Globals and extern declarations
46 *=======================================================================*/
53 /*=========================================================================
54 * FUNCTION: sysGetClassPath
55 * OVERVIEW: Returns the system class path using the getenv() system
56 * call for retrieving the CLASSPATH environment.
57 * INTERFACE:
58 * parameters: none
59 *
60 * returns: Pointer to cpe_t struct ptr (see path.h)
61 *=======================================================================*/
62 cpe_t **
64 {
76 }
79 }
82 ncpe++;
83 }
84 }
85 /* We add 2 since we automatically append "." to the list, and we
86 * need a NULL element at the end.
87 * We add an extra 10 to allow pushing and popping of the classpath.
88 * Generally, we'll need two, at most, but we can afford to be
89 * a little extravagant.
90 */
94 }
100 }
103 }
107 }
112 }
114 /* we don't have to do anything */
116 /* this is a directory */
121 }
123 /* restore only for a valid directory */
130 /* this looks like a JAR file */
131 /* initialize the zip structure */
136 /* Create the zip entry for searching the JAR
137 * directories. If the zip entry is NULL, it
138 * would indicate that we ran out of memory
139 * and would have exited already.
140 */
143 /* search for the JAR directories */
145 /* this is a JAR file - initialize the cpe */
153 /* restore entry only for a valid JAR */
155 }
156 }
157 }
163 }
166 }
169 }
172 /* Puts this directory at the beginning of the class path */
174 void
176 {
185 /* Note that saved_classpath_end points to the NULL at the end. */
186 saved_classpath_end++;
189 }
191 }
194 /* Puts this jar file at the beginning of the class path */
196 void
198 {
207 /* Note that saved_classpath_end points to the NULL at the end. */
208 saved_classpath_end++;
211 }
213 }
216 /* Pop the first element off the class path */
217 void
219 {
226 /* This copies all of the elements, including the NULL at the end */
228 }
229 }
232 /*=========================================================================
233 * Win32 file parsing functions
234 *=======================================================================*/
236 #ifdef WIN32
241 #define islb(c) (IsDBCSLeadByte((BYTE)(c)))
244 /*=========================================================================
245 * FUNCTION: sysNativePath
246 * OVERVIEW: Converts a path name to native format. On win32, this
247 * involves forcing all separators to be '\\' rather than '/'
248 * (both are legal inputs, but Win95 sometimes rejects '/')
249 * and removing redundant separators. The input path is assumed
250 * to have been converted into the character encoding used by
251 * the local system. Because this might be a double-byte
252 * encoding, care is taken to treat double-byte lead characters
253 * correctly.
254 *
255 * INTERFACE:
256 * parameters: char *path
257 *
258 * returns: char *
259 *=======================================================================*/
262 {
265 point to the colon following the drive
266 letter */
268 /* Assumption: '/', '\\', ':', and drive letters are never lead bytes */
271 /* Check for leading separators */
274 /* Remove leading separators if followed by drive specifier. This
275 hack is necessary to support file URLs containing drive
276 specifiers (e.g., "file://c:/path"). As a side effect,
277 "/c:/path" can be used as an alternative to "c:/path". */
284 /* UNC pathname: Retain first separator; leave src pointed at
285 second separator so that further separators will be collapsed
286 into the second separator. The result will be a pathname
287 beginning with "\\\\" followed (most likely) by a host name. */
290 }
291 }
293 /* Remove redundant separators from remainder of path, forcing all
294 separators to be '\\' rather than '/' */
303 /* "\\\\" is not collapsed to "\\" because "\\\\" marks the
304 beginning of a UNC pathname. Even though it is not, by
305 itself, a valid UNC pathname, we leave it as is in order
306 to be consistent with sysCanonicalPath() (below) as well
307 as the win32 APIs, which treat this case as an invalid
308 UNC pathname rather than as an alias for the root
309 directory of the current drive. */
311 }
313 remove trailing separator */
315 }
321 }
324 }
325 }
326 }
329 #ifdef DEBUG_PATH
333 }
336 /*=========================================================================
337 * FUNCTION: opendir
338 * OVERVIEW: open directory given dir pointer.
339 *
340 * INTERFACE:
341 * parameters: const char *dirarg
342 *
343 * returns: Pointer to DIR structure
344 *=======================================================================*/
347 {
355 // errno = ENOMEM;
357 }
362 /*
363 * Win32 accepts "\" in its POSIX stat(), but refuses to treat it
364 * as a directory in FindFirstFile(). We detect this case here and
365 * prepend the current drive name.
366 */
373 }
378 // errno = ENOMEM;
380 }
387 // errno = ENOENT;
392 // errno = ENOTDIR;
394 }
396 /* Append "*.*", or possibly "\\*.*", to path */
400 /* No '\\' needed for cases like "Z:" or "Z:\" */
404 }
411 // errno = EACCES;
413 }
414 }
416 }
419 /*=========================================================================
420 * FUNCTION: readdir
421 * OVERVIEW: read directory given pointer to DIR structure.
422 *
423 * INTERFACE:
424 * parameters: DIR *dirp
425 *
426 * returns: Pointer to dirent structure.
427 *=======================================================================*/
430 {
433 }
439 // errno = EBADF;
441 }
444 }
447 }
450 /*=========================================================================
451 * FUNCTION: closedir
452 * OVERVIEW: close directory given pointer to DIR structure.
453 * Returns non-zero status if the close fails.
454 *
455 * INTERFACE:
456 * parameters: DIR: *dirp
457 *
458 * returns: int: status
459 *=======================================================================*/
460 int
462 {
465 // errno = EBADF;
467 }
469 }
473 }
475 #endif