Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/msdos/msdos.c view on Meta::CPAN
map2fat(pathcomp, last_dot); /* 8.3 truncation (in place) */
# endif
#endif
}
if (*pathcomp == '\0') {
Info(slide, 1, ((char *)slide, LoadFarString(ConversionFailed),
FnFilter1(G.filename)));
return (error & ~MPN_MASK) | MPN_ERR_SKIP;
}
checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
checkdir(__G__ G.filename, GETPATH);
if (G.pInfo->vollabel) { /* set the volume label now */
if (QCOND2)
Info(slide, 0, ((char *)slide, LoadFarString(Labelling),
(nLabelDrive + 'a' - 1),
FnFilter1(G.filename)));
if (volumelabel(G.filename)) {
Info(slide, 1, ((char *)slide, LoadFarString(ErrSetVolLabel)));
return (error & ~MPN_MASK) | MPN_ERR_SKIP;
}
/* success: skip the "extraction" quietly */
return (error & ~MPN_MASK) | MPN_INF_SKIP;
}
return error;
} /* end function mapname() */
/****************************/
/* Function maskDOSdevice() */
/****************************/
static void maskDOSdevice(__G__ pathcomp, last_dot)
__GDEF
char *pathcomp, *last_dot;
{
/*---------------------------------------------------------------------------
Put an underscore in front of the file name if the file name is a
DOS/WINDOWS device name like CON.*, AUX.*, PRN.*, etc. Trying to
extract such a file would fail at best and wedge us at worst.
---------------------------------------------------------------------------*/
#if !defined(S_IFCHR) && defined(_S_IFCHR)
# define S_IFCHR _S_IFCHR
#endif
#if !defined(S_ISCHR)
# if defined(_S_ISCHR)
# define S_ISCHR(m) _S_ISCHR(m)
# elif defined(S_IFCHR)
# define S_ISCHR(m) ((m) & S_IFCHR)
# endif
#endif
#ifdef DEBUG
if (stat(pathcomp, &G.statbuf) == 0) {
Trace((stderr,
"maskDOSdevice() stat(\"%s\", buf) st_mode result: %X, %o\n",
FnFilter1(pathcomp), G.statbuf.st_mode, G.statbuf.st_mode));
} else {
Trace((stderr, "maskDOSdevice() stat(\"%s\", buf) failed\n",
FnFilter1(pathcomp)));
}
#endif
if (stat(pathcomp, &G.statbuf) == 0 && S_ISCHR(G.statbuf.st_mode)) {
extent i;
/* pathcomp contains a name of a DOS character device (builtin or
* installed device driver).
* Prepend a '_' to allow creation of the item in the file system.
*/
for (i = strlen(pathcomp) + 1; i > 0; --i)
pathcomp[i] = pathcomp[i - 1];
pathcomp[0] = '_';
if (last_dot != (char *)NULL)
last_dot++;
}
} /* end function maskDOSdevice() */
#ifdef MAYBE_PLAIN_FAT
/**********************/
/* Function map2fat() */
/**********************/
static void map2fat(pathcomp, last_dot)
char *pathcomp, *last_dot;
{
char *pEnd = pathcomp + strlen(pathcomp);
/*---------------------------------------------------------------------------
Case 1: filename has no dot, so figure out if we should add one. Note
that the algorithm does not try to get too fancy: if there are no dots
already, the name either gets truncated at 8 characters or the last un-
derscore is converted to a dot (only if more characters are saved that
way). In no case is a dot inserted between existing characters.
GRR: have problem if filename is volume label??
---------------------------------------------------------------------------*/
if (last_dot == (char *)NULL) { /* no dots: check for underscores... */
char *plu = strrchr(pathcomp, '_'); /* pointer to last underscore */
if ((plu != (char *)NULL) && /* found underscore: convert to dot? */
(MIN(plu - pathcomp, 8) + MIN(pEnd - plu - 1, 3) > 8)) {
last_dot = plu; /* be lazy: drop through to next if-block */
} else if ((pEnd - pathcomp) > 8)
/* no underscore; or converting underscore to dot would save less
chars than leaving everything in the basename */
pathcomp[8] = '\0'; /* truncate at 8 chars */
/* else whole thing fits into 8 chars or less: no change */
}
/*---------------------------------------------------------------------------
Case 2: filename has dot in it, so truncate first half at 8 chars (shift
extension if necessary) and second half at three.
---------------------------------------------------------------------------*/
if (last_dot != (char *)NULL) { /* one dot is OK: */
*last_dot = '.'; /* put the last back in */
if ((last_dot - pathcomp) > 8) {
char *p, *q;
int i;
p = last_dot;
q = last_dot = pathcomp + 8;
for (i = 0; (i < 4) && *p; ++i) /* too many chars in basename: */
*q++ = *p++; /* shift extension left and */
*q = '\0'; /* truncate/terminate it */
} else if ((pEnd - last_dot) > 4)
last_dot[4] = '\0'; /* too many chars in extension */
/* else filename is fine as is: no change */
if ((last_dot - pathcomp) > 0 && last_dot[-1] == ' ')
last_dot[-1] = '_'; /* NO blank in front of '.'! */
}
} /* end function map2fat() */
#endif /* MAYBE_PLAIN_FAT */
/***********************/
/* Function checkdir() */
/***********************/
int checkdir(__G__ pathcomp, flag)
__GDEF
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
*/
{
static int rootlen = 0; /* length of rootpath */
static char *rootpath; /* user's "extract-to" directory */
static char *buildpath; /* full path (so far) to extracted file */
static char *end; /* pointer to end of buildpath ('\0') */
#ifdef MSC
int attrs; /* work around MSC stat() bug */
#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) {
int too_long = FALSE;
Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
while ((*end = *pathcomp++) != '\0')
++end;
/* GRR: could do better check, see if overrunning buffer as we go:
* check end-buildpath 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. */
if ((end-buildpath) > FILNAMSIZ-3) /* need '/', one-char name, '\0' */
too_long = TRUE; /* check if extracting directory? */
#ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
if (_dos_getfileattr(buildpath, &attrs) || stat(buildpath, &G.statbuf))
#else
if (SSTAT(buildpath, &G.statbuf)) /* path doesn't exist */
#endif
{
if (!G.create_dirs) { /* told not to create (freshening) */
free(buildpath);
/* path doesn't exist: nothing to do */
return MPN_INF_SKIP;
}
if (too_long) {
Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
FnFilter1(buildpath)));
free(buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
if (MKDIR(buildpath, 0777) == -1) { /* create the directory */
Info(slide, 1, ((char *)slide, LoadFarString(CantCreateDir),
FnFilter2(buildpath), FnFilter1(G.filename)));
free(buildpath);
/* path didn't exist, tried to create, failed */
return MPN_ERR_SKIP;
}
created_dir = TRUE;
} else if (!S_ISDIR(G.statbuf.st_mode)) {
Info(slide, 1, ((char *)slide, LoadFarString(DirIsntDirectory),
FnFilter2(buildpath), FnFilter1(G.filename)));
free(buildpath);
/* path existed but wasn't dir */
return MPN_ERR_SKIP;
}
if (too_long) {
Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
FnFilter1(buildpath)));
free(buildpath);
/* no room for filenames: fatal */
return MPN_ERR_TOOLONG;
}
*end++ = '/';
*end = '\0';
Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath)));
return MPN_OK;
} /* end if (FUNCTION == APPEND_DIR) */
/*---------------------------------------------------------------------------
GETPATH: copy full path to the string pointed at by pathcomp, and free
buildpath.
---------------------------------------------------------------------------*/
if (FUNCTION == GETPATH) {
strcpy(pathcomp, buildpath);
Trace((stderr, "getting and freeing path [%s]\n",
FnFilter1(pathcomp)));
free(buildpath);
buildpath = end = (char *)NULL;
return MPN_OK;
}
/*---------------------------------------------------------------------------
unzip-6.0/msdos/msdos.c view on Meta::CPAN
return MPN_VOL_LABEL; /* skipping with message */
}
*buildpath = '\0';
end = buildpath;
} else if (renamed_fullpath) { /* pathcomp = valid data */
end = buildpath;
while ((*end = *pathcomp++) != '\0')
++end;
} else if (rootlen > 0) {
strcpy(buildpath, rootpath);
end = buildpath + rootlen;
} else {
*buildpath = '\0';
end = buildpath;
}
Trace((stderr, "[%s]\n", FnFilter1(buildpath)));
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) {
rootlen = 0;
return MPN_OK;
}
if (rootlen > 0) /* rootpath was already set, nothing to do */
return MPN_OK;
if ((rootlen = strlen(pathcomp)) > 0) {
int had_trailing_pathsep=FALSE, has_drive=FALSE, add_dot=FALSE;
char *tmproot;
if ((tmproot = (char *)malloc(rootlen+3)) == (char *)NULL) {
rootlen = 0;
return MPN_NOMEM;
}
strcpy(tmproot, pathcomp);
if (isalpha((uch)tmproot[0]) && tmproot[1] == ':')
has_drive = TRUE; /* drive designator */
if (tmproot[rootlen-1] == '/' || tmproot[rootlen-1] == '\\') {
tmproot[--rootlen] = '\0';
had_trailing_pathsep = TRUE;
}
if (has_drive && (rootlen == 2)) {
if (!had_trailing_pathsep) /* i.e., original wasn't "x:/" */
add_dot = TRUE; /* relative path: add '.' before '/' */
} else if (rootlen > 0) { /* need not check "x:." and "x:/" */
#ifdef MSC
/* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
if (_dos_getfileattr(tmproot, &attrs) ||
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);
rootlen = 0;
/* treat as stored file */
return MPN_INF_SKIP;
}
/* GRR: scan for wildcard characters? OS-dependent... if find any, return 2:
* treat as stored file(s) */
/* 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);
rootlen = 0;
/* path didn't exist, tried to create, failed: */
/* file exists, or need 2+ subdir levels */
return MPN_ERR_SKIP;
}
}
}
if (add_dot) /* had just "x:", make "x:." */
tmproot[rootlen++] = '.';
tmproot[rootlen++] = '/';
tmproot[rootlen] = '\0';
if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {
free(tmproot);
rootlen = 0;
return MPN_NOMEM;
}
Trace((stderr, "rootpath now = [%s]\n", FnFilter1(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 (rootlen > 0) {
free(rootpath);
rootlen = 0;
}
return MPN_OK;
}
return MPN_INVALID; /* should never reach */
} /* end function checkdir() */
unzip-6.0/msdos/msdos.c view on Meta::CPAN
break;
case 5:
errno = EACCES;
break;
}
asm("1:");
return (unsigned)_doserrno;
}
unsigned _dos_close(int fd)
{
asm("movl %0, %%ebx": : "g" (fd));
asm("movl $0x3e00, %eax");
asm("int $0x21": : : "%eax", "%ebx", "%ecx", "%edx", "%esi", "%edi");
_doserrno = 0;
asm("jnc 1f");
asm ("movl %%eax, %0": "=m" (_doserrno));
if (_doserrno == 6) {
errno = EBADF;
}
asm("1:");
return (unsigned)_doserrno;
}
#endif /* !__DJGPP__ || (__DJGPP__ < 2) */
static int volumelabel(ZCONST char *name)
{
int fd;
return _dos_creat(name, FA_LABEL, &fd) ? fd : _dos_close(fd);
}
#if (defined(__DJGPP__) && (__DJGPP__ >= 2))
#include <dpmi.h> /* These includes for the country info */
#include <go32.h>
#include <sys/farptr.h>
/* The above _dos_getcountryinfo function doesn't work with djgpp v2, presumably
* because ds is not set correctly (does it really work at all?). Note that
* this version only sets the date (ie. CountryInfo[0]).
*/
unsigned _dos_getcountryinfo(void *countrybuffer)
{
__dpmi_regs regs;
regs.x.ax = 0x3800;
regs.x.dx = __tb & 0x0f;
regs.x.ds = (__tb >> 4) & 0xffff;
_doserrno = __dpmi_int(0x21, ®s);
*(ush*)countrybuffer = _farpeekw(_dos_ds, __tb & 0xfffff);
return (unsigned)_doserrno;
}
/* Disable determination of "x" bit in st_mode field for [f]stat() calls. */
int _is_executable (const char *path, int fhandle, const char *ext)
{
return 0;
}
#ifndef USE_DJGPP_GLOB
/* Prevent globbing of filenames. This gives the same functionality as
* "stubedit <program> globbing=no" did with DJGPP v1.
*/
char **__crt0_glob_function(char *_arg)
{
return NULL;
}
#endif /* !USE_DJGPP_GLOB */
#ifndef USE_DJGPP_ENV
/* Reduce the size of the executable and remove the functionality to read
* the program's environment from whatever $DJGPP points to.
*/
void __crt0_load_environment_file(char *_app_name)
{
}
#endif /* !USE_DJGPP_ENV */
#endif /* __DJGPP__ >= 2 */
#endif /* __GO32__ || __EMX__ */
static int getdoscodepage(void)
{
union REGS regs;
WREGS(regs,ax) = 0x6601;
#ifdef __EMX__
_int86(0x21, ®s, ®s);
if (WREGS(regs,flags) & 1)
#else
intdos(®s, ®s);
if (WREGS(regs,cflag))
#endif
{
Trace((stderr,
"error in DOS function 0x66 (AX = 0x%04x): default to 850...\n",
(unsigned int)(WREGS(regs,ax))));
return 858;
} else
return WREGS(regs,bx);
}
#ifdef __EMX__
#ifdef MORE
/*************************/
/* Function screensize() */
/*************************/
int screensize(int *tt_rows, int *tt_cols)
unzip-6.0/msdos/msdos.c view on Meta::CPAN
ush flags;
ush es,ds,fs,gs;
ush ip_ignored,cs_ignored;
ush sp,ss;
};
/* This function is used to call dos interrupts that may not be supported
* by some particular 32-bit DOS extender. It uses DPMI function 300h to
* simulate a real mode call of the interrupt. The caller is responsible
* for providing real mode addresses of any buffer areas used. The docs
* for PMODE/W imply that this should not be necessary for calling the DOS
* interrupts that it doesn't extend, but it crashes when this isn't used. */
static int int86x_realmode(int inter_no, union REGS *in,
union REGS *out, struct SREGS *seg)
{
union REGS local;
struct SREGS localseg;
struct RMINFO rmi;
int r;
rmi.eax = in->x.eax;
rmi.ebx = in->x.ebx;
rmi.ecx = in->x.ecx;
rmi.edx = in->x.edx;
rmi.edi = in->x.edi;
rmi.esi = in->x.esi;
rmi.ebp = rmi.reserved = 0L;
rmi.es = seg->es;
rmi.ds = seg->ds;
rmi.fs = seg->fs;
rmi.gs = seg->gs;
rmi.sp = rmi.ss = rmi.ip_ignored = rmi.cs_ignored = rmi.flags = 0;
memset(&local, 0, sizeof(local));
memset(&localseg, 0, sizeof(localseg));
local.w.ax = 0x0300;
local.h.bl = inter_no;
local.h.bh = 0;
local.w.cx = 0;
localseg.es = FP_SEG(&rmi);
local.x.edi = FP_OFF(&rmi);
r = int386x(0x31, &local, &local, &localseg);
out->x.eax = rmi.eax;
out->x.ebx = rmi.ebx;
out->x.ecx = rmi.ecx;
out->x.edx = rmi.edx;
out->x.edi = rmi.edi;
out->x.esi = rmi.esi;
out->x.cflag = rmi.flags & INTR_CF;
return r;
}
#endif /* WATCOMC_386 */
#ifdef DOS_STAT_BANDAID
/* This papers over a bug in Watcom 10.6's standard library...sigh.
* Apparently it applies to both the DOS and Win32 stat()s. */
int stat_bandaid(const char *path, struct stat *buf)
{
char newname[4];
if (!stat(path, buf))
return 0;
else if (!strcmp(path, ".") || (path[0] && !strcmp(path + 1, ":."))) {
strcpy(newname, path);
newname[strlen(path) - 1] = '\\'; /* stat(".") fails for root! */
return stat(newname, buf);
} else
return -1;
}
#endif /* DOS_STAT_BANDAID */
#endif /* !FUNZIP */
( run in 1.411 second using v1.01-cache-2.11-cpan-cdf2f3d4e48 )