Archive-Unzip-Burst
view release on metacpan or search on metacpan
unzip-6.0/unzip.c view on Meta::CPAN
{
#ifndef NO_ZIPINFO
char *p;
#endif
#if (defined(DOS_FLX_H68_NLM_OS2_W32) || !defined(SFX))
int i;
#endif
int retcode, error=FALSE;
#ifndef NO_EXCEPT_SIGNALS
#ifdef REENTRANT
savsigs_info *oldsighandlers = NULL;
# define SET_SIGHANDLER(sigtype, newsighandler) \
if ((retcode = setsignalhandler(__G__ &oldsighandlers, (sigtype), \
(newsighandler))) > PK_WARN) \
goto cleanup_and_exit
#else
# define SET_SIGHANDLER(sigtype, newsighandler) \
signal((sigtype), (newsighandler))
#endif
#endif /* NO_EXCEPT_SIGNALS */
/* initialize international char support to the current environment */
SETLOCALE(LC_CTYPE, "");
#ifdef UNICODE_SUPPORT
/* see if can use UTF-8 Unicode locale */
# ifdef UTF8_MAYBE_NATIVE
{
char *codeset;
# if !(defined(NO_NL_LANGINFO) || defined(NO_LANGINFO_H))
/* get the codeset (character set encoding) currently used */
# include <langinfo.h>
codeset = nl_langinfo(CODESET);
# else /* NO_NL_LANGINFO || NO_LANGINFO_H */
/* query the current locale setting for character classification */
codeset = setlocale(LC_CTYPE, NULL);
if (codeset != NULL) {
/* extract the codeset portion of the locale name */
codeset = strchr(codeset, '.');
if (codeset != NULL) ++codeset;
}
# endif /* ?(NO_NL_LANGINFO || NO_LANGINFO_H) */
/* is the current codeset UTF-8 ? */
if ((codeset != NULL) && (strcmp(codeset, "UTF-8") == 0)) {
/* successfully found UTF-8 char coding */
G.native_is_utf8 = TRUE;
} else {
/* Current codeset is not UTF-8 or cannot be determined. */
G.native_is_utf8 = FALSE;
}
/* Note: At least for UnZip, trying to change the process codeset to
* UTF-8 does not work. For the example Linux setup of the
* UnZip maintainer, a successful switch to "en-US.UTF-8"
* resulted in garbage display of all non-basic ASCII characters.
*/
}
# endif /* UTF8_MAYBE_NATIVE */
/* initialize Unicode */
G.unicode_escape_all = 0;
G.unicode_mismatch = 0;
G.unipath_version = 0;
G.unipath_checksum = 0;
G.unipath_filename = NULL;
#endif /* UNICODE_SUPPORT */
#if (defined(__IBMC__) && defined(__DEBUG_ALLOC__))
extern void DebugMalloc(void);
atexit(DebugMalloc);
#endif
#ifdef MALLOC_WORK
/* The following (rather complex) expression determines the allocation
size of the decompression work area. It simulates what the
combined "union" and "struct" declaration of the "static" work
area reservation achieves automatically at compile time.
Any decent compiler should evaluate this expression completely at
compile time and provide constants to the zcalloc() call.
(For better readability, some subexpressions are encapsulated
in temporarly defined macros.)
*/
# define UZ_SLIDE_CHUNK (sizeof(shrint)+sizeof(uch)+sizeof(uch))
# define UZ_NUMOF_CHUNKS \
(unsigned)(((WSIZE+UZ_SLIDE_CHUNK-1)/UZ_SLIDE_CHUNK > HSIZE) ? \
(WSIZE+UZ_SLIDE_CHUNK-1)/UZ_SLIDE_CHUNK : HSIZE)
G.area.Slide = (uch *)zcalloc(UZ_NUMOF_CHUNKS, UZ_SLIDE_CHUNK);
# undef UZ_SLIDE_CHUNK
# undef UZ_NUMOF_CHUNKS
G.area.shrink.Parent = (shrint *)G.area.Slide;
G.area.shrink.value = G.area.Slide + (sizeof(shrint)*(HSIZE));
G.area.shrink.Stack = G.area.Slide +
(sizeof(shrint) + sizeof(uch))*(HSIZE);
#endif
/*---------------------------------------------------------------------------
Set signal handler for restoring echo, warn of zipfile corruption, etc.
---------------------------------------------------------------------------*/
#ifndef NO_EXCEPT_SIGNALS
#ifdef SIGINT
SET_SIGHANDLER(SIGINT, handler);
#endif
#ifdef SIGTERM /* some systems really have no SIGTERM */
SET_SIGHANDLER(SIGTERM, handler);
#endif
#if defined(SIGABRT) && !(defined(AMIGA) && defined(__SASC))
SET_SIGHANDLER(SIGABRT, handler);
#endif
#ifdef SIGBREAK
SET_SIGHANDLER(SIGBREAK, handler);
#endif
#ifdef SIGBUS
SET_SIGHANDLER(SIGBUS, handler);
#endif
#ifdef SIGILL
SET_SIGHANDLER(SIGILL, handler);
#endif
#ifdef SIGSEGV
SET_SIGHANDLER(SIGSEGV, handler);
unzip-6.0/unzip.c view on Meta::CPAN
if (in_files) { /* ... zipfile ... -d exdir ... */
*pp = (char *)NULL; /* terminate G.pfnames */
G.filespecs = pp - G.pfnames;
in_files = FALSE;
} else if (in_xfiles) {
*pp = (char *)NULL; /* terminate G.pxnames */
G.xfilespecs = pp - G.pxnames;
/* "... -x xlist -d exdir": nothing left */
}
/* first check for "-dexdir", then for "-d exdir" */
if (*uO.exdir == '\0') {
if (*++pp)
uO.exdir = *pp;
else {
Info(slide, 0x401, ((char *)slide,
LoadFarString(MustGiveExdir)));
/* don't extract here by accident */
retcode = PK_PARAM;
goto cleanup_and_exit;
}
}
if (firstarg) { /* ... zipfile -d exdir ... */
if (pp[1]) {
G.pfnames = pp + 1; /* argv+2 */
G.filespecs = argc - (G.pfnames-argv); /* for now... */
} else {
G.process_all_files = TRUE;
G.pfnames = (char **)fnames; /* GRR: necessary? */
G.filespecs = 0; /* GRR: necessary? */
break;
}
}
} else if (!in_xfiles) {
if (strcmp(*pp, "-x") == 0) {
in_xfiles = TRUE;
if (pp == G.pfnames) {
G.pfnames = (char **)fnames; /* defaults */
G.filespecs = 0;
} else if (in_files) {
*pp = 0; /* terminate G.pfnames */
G.filespecs = pp - G.pfnames; /* adjust count */
in_files = FALSE;
}
G.pxnames = pp + 1; /* excluded-names ptr starts after -x */
G.xfilespecs = argc - (G.pxnames-argv); /* anything left */
} else
in_files = TRUE;
}
}
} else
G.process_all_files = TRUE; /* for speed */
if (uO.exdir != (char *)NULL && !G.extract_flag) /* -d ignored */
Info(slide, 0x401, ((char *)slide, LoadFarString(NotExtracting)));
#endif /* ?(SFX && !SFX_EXDIR) */
#ifdef UNICODE_SUPPORT
/* set Unicode-escape-all if option -U used */
if (uO.U_flag == 1)
# ifdef UNICODE_WCHAR
G.unicode_escape_all = TRUE;
# else
Info(slide, 0x401, ((char *)slide, LoadFarString(UTF8EscapeUnSupp)));
# endif
#endif
/*---------------------------------------------------------------------------
Okey dokey, we have everything we need to get started. Let's roll.
---------------------------------------------------------------------------*/
retcode = process_zipfiles(__G);
cleanup_and_exit:
#if (defined(REENTRANT) && !defined(NO_EXCEPT_SIGNALS))
/* restore all signal handlers back to their state at function entry */
while (oldsighandlers != NULL) {
savsigs_info *thissigsav = oldsighandlers;
signal(thissigsav->sigtype, thissigsav->sighandler);
oldsighandlers = thissigsav->previous;
free(thissigsav);
}
#endif
#if (defined(MALLOC_WORK) && !defined(REENTRANT))
if (G.area.Slide != (uch *)NULL) {
free(G.area.Slide);
G.area.Slide = (uch *)NULL;
}
#endif
#if (defined(MSDOS) && !defined(SFX) && !defined(WINDLL))
if (retcode != PK_OK)
check_for_windows("UnZip");
#endif
return(retcode);
} /* end main()/unzip() */
#if (defined(REENTRANT) && !defined(NO_EXCEPT_SIGNALS))
/*******************************/
/* Function setsignalhandler() */
/*******************************/
static int setsignalhandler(__G__ p_savedhandler_chain, signal_type,
newhandler)
__GDEF
savsigs_info **p_savedhandler_chain;
int signal_type;
void (*newhandler)(int);
{
savsigs_info *savsig;
savsig = malloc(sizeof(savsigs_info));
if (savsig == NULL) {
/* error message and break */
Info(slide, 0x401, ((char *)slide, LoadFarString(CantSaveSigHandler)));
return PK_MEM;
( run in 1.224 second using v1.01-cache-2.11-cpan-acf6aa7dc9e )