Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/os2/os2.c view on Meta::CPAN
PPIB pppib;
char *szPath;
DosGetInfoBlocks(&pptib, &pppib);
szPath = pppib -> pib_pchenv;
#else /* 16-bit, note: requires large data model */
SEL selEnv;
USHORT offCmd;
char *szPath;
DosGetEnv(&selEnv, &offCmd);
szPath = MAKEP(selEnv, 0);
#endif
while (*szPath) /* find end of process environment */
szPath = strchr(szPath, 0) + 1;
return szPath + 1; /* .exe file name follows environment */
} /* end function GetLoadPath() */
#else /* !SFX */
DIR *opendir(__GPRO__ const char *name)
{
struct stat statb;
DIR *dirp;
char c;
char *s;
struct _dircontents *dp;
char nbuf[MAXPATHLEN + 1];
int len;
strcpy(nbuf, name);
if ((len = strlen(nbuf)) == 0)
return NULL;
if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len > 1) )
{
nbuf[len - 1] = 0;
--len;
if ( nbuf[len - 1] == ':' )
{
strcpy(nbuf+len, "\\.");
len += 2;
}
}
else
if ( nbuf[len - 1] == ':' )
{
strcpy(nbuf+len, ".");
++len;
}
/* GRR: Borland and Watcom C return non-zero on wildcards... < 0 ? */
if (stat(nbuf, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
{
Trace((stderr, "opendir: stat(%s) returns negative or not directory\n",
FnFilter1(nbuf)));
return NULL;
}
if ( (dirp = malloc(sizeof(DIR))) == NULL )
return NULL;
if ( nbuf[len - 1] == '.' && (len == 1 || nbuf[len - 2] != '.') )
strcpy(nbuf+len-1, "*");
else
if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len == 1) )
strcpy(nbuf+len, "*");
else
strcpy(nbuf+len, "\\*");
/* len is no longer correct (but no longer needed) */
Trace((stderr, "opendir: nbuf = [%s]\n", FnFilter1(nbuf)));
dirp -> dd_loc = 0;
dirp -> dd_contents = dirp -> dd_cp = NULL;
if ((s = getdirent(__G__ nbuf)) == NULL)
return dirp;
do
{
if (((dp = malloc(sizeof(struct _dircontents))) == NULL) ||
((dp -> _d_entry = malloc(strlen(s) + 1)) == NULL) )
{
if (dp)
free(dp);
free_dircontents(dirp -> dd_contents);
return NULL;
}
if (dirp -> dd_contents)
{
dirp -> dd_cp -> _d_next = dp;
dirp -> dd_cp = dirp -> dd_cp -> _d_next;
}
else
dirp -> dd_contents = dirp -> dd_cp = dp;
strcpy(dp -> _d_entry, s);
dp -> _d_next = NULL;
dp -> _d_size = G.os2.find.cbFile;
dp -> _d_mode = G.os2.find.attrFile;
dp -> _d_time = *(unsigned *) &(G.os2.find.ftimeLastWrite);
dp -> _d_date = *(unsigned *) &(G.os2.find.fdateLastWrite);
}
while ((s = getdirent(__G__ NULL)) != NULL);
dirp -> dd_cp = dirp -> dd_contents;
return dirp;
}
unzip-6.0/os2/os2.c view on Meta::CPAN
char *pathcomp;
int flag;
/*
* returns:
* MPN_OK - no problem detected
* MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
* MPN_INF_SKIP - path doesn't exist, not allowed to create
* MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
* exists and is not a directory, but is supposed to be
* MPN_ERR_TOOLONG - path is too long
* MPN_NOMEM - can't allocate memory for filename buffers
*/
{
/* moved to os2data.h so they can be global */
#if 0
static int rootlen = 0; /* length of rootpath */
static char *rootpath; /* user's "extract-to" directory */
static char *buildpathHPFS; /* full path (so far) to extracted file, */
static char *buildpathFAT; /* both HPFS/EA (main) and FAT versions */
static char *endHPFS; /* corresponding pointers to end of */
static char *endFAT; /* buildpath ('\0') */
#endif
# define FN_MASK 7
# define FUNCTION (flag & FN_MASK)
/*---------------------------------------------------------------------------
APPEND_DIR: append the path component to the path being built and check
for its existence. If doesn't exist and we are creating directories, do
so for this one; else signal success or error as appropriate.
---------------------------------------------------------------------------*/
if (FUNCTION == APPEND_DIR) {
char *p = pathcomp;
int longdirEA, too_long=FALSE;
Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
while ((*G.os2.endHPFS = *p++) != '\0') /* copy to HPFS filename */
++G.os2.endHPFS;
if (IsFileNameValid(G.os2.buildpathHPFS)) {
longdirEA = FALSE;
p = pathcomp;
while ((*G.os2.endFAT = *p++) != '\0') /* copy to FAT filename, too */
++G.os2.endFAT;
} else {
longdirEA = TRUE;
/* GRR: check error return? */
map2fat(pathcomp, &G.os2.endFAT); /* map, put in FAT fn, update endFAT */
}
/* GRR: could do better check, see if overrunning buffer as we go:
* check endHPFS-G.os2.buildpathHPFS after each append, set warning variable
* if within 20 of FILNAMSIZ; then if var set, do careful check when
* appending. Clear variable when begin new path. */
/* next check: need to append '/', at least one-char name, '\0' */
if ((G.os2.endHPFS-G.os2.buildpathHPFS) > FILNAMSIZ-3)
too_long = TRUE; /* check if extracting dir? */
#ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
if (GetFileTime(G.os2.buildpathFAT) == -1 || stat(G.os2.buildpathFAT, &G.statbuf))
#else
if (stat(G.os2.buildpathFAT, &G.statbuf)) /* path doesn't exist */
#endif
{
if (!G.create_dirs) { /* told not to create (freshening) */
free(G.os2.buildpathHPFS);
free(G.os2.buildpathFAT);
/* path doesn't exist: nothing to do */
return MPN_INF_SKIP;
}
if (too_long) { /* GRR: should allow FAT extraction w/o EAs */
Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
FnFilter1(G.os2.buildpathHPFS)));
free(G.os2.buildpathHPFS);
free(G.os2.buildpathFAT);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
if (MKDIR(G.os2.buildpathFAT, 0777) == -1) { /* create the directory */
Info(slide, 1, ((char *)slide, LoadFarString(CantCreateDir),
FnFilter2(G.os2.buildpathFAT), FnFilter1(G.filename)));
free(G.os2.buildpathHPFS);
free(G.os2.buildpathFAT);
/* path didn't exist, tried to create, failed */
return MPN_ERR_SKIP;
}
G.os2.created_dir = TRUE;
/* only set EA if creating directory */
/* GRR: need trailing '/' before function call? */
if (longdirEA) {
#ifdef DEBUG
int e =
#endif
SetLongNameEA(G.os2.buildpathFAT, pathcomp);
Trace((stderr, "APPEND_DIR: SetLongNameEA() returns %d\n", e));
}
} else if (!S_ISDIR(G.statbuf.st_mode)) {
Info(slide, 1, ((char *)slide, LoadFarString(DirIsntDirectory),
FnFilter2(G.os2.buildpathFAT), FnFilter1(G.filename)));
free(G.os2.buildpathHPFS);
free(G.os2.buildpathFAT);
/* path existed but wasn't dir */
return MPN_ERR_SKIP;
}
if (too_long) {
Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
FnFilter1(G.os2.buildpathHPFS)));
free(G.os2.buildpathHPFS);
free(G.os2.buildpathFAT);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
*G.os2.endHPFS++ = '/';
*G.os2.endFAT++ = '/';
*G.os2.endHPFS = *G.os2.endFAT = '\0';
Trace((stderr, "buildpathHPFS now = [%s]\n",
FnFilter1(G.os2.buildpathHPFS)));
Trace((stderr, "buildpathFAT now = [%s]\n",
FnFilter1(G.os2.buildpathFAT)));
return MPN_OK;
} /* end if (FUNCTION == APPEND_DIR) */
unzip-6.0/os2/os2.c view on Meta::CPAN
free(G.os2.buildpathFAT);
return MPN_VOL_LABEL; /* skipping with message */
}
*G.os2.buildpathHPFS = '\0';
} else if (G.os2.renamed_fullpath) /* pathcomp = valid data */
strcpy(G.os2.buildpathHPFS, pathcomp);
else if (G.os2.rootlen > 0)
strcpy(G.os2.buildpathHPFS, G.os2.rootpath);
else
*G.os2.buildpathHPFS = '\0';
G.os2.endHPFS = G.os2.buildpathHPFS;
G.os2.endFAT = G.os2.buildpathFAT;
while ((*G.os2.endFAT = *G.os2.endHPFS) != '\0') {
++G.os2.endFAT;
++G.os2.endHPFS;
}
Trace((stderr, "[%s]\n", FnFilter1(G.os2.buildpathHPFS)));
return MPN_OK;
}
/*---------------------------------------------------------------------------
ROOT: if appropriate, store the path in rootpath and create it if neces-
sary; else assume it's a zipfile member and return. This path segment
gets used in extracting all members from every zipfile specified on the
command line. Note that under OS/2 and MS-DOS, if a candidate extract-to
directory specification includes a drive letter (leading "x:"), it is
treated just as if it had a trailing '/'--that is, one directory level
will be created if the path doesn't exist, unless this is otherwise pro-
hibited (e.g., freshening).
---------------------------------------------------------------------------*/
#if (!defined(SFX) || defined(SFX_EXDIR))
if (FUNCTION == ROOT) {
Trace((stderr, "initializing root path to [%s]\n",
FnFilter1(pathcomp)));
if (pathcomp == (char *)NULL) {
G.os2.rootlen = 0;
return MPN_OK;
}
if (G.os2.rootlen > 0) /* rootpath was already set, nothing to do */
return MPN_OK;
if ((G.os2.rootlen = strlen(pathcomp)) > 0) {
int had_trailing_pathsep=FALSE, has_drive=FALSE, add_dot=FALSE;
char *tmproot;
if ((tmproot = (char *)malloc(G.os2.rootlen+3)) == (char *)NULL) {
G.os2.rootlen = 0;
return MPN_NOMEM;
}
strcpy(tmproot, pathcomp);
if (isalpha((uch)tmproot[0]) && tmproot[1] == ':')
has_drive = TRUE; /* drive designator */
if (tmproot[G.os2.rootlen-1] == '/') {
tmproot[--G.os2.rootlen] = '\0';
had_trailing_pathsep = TRUE;
}
if (has_drive && (G.os2.rootlen == 2)) {
if (!had_trailing_pathsep) /* i.e., original wasn't "x:/" */
add_dot = TRUE; /* relative path: add '.' before '/' */
} else if (G.os2.rootlen > 0) { /* need not check "x:." and "x:/" */
#ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
if (GetFileTime(tmproot) == -1 ||
SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))
#else
if (SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))
#endif
{ /* path does not exist */
if (!G.create_dirs /* || iswild(tmproot) */
) {
free(tmproot);
G.os2.rootlen = 0;
return MPN_INF_SKIP; /* treat as stored file */
}
/* create directory (could add loop here scanning tmproot
* to create more than one level, but really necessary?) */
if (MKDIR(tmproot, 0777) == -1) {
Info(slide, 1, ((char *)slide,
LoadFarString(CantCreateExtractDir),
FnFilter1(tmproot)));
free(tmproot);
G.os2.rootlen = 0;
/* path didn't exist, tried to create, failed: */
/* file exists, or need 2+ directory levels */
return MPN_ERR_SKIP;
}
}
}
if (add_dot) /* had just "x:", make "x:." */
tmproot[G.os2.rootlen++] = '.';
tmproot[G.os2.rootlen++] = '/';
tmproot[G.os2.rootlen] = '\0';
if ((G.os2.rootpath = realloc(tmproot, G.os2.rootlen+1)) == NULL) {
free(tmproot);
G.os2.rootlen = 0;
return MPN_NOMEM;
}
Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.os2.rootpath)));
}
return MPN_OK;
}
#endif /* !SFX || SFX_EXDIR */
/*---------------------------------------------------------------------------
END: free rootpath, immediately prior to program exit.
---------------------------------------------------------------------------*/
if (FUNCTION == END) {
Trace((stderr, "freeing rootpath\n"));
if (G.os2.rootlen > 0) {
free(G.os2.rootpath);
G.os2.rootlen = 0;
}
return MPN_OK;
}
return MPN_INVALID; /* should never reach */
} /* end function checkdir() */
( run in 2.616 seconds using v1.01-cache-2.11-cpan-2e0ccfb7a10 )