123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856 |
- #define __FILEIO_C
- #define UNZIP_INTERNAL
- #include "unzip.h"
- #ifdef WINDLL
- # ifdef POCKET_UNZIP
- # include "wince/intrface.h"
- # else
- # include "windll/windll.h"
- # endif
- # include <setjmp.h>
- #endif
- #include "crc32.h"
- #include "crypt.h"
- #include "ttyio.h"
- #if CRYPT
- # if (defined(CRYP_USES_ISO2OEM) && !defined(IZ_ISO2OEM_ARRAY))
- # define IZ_ISO2OEM_ARRAY
- # endif
- # if (defined(CRYP_USES_OEM2ISO) && !defined(IZ_OEM2ISO_ARRAY))
- # define IZ_OEM2ISO_ARRAY
- # endif
- #endif
- #include "ebcdic.h"
- #ifdef WINDLL
- # define WriteError(buf,len,strm) \
- (win_fprintf(pG, strm, (extent)len, (char far *)buf) != (int)(len))
- #else
- # ifdef USE_FWRITE
- # define WriteError(buf,len,strm) \
- ((extent)fwrite((char *)(buf),1,(extent)(len),strm) != (extent)(len))
- # else
- # define WriteError(buf,len,strm) \
- ((extent)write(fileno(strm),(char *)(buf),(extent)(len)) != (extent)(len))
- # endif
- #endif
- #ifdef VMS
- # define WriteTxtErr(buf,len,strm) \
- ((extent)fprintf(strm, "%.*s", len, buf) != (extent)(len))
- #else
- # define WriteTxtErr(buf,len,strm) WriteError(buf,len,strm)
- #endif
- #if (defined(USE_DEFLATE64) && defined(__16BIT__))
- static int partflush OF((__GPRO__ uch *rawbuf, ulg size, int unshrink));
- #endif
- #ifdef VMS_TEXT_CONV
- static int is_vms_varlen_txt OF((__GPRO__ uch *ef_buf, unsigned ef_len));
- #endif
- static int disk_error OF((__GPRO));
- static ZCONST char Far CannotOpenZipfile[] =
- "error: cannot open zipfile [ %s ]\n %s\n";
- #if (!defined(VMS) && !defined(AOS_VS) && !defined(CMS_MVS) && !defined(MACOS))
- #if (!defined(TANDEM))
- #if (defined(ATH_BEO_THS_UNX) || defined(DOS_FLX_NLM_OS2_W32))
- static ZCONST char Far CannotDeleteOldFile[] =
- "error: cannot delete old %s\n %s\n";
- #ifdef UNIXBACKUP
- static ZCONST char Far CannotRenameOldFile[] =
- "error: cannot rename old %s\n %s\n";
- static ZCONST char Far BackupSuffix[] = "~";
- #endif
- #endif
- #ifdef NOVELL_BUG_FAILSAFE
- static ZCONST char Far NovellBug[] =
- "error: %s: stat() says does not exist, but fopen() found anyway\n";
- #endif
- static ZCONST char Far CannotCreateFile[] =
- "error: cannot create %s\n %s\n";
- #endif
- #endif
- static ZCONST char Far ReadError[] = "error: zipfile read error\n";
- static ZCONST char Far FilenameTooLongTrunc[] =
- "warning: filename too long--truncating.\n";
- #ifdef UNICODE_SUPPORT
- static ZCONST char Far UFilenameTooLongTrunc[] =
- "warning: Converted unicode filename too long--truncating.\n";
- #endif
- static ZCONST char Far ExtraFieldTooLong[] =
- "warning: extra field too long (%d). Ignoring...\n";
- #ifdef WINDLL
- static ZCONST char Far DiskFullQuery[] =
- "%s: write error (disk full?).\n";
- #else
- static ZCONST char Far DiskFullQuery[] =
- "%s: write error (disk full?). Continue? (y/n/^C) ";
- static ZCONST char Far ZipfileCorrupt[] =
- "error: zipfile probably corrupt (%s)\n";
- # ifdef SYMLINKS
- static ZCONST char Far FileIsSymLink[] =
- "%s exists and is a symbolic link%s.\n";
- # endif
- # ifdef MORE
- static ZCONST char Far MorePrompt[] = "--More--(%lu)";
- # endif
- static ZCONST char Far QuitPrompt[] =
- "--- Press `Q' to quit, or any other key to continue ---";
- static ZCONST char Far HidePrompt[] =
- "\r \r";
- # if CRYPT
- # ifdef MACOS
-
- static ZCONST char Far PasswPrompt[] = "[%s]\n %s password: ";
- # else
- static ZCONST char Far PasswPrompt[] = "[%s] %s password: ";
- # endif
- static ZCONST char Far PasswPrompt2[] = "Enter password: ";
- static ZCONST char Far PasswRetry[] = "password incorrect--reenter: ";
- # endif
- #endif
- int open_input_file(__G)
- __GDEF
- {
-
- #ifdef VMS
- G.zipfd = open(G.zipfn, O_RDONLY, 0, OPNZIP_RMS_ARGS);
- #else
- #ifdef MACOS
- G.zipfd = open(G.zipfn, 0);
- #else
- #ifdef CMS_MVS
- G.zipfd = vmmvs_open_infile(__G);
- #else
- #ifdef USE_STRM_INPUT
- G.zipfd = fopen(G.zipfn, FOPR);
- #else
- G.zipfd = open(G.zipfn, O_RDONLY | O_BINARY);
- #endif
- #endif
- #endif
- #endif
- #ifdef USE_STRM_INPUT
- if (G.zipfd == NULL)
- #else
-
- if (G.zipfd == -1)
- #endif
- {
- Info(slide, 0x401, ((char *)slide, LoadFarString(CannotOpenZipfile),
- G.zipfn, strerror(errno)));
- return 1;
- }
- return 0;
- }
- #if (!defined(VMS) && !defined(AOS_VS) && !defined(CMS_MVS) && !defined(MACOS))
- #if (!defined(TANDEM))
- int open_outfile(__G)
- __GDEF
- {
- #ifdef DLL
- if (G.redirect_data)
- return (redirect_outfile(__G) == FALSE);
- #endif
- #ifdef QDOS
- QFilename(__G__ G.filename);
- #endif
- #if (defined(DOS_FLX_NLM_OS2_W32) || defined(ATH_BEO_THS_UNX))
- #ifdef BORLAND_STAT_BUG
-
- if (access(G.filename, 0) == -1) {
- FILE *tmp = fopen(G.filename, "wb+");
-
- fputc('0', tmp);
- fclose(tmp);
- }
- #endif
- #ifdef SYMLINKS
- if (SSTAT(G.filename, &G.statbuf) == 0 ||
- lstat(G.filename, &G.statbuf) == 0)
- #else
- if (SSTAT(G.filename, &G.statbuf) == 0)
- #endif
- {
- Trace((stderr, "open_outfile: stat(%s) returns 0: file exists\n",
- FnFilter1(G.filename)));
- #ifdef UNIXBACKUP
- if (uO.B_flag) {
- char *tname;
- z_stat tmpstat;
- int blen, flen, tlen;
- blen = strlen(BackupSuffix);
- flen = strlen(G.filename);
- tlen = flen + blen + 6;
- if (tlen >= FILNAMSIZ) {
- tname = (char *)malloc(FILNAMSIZ);
- if (tname == NULL)
- return 1;
- tlen = FILNAMSIZ - 1 - blen;
- strcpy(tname, G.filename);
- tname[tlen] = '\0';
- if (flen > tlen) flen = tlen;
- tlen = FILNAMSIZ;
- } else {
- tname = (char *)malloc(tlen);
- if (tname == NULL)
- return 1;
- strcpy(tname, G.filename);
- }
- strcpy(tname+flen, BackupSuffix);
- if (IS_OVERWRT_ALL) {
-
- if (SSTAT(tname, &tmpstat) == 0)
- unlink(tname);
- } else {
-
- unsigned maxtail, i;
- char *numtail = tname + flen + blen;
-
- maxtail = ( ((~0) >= 99999L) ? 99999 : (~0) );
- switch (tlen - flen - blen - 1) {
- case 4: maxtail = 9999; break;
- case 3: maxtail = 999; break;
- case 2: maxtail = 99; break;
- case 1: maxtail = 9; break;
- case 0: maxtail = 0; break;
- }
-
- for (i = 0; (i < maxtail) && (SSTAT(tname, &tmpstat) == 0);)
- sprintf(numtail,"%u", ++i);
- }
- if (rename(G.filename, tname) != 0) {
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(CannotRenameOldFile),
- FnFilter1(G.filename), strerror(errno)));
- free(tname);
- return 1;
- }
- Trace((stderr, "open_outfile: %s now renamed into %s\n",
- FnFilter1(G.filename), FnFilter2(tname)));
- free(tname);
- } else
- #endif
- {
- #ifdef DOS_FLX_OS2_W32
- if (!(G.statbuf.st_mode & S_IWRITE)) {
- Trace((stderr,
- "open_outfile: existing file %s is read-only\n",
- FnFilter1(G.filename)));
- chmod(G.filename, S_IREAD | S_IWRITE);
- Trace((stderr, "open_outfile: %s now writable\n",
- FnFilter1(G.filename)));
- }
- #endif
- #ifdef NLM
-
- chmod(G.filename, 0);
- #endif
- if (unlink(G.filename) != 0) {
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(CannotDeleteOldFile),
- FnFilter1(G.filename), strerror(errno)));
- return 1;
- }
- Trace((stderr, "open_outfile: %s now deleted\n",
- FnFilter1(G.filename)));
- }
- }
- #endif
- #ifdef RISCOS
- if (SWI_OS_File_7(G.filename,0xDEADDEAD,0xDEADDEAD,G.lrec.ucsize)!=NULL) {
- Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
- FnFilter1(G.filename), strerror(errno)));
- return 1;
- }
- #endif
- #ifdef TOPS20
- char *tfilnam;
- if ((tfilnam = (char *)malloc(2*strlen(G.filename)+1)) == (char *)NULL)
- return 1;
- strcpy(tfilnam, G.filename);
- upper(tfilnam);
- enquote(tfilnam);
- if ((G.outfile = fopen(tfilnam, FOPW)) == (FILE *)NULL) {
- Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
- tfilnam, strerror(errno)));
- free(tfilnam);
- return 1;
- }
- free(tfilnam);
- #else
- #ifdef MTS
- if (uO.aflag)
- G.outfile = zfopen(G.filename, FOPWT);
- else
- G.outfile = zfopen(G.filename, FOPW);
- if (G.outfile == (FILE *)NULL) {
- Info(slide, 1, ((char *)slide, LoadFarString(CannotCreateFile),
- FnFilter1(G.filename), strerror(errno)));
- return 1;
- }
- #else
- #ifdef DEBUG
- Info(slide, 1, ((char *)slide,
- "open_outfile: doing fopen(%s) for reading\n", FnFilter1(G.filename)));
- if ((G.outfile = zfopen(G.filename, FOPR)) == (FILE *)NULL)
- Info(slide, 1, ((char *)slide,
- "open_outfile: fopen(%s) for reading failed: does not exist\n",
- FnFilter1(G.filename)));
- else {
- Info(slide, 1, ((char *)slide,
- "open_outfile: fopen(%s) for reading succeeded: file exists\n",
- FnFilter1(G.filename)));
- fclose(G.outfile);
- }
- #endif
- #ifdef NOVELL_BUG_FAILSAFE
- if (G.dne && ((G.outfile = zfopen(G.filename, FOPR)) != (FILE *)NULL)) {
- Info(slide, 0x401, ((char *)slide, LoadFarString(NovellBug),
- FnFilter1(G.filename)));
- fclose(G.outfile);
- return 1;
- }
- #endif
- Trace((stderr, "open_outfile: doing fopen(%s) for writing\n",
- FnFilter1(G.filename)));
- {
- #if defined(ATH_BE_UNX) || defined(AOS_VS) || defined(QDOS) || defined(TANDEM)
- mode_t umask_sav = umask(0077);
- #endif
- #if defined(SYMLINKS) || defined(QLZIP)
-
- G.outfile = zfopen(G.filename, FOPWR);
- #else
- G.outfile = zfopen(G.filename, FOPW);
- #endif
- #if defined(ATH_BE_UNX) || defined(AOS_VS) || defined(QDOS) || defined(TANDEM)
- umask(umask_sav);
- #endif
- }
- if (G.outfile == (FILE *)NULL) {
- Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),
- FnFilter1(G.filename), strerror(errno)));
- return 1;
- }
- Trace((stderr, "open_outfile: fopen(%s) for writing succeeded\n",
- FnFilter1(G.filename)));
- #endif
- #endif
- #ifdef USE_FWRITE
- #ifdef DOS_NLM_OS2_W32
-
- setbuf(G.outfile, (char *)NULL);
- #else
- #ifndef RISCOS
- #ifdef _IOFBF
- setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);
- #else
- setbuf(G.outfile, (char *)slide);
- #endif
- #endif
- #endif
- #endif
- #ifdef OS2_W32
-
- SetFileSize(G.outfile, G.lrec.ucsize);
- #endif
- return 0;
- }
- #endif
- #endif
- void undefer_input(__G)
- __GDEF
- {
- if (G.incnt > 0)
- G.csize += G.incnt;
- if (G.incnt_leftover > 0) {
-
- G.incnt = G.incnt_leftover + (int)G.csize;
- G.inptr = G.inptr_leftover - (int)G.csize;
- G.incnt_leftover = 0;
- } else if (G.incnt < 0)
- G.incnt = 0;
- }
- void defer_leftover_input(__G)
- __GDEF
- {
- if ((zoff_t)G.incnt > G.csize) {
-
- if (G.csize < 0L)
- G.csize = 0L;
- G.inptr_leftover = G.inptr + (int)G.csize;
- G.incnt_leftover = G.incnt - (int)G.csize;
- G.incnt = (int)G.csize;
- } else
- G.incnt_leftover = 0;
- G.csize -= G.incnt;
- }
- unsigned readbuf(__G__ buf, size)
- __GDEF
- char *buf;
- register unsigned size;
- {
- register unsigned count;
- unsigned n;
- n = size;
- while (size) {
- if (G.incnt <= 0) {
- if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) == 0)
- return (n-size);
- else if (G.incnt < 0) {
-
- (*G.message)((zvoid *)&G,
- (uch *)LoadFarString(ReadError),
- (ulg)strlen(LoadFarString(ReadError)), 0x401);
- return 0;
- }
-
- G.cur_zipfile_bufstart += INBUFSIZ;
- G.inptr = G.inbuf;
- }
- count = MIN(size, (unsigned)G.incnt);
- memcpy(buf, G.inptr, count);
- buf += count;
- G.inptr += count;
- G.incnt -= count;
- size -= count;
- }
- return n;
- }
- int readbyte(__G)
- __GDEF
- {
- if (G.mem_mode)
- return EOF;
- if (G.csize <= 0) {
- G.csize--;
- G.incnt = 0;
- return EOF;
- }
- if (G.incnt <= 0) {
- if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) == 0) {
- return EOF;
- } else if (G.incnt < 0) {
-
- (*G.message)((zvoid *)&G,
- (uch *)LoadFarString(ReadError),
- (ulg)strlen(LoadFarString(ReadError)), 0x401);
- echon();
- #ifdef WINDLL
- longjmp(dll_error_return, 1);
- #else
- DESTROYGLOBALS();
- EXIT(PK_BADERR);
- #endif
- }
- G.cur_zipfile_bufstart += INBUFSIZ;
- G.inptr = G.inbuf;
- defer_leftover_input(__G);
- }
- #if CRYPT
- if (G.pInfo->encrypted) {
- uch *p;
- int n;
-
- for (n = G.incnt, p = G.inptr; n--; p++)
- zdecode(*p);
- }
- #endif
- --G.incnt;
- return *G.inptr++;
- }
- #if defined(USE_ZLIB) || defined(USE_BZIP2)
- int fillinbuf(__G)
- __GDEF
- {
- if (G.mem_mode ||
- (G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
- return 0;
- G.cur_zipfile_bufstart += INBUFSIZ;
- G.inptr = G.inbuf;
- defer_leftover_input(__G);
- #if CRYPT
- if (G.pInfo->encrypted) {
- uch *p;
- int n;
- for (n = G.incnt, p = G.inptr; n--; p++)
- zdecode(*p);
- }
- #endif
- return G.incnt;
- }
- #endif
- int seek_zipf(__G__ abs_offset)
- __GDEF
- zoff_t abs_offset;
- {
- zoff_t request = abs_offset + G.extra_bytes;
- zoff_t inbuf_offset = request % INBUFSIZ;
- zoff_t bufstart = request - inbuf_offset;
- if (request < 0) {
- Info(slide, 1, ((char *)slide, LoadFarStringSmall(SeekMsg),
- G.zipfn, LoadFarString(ReportMsg)));
- return(PK_BADERR);
- } else if (bufstart != G.cur_zipfile_bufstart) {
- Trace((stderr,
- "fpos_zip: abs_offset = %s, G.extra_bytes = %s\n",
- FmZofft(abs_offset, NULL, NULL),
- FmZofft(G.extra_bytes, NULL, NULL)));
- #ifdef USE_STRM_INPUT
- zfseeko(G.zipfd, bufstart, SEEK_SET);
- G.cur_zipfile_bufstart = zftello(G.zipfd);
- #else
- G.cur_zipfile_bufstart = zlseek(G.zipfd, bufstart, SEEK_SET);
- #endif
- Trace((stderr,
- " request = %s, (abs+extra) = %s, inbuf_offset = %s\n",
- FmZofft(request, NULL, NULL),
- FmZofft((abs_offset+G.extra_bytes), NULL, NULL),
- FmZofft(inbuf_offset, NULL, NULL)));
- Trace((stderr, " bufstart = %s, cur_zipfile_bufstart = %s\n",
- FmZofft(bufstart, NULL, NULL),
- FmZofft(G.cur_zipfile_bufstart, NULL, NULL)));
- if ((G.incnt = read(G.zipfd, (char *)G.inbuf, INBUFSIZ)) <= 0)
- return(PK_EOF);
- G.incnt -= (int)inbuf_offset;
- G.inptr = G.inbuf + (int)inbuf_offset;
- } else {
- G.incnt += (G.inptr-G.inbuf) - (int)inbuf_offset;
- G.inptr = G.inbuf + (int)inbuf_offset;
- }
- return(PK_OK);
- }
- #ifndef VMS
-
-
- int flush(__G__ rawbuf, size, unshrink)
- __GDEF
- uch *rawbuf;
- ulg size;
- int unshrink;
- #if (defined(USE_DEFLATE64) && defined(__16BIT__))
- {
- int ret;
-
- while (size > 0x8000L) {
- ret = partflush(__G__ rawbuf, 0x8000L, unshrink);
- if (ret != PK_OK)
- return ret;
- size -= 0x8000L;
- rawbuf += (extent)0x8000;
- }
- return partflush(__G__ rawbuf, size, unshrink);
- }
-
-
- static int partflush(__G__ rawbuf, size, unshrink)
- __GDEF
- uch *rawbuf;
- ulg size;
- int unshrink;
- #endif
- {
- register uch *p;
- register uch *q;
- uch *transbuf;
- #if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
- ulg transbufsiz;
- #endif
-
- G.crc32val = crc32(G.crc32val, rawbuf, (extent)size);
- #ifdef DLL
- if ((G.statreportcb != NULL) &&
- (*G.statreportcb)(__G__ UZ_ST_IN_PROGRESS, G.zipfn, G.filename, NULL))
- return IZ_CTRLC;
- #endif
- if (uO.tflag || size == 0L)
- return PK_OK;
- if (G.disk_full)
- return PK_DISK;
- if (!G.pInfo->textmode) {
-
- #ifdef DLL
- if (G.redirect_data) {
- #ifdef NO_SLIDE_REDIR
- if (writeToMemory(__G__ rawbuf, (extent)size)) return PK_ERR;
- #else
- writeToMemory(__G__ rawbuf, (extent)size);
- #endif
- } else
- #endif
- if (!uO.cflag && WriteError(rawbuf, size, G.outfile))
- return disk_error(__G);
- else if (uO.cflag && (*G.message)((zvoid *)&G, rawbuf, size, 0))
- return PK_OK;
- } else {
- if (unshrink) {
-
- transbuf = G.outbuf2;
- #if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
- transbufsiz = TRANSBUFSIZ;
- #endif
- } else {
-
- transbuf = G.outbuf;
- #if (defined(SMALL_MEM) || defined(MED_MEM) || defined(VMS_TEXT_CONV))
- transbufsiz = OUTBUFSIZ;
- Trace((stderr, "\ntransbufsiz = OUTBUFSIZ = %u\n",
- (unsigned)OUTBUFSIZ));
- #endif
- }
- if (G.newfile) {
- #ifdef VMS_TEXT_CONV
- if (G.pInfo->hostnum == VMS_ && G.extra_field &&
- is_vms_varlen_txt(__G__ G.extra_field,
- G.lrec.extra_field_length))
- G.VMS_line_state = 0;
- else
- G.VMS_line_state = -1;
- #endif
- G.didCRlast = FALSE;
- G.newfile = FALSE;
- }
- #ifdef VMS_TEXT_CONV
- if (G.VMS_line_state >= 0)
- {
- p = rawbuf;
- q = transbuf;
- while ((extent)(p-rawbuf) < (extent)size) {
- switch (G.VMS_line_state) {
-
- case 0:
- G.VMS_line_length = 0;
- if ((extent)(p-rawbuf) == (extent)size-1) {
-
- G.VMS_line_length = (unsigned)(*p++);
- G.VMS_line_state = 1;
- } else {
- G.VMS_line_length = makeword(p);
- p += 2;
- G.VMS_line_state = 2;
- }
- G.VMS_line_pad =
- ((G.VMS_line_length & 1) != 0);
- break;
-
- case 1:
- G.VMS_line_length += ((unsigned)(*p++) << 8);
- G.VMS_line_state = 2;
- break;
-
- case 2:
- {
- extent remaining = (extent)size+(rawbuf-p);
- extent outroom;
- if (G.VMS_line_length < remaining) {
- remaining = G.VMS_line_length;
- G.VMS_line_state = 3;
- }
- outroom = transbuf+(extent)transbufsiz-q;
- if (remaining >= outroom) {
- remaining -= outroom;
- for (;outroom > 0; p++, outroom--)
- *q++ = native(*p);
- #ifdef DLL
- if (G.redirect_data) {
- if (writeToMemory(__G__ transbuf,
- (extent)(q-transbuf))) return PK_ERR;
- } else
- #endif
- if (!uO.cflag && WriteError(transbuf,
- (extent)(q-transbuf), G.outfile))
- return disk_error(__G);
- else if (uO.cflag && (*G.message)((zvoid *)&G,
- transbuf, (ulg)(q-transbuf), 0))
- return PK_OK;
- q = transbuf;
-
- }
- G.VMS_line_length -= remaining;
- for (;remaining > 0; p++, remaining--)
- *q++ = native(*p);
- }
- break;
-
- case 3:
- if (q > transbuf+(extent)transbufsiz-lenEOL) {
- #ifdef DLL
- if (G.redirect_data) {
- if (writeToMemory(__G__ transbuf,
- (extent)(q-transbuf))) return PK_ERR;
- } else
- #endif
- if (!uO.cflag &&
- WriteError(transbuf, (extent)(q-transbuf),
- G.outfile))
- return disk_error(__G);
- else if (uO.cflag && (*G.message)((zvoid *)&G,
- transbuf, (ulg)(q-transbuf), 0))
- return PK_OK;
- q = transbuf;
- }
- PutNativeEOL
- G.VMS_line_state = G.VMS_line_pad ? 4 : 0;
- break;
-
- case 4:
- ++p;
- G.VMS_line_state = 0;
- break;
- }
- }
- } else
- #endif
-
- {
- p = rawbuf;
- if (*p == LF && G.didCRlast)
- ++p;
- G.didCRlast = FALSE;
- for (q = transbuf; (extent)(p-rawbuf) < (extent)size; ++p) {
- if (*p == CR) {
- PutNativeEOL
- if ((extent)(p-rawbuf) == (extent)size-1)
-
- G.didCRlast = TRUE;
- else if (p[1] == LF)
- ++p;
- } else if (*p == LF)
- PutNativeEOL
- else
- #ifndef DOS_FLX_OS2_W32
- if (*p != CTRLZ)
- #endif
- *q++ = native(*p);
- #if (defined(SMALL_MEM) || defined(MED_MEM))
- # if (lenEOL == 1)
- if (!unshrink)
- # endif
-
- if (q > transbuf+(extent)transbufsiz-lenEOL) {
- Trace((stderr,
- "p - rawbuf = %u q-transbuf = %u size = %lu\n",
- (unsigned)(p-rawbuf), (unsigned)(q-transbuf), size));
- if (!uO.cflag && WriteError(transbuf,
- (extent)(q-transbuf), G.outfile))
- return disk_error(__G);
- else if (uO.cflag && (*G.message)((zvoid *)&G,
- transbuf, (ulg)(q-transbuf), 0))
- return PK_OK;
- q = transbuf;
- continue;
- }
- #endif
- }
- }
-
- Trace((stderr, "p - rawbuf = %u q-transbuf = %u size = %lu\n",
- (unsigned)(p-rawbuf), (unsigned)(q-transbuf), size));
- if (q > transbuf) {
- #ifdef DLL
- if (G.redirect_data) {
- if (writeToMemory(__G__ transbuf, (extent)(q-transbuf)))
- return PK_ERR;
- } else
- #endif
- if (!uO.cflag && WriteError(transbuf, (extent)(q-transbuf),
- G.outfile))
- return disk_error(__G);
- else if (uO.cflag && (*G.message)((zvoid *)&G, transbuf,
- (ulg)(q-transbuf), 0))
- return PK_OK;
- }
- }
- return PK_OK;
- }
- #ifdef VMS_TEXT_CONV
- static int is_vms_varlen_txt(__G__ ef_buf, ef_len)
- __GDEF
- uch *ef_buf;
- unsigned ef_len;
- {
- unsigned eb_id;
- unsigned eb_len;
- uch *eb_data;
- unsigned eb_datlen;
- #define VMSREC_C_UNDEF 0
- #define VMSREC_C_VAR 2
- uch vms_rectype = VMSREC_C_UNDEF;
-
- #define VMSPK_ITEMID 0
- #define VMSPK_ITEMLEN 2
- #define VMSPK_ITEMHEADSZ 4
- #define VMSATR_C_RECATTR 4
- #define VMS_FABSIG 0x42414656
- #define VMSFAB_B_RFM 31
- #define VMSFAB_B_ORG 29
- if (ef_len == 0 || ef_buf == NULL)
- return FALSE;
- while (ef_len >= EB_HEADSIZE) {
- eb_id = makeword(EB_ID + ef_buf);
- eb_len = makeword(EB_LEN + ef_buf);
- if (eb_len > (ef_len - EB_HEADSIZE)) {
-
- Trace((stderr,
- "is_vms_varlen_txt: block length %u > rest ef_size %u\n", eb_len,
- ef_len - EB_HEADSIZE));
- break;
- }
- switch (eb_id) {
- case EF_PKVMS:
-
-
- eb_data = ef_buf+(EB_HEADSIZE+4);
- eb_datlen = eb_len-4;
-
- if (makelong(ef_buf+EB_HEADSIZE) !=
- crc32(CRCVAL_INITIAL, eb_data, (extent)eb_datlen))
- {
- Info(slide, 1, ((char *)slide,
- "[Warning: CRC error, discarding PKWARE extra field]\n"));
-
- break;
- }
-
- while (eb_datlen > 4)
- {
- unsigned fldsize = makeword(&eb_data[VMSPK_ITEMLEN]);
-
- switch (makeword(&eb_data[VMSPK_ITEMID])) {
- case VMSATR_C_RECATTR:
-
- if (fldsize >= 1) {
- vms_rectype = eb_data[VMSPK_ITEMHEADSZ] & 15;
-
- }
- break;
- default:
- break;
- }
-
- eb_datlen -= fldsize + VMSPK_ITEMHEADSZ;
- eb_data += fldsize + VMSPK_ITEMHEADSZ;
- }
- break;
- case EF_IZVMS:
- if (makelong(ef_buf+EB_HEADSIZE) == VMS_FABSIG) {
- if ((eb_data = extract_izvms_block(__G__
- ef_buf+EB_HEADSIZE, eb_len,
- &eb_datlen, NULL, 0))
- != NULL)
- {
- if (eb_datlen >= VMSFAB_B_RFM+1) {
- vms_rectype = eb_data[VMSFAB_B_RFM] & 15;
-
- }
- free(eb_data);
- }
- }
- break;
- default:
- break;
- }
-
- ef_buf += (eb_len + EB_HEADSIZE);
- ef_len -= (eb_len + EB_HEADSIZE);
- }
- return (vms_rectype == VMSREC_C_VAR);
- }
- #endif
- static int disk_error(__G)
- __GDEF
- {
-
- Info(slide, 0x4a1, ((char *)slide, LoadFarString(DiskFullQuery),
- FnFilter1(G.filename)));
- #ifndef WINDLL
- fgets(G.answerbuf, sizeof(G.answerbuf), stdin);
- if (*G.answerbuf == 'y')
- G.disk_full = 1;
- else
- #endif
- G.disk_full = 2;
- return PK_DISK;
- }
- #endif
- int UZ_EXP UzpMessagePrnt(pG, buf, size, flag)
- zvoid *pG;
- uch *buf;
- ulg size;
- int flag;
- {
-
- int error;
- uch *q=buf, *endbuf=buf+(unsigned)size;
- #ifdef MORE
- uch *p=buf;
- #if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
- int islinefeed = FALSE;
- #endif
- #endif
- FILE *outfp;
- #if (defined(OS2) && defined(DLL))
- if (MSG_NO_DLL2(flag))
- return 0;
- #endif
- #ifdef WINDLL
- if (MSG_NO_WDLL(flag))
- return 0;
- #endif
- #ifdef WINDLL
- if (MSG_NO_WGUI(flag))
- return 0;
- #endif
- #ifdef DLL
- if (((Uz_Globs *)pG)->redirect_data &&
- !((Uz_Globs *)pG)->redirect_text)
- return 0;
- #endif
- if (MSG_STDERR(flag) && !((Uz_Globs *)pG)->UzO.tflag)
- outfp = (FILE *)stderr;
- else
- outfp = (FILE *)stdout;
- #ifdef QUERY_TRNEWLN
-
- if (MSG_MNEWLN(flag)) {
- *endbuf++ = '\n';
- ++size;
- }
- #endif
- if (MSG_TNEWLN(flag)) {
- if ((!size && !((Uz_Globs *)pG)->sol) ||
- (size && (endbuf[-1] != '\n')))
- {
- *endbuf++ = '\n';
- ++size;
- }
- }
- #ifdef MORE
- # ifdef SCREENSIZE
-
- # if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
- SCREENSIZE(&((Uz_Globs *)pG)->height, &((Uz_Globs *)pG)->width);
- # else
- SCREENSIZE(&((Uz_Globs *)pG)->height, (int *)NULL);
- # endif
- ((Uz_Globs *)pG)->height -= 2;
- # else
-
- ((Uz_Globs *)pG)->height = SCREENLINES - 2;
- # if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
- ((Uz_Globs *)pG)->width = SCREENWIDTH;
- # endif
- # endif
- #endif
- if (MSG_LNEWLN(flag) && !((Uz_Globs *)pG)->sol) {
-
- #ifdef OS2DLL
- if (!((Uz_Globs *)pG)->redirect_text) {
- #endif
- putc('\n', outfp);
- fflush(outfp);
- #ifdef MORE
- if (((Uz_Globs *)pG)->M_flag)
- {
- #if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
- ((Uz_Globs *)pG)->chars = 0;
- #endif
- ++((Uz_Globs *)pG)->numlines;
- ++((Uz_Globs *)pG)->lines;
- if (((Uz_Globs *)pG)->lines >= ((Uz_Globs *)pG)->height)
- (*((Uz_Globs *)pG)->mpause)((zvoid *)pG,
- LoadFarString(MorePrompt), 1);
- }
- #endif
- if (MSG_STDERR(flag) && ((Uz_Globs *)pG)->UzO.tflag &&
- !isatty(1) && isatty(2))
- {
-
- putc('\n', stderr);
- fflush(stderr);
- }
- #ifdef OS2DLL
- } else
- REDIRECTC('\n');
- #endif
- ((Uz_Globs *)pG)->sol = TRUE;
- }
-
- #ifdef MORE
- if (((Uz_Globs *)pG)->M_flag
- #ifdef OS2DLL
- && !((Uz_Globs *)pG)->redirect_text
- #endif
- )
- {
- while (p < endbuf) {
- if (*p == '\n') {
- #if (defined(SCREENWIDTH) && defined(SCREENLWRAP))
- islinefeed = TRUE;
- } else if (SCREENLWRAP) {
- if (*p == '\r') {
- ((Uz_Globs *)pG)->chars = 0;
- } else {
- # ifdef TABSIZE
- if (*p == '\t')
- ((Uz_Globs *)pG)->chars +=
- (TABSIZE - (((Uz_Globs *)pG)->chars % TABSIZE));
- else
- # endif
- ++((Uz_Globs *)pG)->chars;
- if (((Uz_Globs *)pG)->chars >= ((Uz_Globs *)pG)->width)
- islinefeed = TRUE;
- }
- }
- if (islinefeed) {
- islinefeed = FALSE;
- ((Uz_Globs *)pG)->chars = 0;
- #endif
- ++((Uz_Globs *)pG)->numlines;
- ++((Uz_Globs *)pG)->lines;
- if (((Uz_Globs *)pG)->lines >= ((Uz_Globs *)pG)->height)
- {
- if ((error = WriteTxtErr(q, p-q+1, outfp)) != 0)
- return error;
- fflush(outfp);
- ((Uz_Globs *)pG)->sol = TRUE;
- q = p + 1;
- (*((Uz_Globs *)pG)->mpause)((zvoid *)pG,
- LoadFarString(MorePrompt), 1);
- }
- }
- INCSTR(p);
- }
- size = (ulg)(p - q);
- }
- #endif
- if (size) {
- #ifdef OS2DLL
- if (!((Uz_Globs *)pG)->redirect_text) {
- #endif
- if ((error = WriteTxtErr(q, size, outfp)) != 0)
- return error;
- #ifndef VMS
- fflush(outfp);
- #endif
- if (MSG_STDERR(flag) && ((Uz_Globs *)pG)->UzO.tflag &&
- !isatty(1) && isatty(2))
- {
-
- if ((error = WriteTxtErr(q, size, stderr)) != 0)
- return error;
- fflush(stderr);
- }
- #ifdef OS2DLL
- } else {
- if ((error = REDIRECTPRINT(q, size)) != 0)
- return error;
- }
- #endif
- ((Uz_Globs *)pG)->sol = (endbuf[-1] == '\n');
- }
- return 0;
- }
- #ifdef DLL
-
- int UZ_EXP UzpMessageNull(pG, buf, size, flag)
- zvoid *pG;
- uch *buf;
- ulg size;
- int flag;
- {
- return 0;
- }
- #endif
-
- int UZ_EXP UzpInput(pG, buf, size, flag)
- zvoid *pG;
- uch *buf;
- int *size;
- int flag;
- {
-
- pG = pG; buf = buf; flag = flag;
- *size = 0;
- return 0;
- }
- #if (!defined(WINDLL) && !defined(MACOS))
- void UZ_EXP UzpMorePause(pG, prompt, flag)
- zvoid *pG;
- ZCONST char *prompt;
- int flag;
- {
- uch c;
- if (!((Uz_Globs *)pG)->sol)
- fprintf(stderr, "\n");
-
- fprintf(stderr, prompt, ((Uz_Globs *)pG)->numlines);
- fflush(stderr);
- if (flag & 1) {
- do {
- c = (uch)FGETCH(0);
- } while (
- #ifdef THEOS
- c != 17 &&
- #endif
- c != '\r' && c != '\n' && c != ' ' && c != 'q' && c != 'Q');
- } else
- c = (uch)FGETCH(0);
-
- fprintf(stderr, LoadFarString(HidePrompt));
- fflush(stderr);
- if (
- #ifdef THEOS
- (c == 17) ||
- #endif
- (ToLower(c) == 'q')) {
- DESTROYGLOBALS();
- EXIT(PK_COOL);
- }
- ((Uz_Globs *)pG)->sol = TRUE;
- #ifdef MORE
-
- if ((flag & 1) && c == ' ')
- ((Uz_Globs *)pG)->lines = 0;
- #endif
- }
- #endif
- #ifndef WINDLL
- int UZ_EXP UzpPassword (pG, rcnt, pwbuf, size, zfn, efn)
- zvoid *pG;
- int *rcnt;
- char *pwbuf;
- int size;
- ZCONST char *zfn;
- ZCONST char *efn;
- {
- #if CRYPT
- int r = IZ_PW_ENTERED;
- char *m;
- char *prompt;
- #ifndef REENTRANT
-
- pG = pG;
- #endif
- if (*rcnt == 0) {
- *rcnt = 2;
- if ((prompt = (char *)malloc(2*FILNAMSIZ + 15)) != (char *)NULL) {
- sprintf(prompt, LoadFarString(PasswPrompt),
- FnFilter1(zfn), FnFilter2(efn));
- m = prompt;
- } else
- m = (char *)LoadFarString(PasswPrompt2);
- } else {
- (*rcnt)--;
- prompt = NULL;
- m = (char *)LoadFarString(PasswRetry);
- }
- m = getp(__G__ m, pwbuf, size);
- if (prompt != (char *)NULL) {
- free(prompt);
- }
- if (m == (char *)NULL) {
- r = IZ_PW_ERROR;
- }
- else if (*pwbuf == '\0') {
- r = IZ_PW_CANCELALL;
- }
- return r;
- #else
-
- pG = pG; rcnt = rcnt; pwbuf = pwbuf; size = size; zfn = zfn; efn = efn;
- return IZ_PW_ERROR;
- #endif
- }
- void handler(signal)
- int signal;
- {
- GETGLOBALS();
- #if !(defined(SIGBUS) || defined(SIGSEGV))
- (*G.message)((zvoid *)&G, slide, 0L, 0x41);
- #endif
- echon();
- #ifdef SIGBUS
- if (signal == SIGBUS) {
- Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt),
- "bus error"));
- DESTROYGLOBALS();
- EXIT(PK_BADERR);
- }
- #endif
- #ifdef SIGILL
- if (signal == SIGILL) {
- Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt),
- "illegal instruction"));
- DESTROYGLOBALS();
- EXIT(PK_BADERR);
- }
- #endif
- #ifdef SIGSEGV
- if (signal == SIGSEGV) {
- Info(slide, 0x421, ((char *)slide, LoadFarString(ZipfileCorrupt),
- "segmentation violation"));
- DESTROYGLOBALS();
- EXIT(PK_BADERR);
- }
- #endif
-
- DESTROYGLOBALS();
- #if defined(AMIGA) && defined(__SASC)
- _abort();
- #endif
- EXIT(IZ_CTRLC);
- }
- #endif
- #if (!defined(VMS) && !defined(CMS_MVS))
- #if (!defined(OS2) || defined(TIMESTAMP))
- #if (!defined(HAVE_MKTIME) || defined(WIN32))
- ZCONST ush ydays[] =
- { 0, 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 };
- #endif
-
- time_t dos_to_unix_time(dosdatetime)
- ulg dosdatetime;
- {
- time_t m_time;
- #ifdef HAVE_MKTIME
- ZCONST time_t now = time(NULL);
- struct tm *tm;
- # define YRBASE 1900
- tm = localtime(&now);
- tm->tm_isdst = -1;
-
- tm->tm_year = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE);
- tm->tm_mon = ((int)(dosdatetime >> 21) & 0x0f) - 1;
- tm->tm_mday = ((int)(dosdatetime >> 16) & 0x1f);
-
- tm->tm_hour = (int)((unsigned)dosdatetime >> 11) & 0x1f;
- tm->tm_min = (int)((unsigned)dosdatetime >> 5) & 0x3f;
- tm->tm_sec = (int)((unsigned)dosdatetime << 1) & 0x3e;
- m_time = mktime(tm);
- NATIVE_TO_TIMET(m_time)
- TTrace((stderr, " final m_time = %lu\n", (ulg)m_time));
- #else
- int yr, mo, dy, hh, mm, ss;
- #ifdef TOPS20
- # define YRBASE 1900
- struct tmx *tmx;
- char temp[20];
- #else
- # define YRBASE 1970
- int leap;
- unsigned days;
- struct tm *tm;
- #if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))
- #ifdef WIN32
- TIME_ZONE_INFORMATION tzinfo;
- DWORD res;
- #else
- #ifndef BSD4_4
- #if (defined(BSD) || defined(MTS) || defined(__GO32__))
- struct timeb tbp;
- #else
- #ifdef DECLARE_TIMEZONE
- extern time_t timezone;
- #endif
- #endif
- #endif
- #endif
- #endif
- #endif
-
- yr = ((int)(dosdatetime >> 25) & 0x7f) + (1980 - YRBASE);
- mo = ((int)(dosdatetime >> 21) & 0x0f) - 1;
- dy = ((int)(dosdatetime >> 16) & 0x1f) - 1;
-
- hh = (int)((unsigned)dosdatetime >> 11) & 0x1f;
- mm = (int)((unsigned)dosdatetime >> 5) & 0x3f;
- ss = (int)((unsigned)dosdatetime & 0x1f) * 2;
- #ifdef TOPS20
- tmx = (struct tmx *)malloc(sizeof(struct tmx));
- sprintf (temp, "%02d/%02d/%02d %02d:%02d:%02d", mo+1, dy+1, yr, hh, mm, ss);
- time_parse(temp, tmx, (char *)0);
- m_time = time_make(tmx);
- free(tmx);
- #else
-
- leap = ((yr + YRBASE - 1) / 4);
-
- days = (yr * 365) + (leap - 492) + ydays[mo];
-
- if ((mo > 1) && ((yr+YRBASE)%4 == 0) && ((yr+YRBASE) != 2100))
- ++days;
-
- m_time = (time_t)((unsigned long)(days + dy) * 86400L +
- (unsigned long)hh * 3600L +
- (unsigned long)(mm * 60 + ss));
-
- TTrace((stderr, "dos_to_unix_time:\n"));
- TTrace((stderr, " m_time before timezone = %lu\n", (ulg)m_time));
- #if (!defined(MACOS) && !defined(RISCOS) && !defined(QDOS) && !defined(TANDEM))
- #ifdef WIN32
-
- res = GetTimeZoneInformation(&tzinfo);
- if (res != TIME_ZONE_ID_INVALID)
- {
- m_time += 60*(tzinfo.Bias);
- #else
- #if (defined(BSD) || defined(MTS) || defined(__GO32__))
- #ifdef BSD4_4
- if ( (dosdatetime >= DOSTIME_2038_01_18) &&
- (m_time < (time_t)0x70000000L) )
- m_time = U_TIME_T_MAX;
- if (m_time < (time_t)0L)
- m_time = S_TIME_T_MAX;
- if ((tm = localtime(&m_time)) != (struct tm *)NULL)
- m_time -= tm->tm_gmtoff;
- #else
- ftime(&tbp);
- m_time += tbp.timezone * 60L;
- #endif
- #else
-
-
- #ifndef __BEOS__
- m_time += timezone;
- #endif
- #endif
- #endif
- TTrace((stderr, " m_time after timezone = %lu\n", (ulg)m_time));
- #ifndef BSD4_4
- if ( (dosdatetime >= DOSTIME_2038_01_18) &&
- (m_time < (time_t)0x70000000L) )
- m_time = U_TIME_T_MAX;
- if (m_time < (time_t)0L)
- m_time = S_TIME_T_MAX;
- TIMET_TO_NATIVE(m_time)
- if (((tm = localtime((time_t *)&m_time)) != NULL) && tm->tm_isdst)
- #ifdef WIN32
- m_time += 60L * tzinfo.DaylightBias;
- else
- m_time += 60L * tzinfo.StandardBias;
- #else
- m_time -= 60L * 60L;
- #endif
- NATIVE_TO_TIMET(m_time)
- TTrace((stderr, " m_time after DST = %lu\n", (ulg)m_time));
- #endif
- #ifdef WIN32
- }
- #endif
- #endif
- #endif
- #endif
- if ( (dosdatetime >= DOSTIME_2038_01_18) &&
- (m_time < (time_t)0x70000000L) )
- m_time = U_TIME_T_MAX;
- if (m_time < (time_t)0L)
- m_time = S_TIME_T_MAX;
- return m_time;
- }
- #endif
- #endif
- #if (!defined(VMS) && !defined(OS2) && !defined(CMS_MVS))
-
- int check_for_newer(__G__ filename)
- __GDEF
- char *filename;
- {
- time_t existing, archive;
- #ifdef USE_EF_UT_TIME
- iztimes z_utime;
- #endif
- #ifdef AOS_VS
- long dyy, dmm, ddd, dhh, dmin, dss;
- dyy = (lrec.last_mod_dos_datetime >> 25) + 1980;
- dmm = (lrec.last_mod_dos_datetime >> 21) & 0x0f;
- ddd = (lrec.last_mod_dos_datetime >> 16) & 0x1f;
- dhh = (lrec.last_mod_dos_datetime >> 11) & 0x1f;
- dmin = (lrec.last_mod_dos_datetime >> 5) & 0x3f;
- dss = (lrec.last_mod_dos_datetime & 0x1f) * 2;
-
- if (!zvs_create(filename, (((ulg)dgdate(dmm, ddd, dyy)) << 16) |
- (dhh*1800L + dmin*30L + dss/2L), -1L, -1L, (char *) -1, -1, -1, -1))
- return DOES_NOT_EXIST;
- #endif
- Trace((stderr, "check_for_newer: doing stat(%s)\n", FnFilter1(filename)));
- if (SSTAT(filename, &G.statbuf)) {
- Trace((stderr,
- "check_for_newer: stat(%s) returns %d: file does not exist\n",
- FnFilter1(filename), SSTAT(filename, &G.statbuf)));
- #ifdef SYMLINKS
- Trace((stderr, "check_for_newer: doing lstat(%s)\n",
- FnFilter1(filename)));
-
- if (lstat(filename, &G.statbuf) == 0) {
- Trace((stderr,
- "check_for_newer: lstat(%s) returns 0: symlink does exist\n",
- FnFilter1(filename)));
- if (QCOND2 && !IS_OVERWRT_ALL)
- Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink),
- FnFilter1(filename), " with no real file"));
- return EXISTS_AND_OLDER;
- }
- #endif
- return DOES_NOT_EXIST;
- }
- Trace((stderr, "check_for_newer: stat(%s) returns 0: file exists\n",
- FnFilter1(filename)));
- #ifdef SYMLINKS
-
- if (lstat(filename, &G.statbuf) == 0 && S_ISLNK(G.statbuf.st_mode)) {
- Trace((stderr, "check_for_newer: %s is a symbolic link\n",
- FnFilter1(filename)));
- if (QCOND2 && !IS_OVERWRT_ALL)
- Info(slide, 0, ((char *)slide, LoadFarString(FileIsSymLink),
- FnFilter1(filename), ""));
- return EXISTS_AND_OLDER;
- }
- #endif
- NATIVE_TO_TIMET(G.statbuf.st_mtime)
- #ifdef USE_EF_UT_TIME
-
- if (G.extra_field &&
- #ifdef IZ_CHECK_TZ
- G.tz_is_valid &&
- #endif
- (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
- G.lrec.last_mod_dos_datetime, &z_utime, NULL)
- & EB_UT_FL_MTIME))
- {
- TTrace((stderr, "check_for_newer: using Unix extra field mtime\n"));
- existing = G.statbuf.st_mtime;
- archive = z_utime.mtime;
- } else {
-
- existing = ((G.statbuf.st_mtime & 1) &&
- (G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ?
- G.statbuf.st_mtime + 1 : G.statbuf.st_mtime;
- archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
- }
- #else
-
- existing = ((G.statbuf.st_mtime & 1) &&
- (G.statbuf.st_mtime + 1 > G.statbuf.st_mtime)) ?
- G.statbuf.st_mtime + 1 : G.statbuf.st_mtime;
- archive = dos_to_unix_time(G.lrec.last_mod_dos_datetime);
- #endif
- TTrace((stderr, "check_for_newer: existing %lu, archive %lu, e-a %ld\n",
- (ulg)existing, (ulg)archive, (long)(existing-archive)));
- return (existing >= archive);
- }
- #endif
- int do_string(__G__ length, option)
- __GDEF
- unsigned int length;
- int option;
- {
- unsigned comment_bytes_left;
- unsigned int block_len;
- int error=PK_OK;
- #ifdef AMIGA
- char tmp_fnote[2 * AMIGA_FILENOTELEN];
- #endif
- if (!length)
- return PK_COOL;
- switch (option) {
- #if (defined(SFX) && defined(CHEAP_SFX_AUTORUN))
-
- case CHECK_AUTORUN:
- case CHECK_AUTORUN_Q:
- comment_bytes_left = length;
- if (length >= 10)
- {
- block_len = readbuf(__G__ (char *)G.outbuf, 10);
- if (block_len == 0)
- return PK_EOF;
- comment_bytes_left -= block_len;
- G.outbuf[block_len] = '\0';
- if (!strcmp((char *)G.outbuf, "$AUTORUN$>")) {
- char *eol;
- length -= 10;
- block_len = readbuf(__G__ G.autorun_command,
- MIN(length, sizeof(G.autorun_command)-1));
- if (block_len == 0)
- return PK_EOF;
- comment_bytes_left -= block_len;
- G.autorun_command[block_len] = '\0';
- A_TO_N(G.autorun_command);
- eol = strchr(G.autorun_command, '\n');
- if (!eol)
- eol = G.autorun_command + strlen(G.autorun_command) - 1;
- length -= eol + 1 - G.autorun_command;
- while (eol >= G.autorun_command && isspace(*eol))
- *eol-- = '\0';
- #if (defined(WIN32) && !defined(_WIN32_WCE))
-
- INTERN_TO_OEM(G.autorun_command, G.autorun_command);
- #endif
- }
- }
- if (option == CHECK_AUTORUN_Q)
- length = 0;
-
-
- seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
- (G.inptr - G.inbuf) + comment_bytes_left - length);
- if (!length)
- break;
-
- #endif
-
- case DISPLAY:
- case DISPL_8:
- comment_bytes_left = length;
- block_len = OUTBUFSIZ;
- while (comment_bytes_left > 0 && block_len > 0) {
- register uch *p = G.outbuf;
- register uch *q = G.outbuf;
- if ((block_len = readbuf(__G__ (char *)G.outbuf,
- MIN((unsigned)OUTBUFSIZ, comment_bytes_left))) == 0)
- return PK_EOF;
- comment_bytes_left -= block_len;
-
- G.outbuf[block_len] = '\0';
-
- while (*p) {
- while (*p == CR)
- ++p;
- *q++ = *p++;
- }
-
- *q = '\0';
- if (option == DISPL_8) {
-
- Ext_ASCII_TO_Native((char *)G.outbuf, G.pInfo->hostnum,
- G.pInfo->hostver, G.pInfo->HasUxAtt,
- FALSE);
- #ifdef WINDLL
-
- INTERN_TO_ISO((char *)G.outbuf, (char *)G.outbuf);
- #else
- #if (defined(WIN32) && !defined(_WIN32_WCE))
-
- INTERN_TO_OEM((char *)G.outbuf, (char *)G.outbuf);
- #endif
- #endif
- } else {
- A_TO_N(G.outbuf);
- }
- #ifdef WINDLL
-
- win_fprintf((zvoid *)&G, stdout, (extent)(q-G.outbuf),
- (char *)G.outbuf);
- win_fprintf((zvoid *)&G, stdout, 2, (char *)"\n\n");
- #else
- #ifdef NOANSIFILT
- (*G.message)((zvoid *)&G, G.outbuf, (ulg)(q-G.outbuf), 0);
- #else
- p = G.outbuf - 1;
- q = slide;
- while (*++p) {
- int pause = FALSE;
- if (*p == 0x1B) {
- *q++ = '^';
- *q++ = '[';
- } else if (*p == 0x13) {
- pause = TRUE;
- if (p[1] == LF)
- *q++ = *++p;
- else if (p[1] == CR && p[2] == LF) {
- *q++ = *++p;
- *q++ = *++p;
- }
- } else
- *q++ = *p;
- if ((unsigned)(q-slide) > WSIZE-3 || pause) {
- (*G.message)((zvoid *)&G, slide, (ulg)(q-slide), 0);
- q = slide;
- if (pause && G.extract_flag)
- (*G.mpause)((zvoid *)&G, LoadFarString(QuitPrompt), 0);
- }
- }
- (*G.message)((zvoid *)&G, slide, (ulg)(q-slide), 0);
- #endif
- #endif
- }
-
- (*G.message)((zvoid *)&G, slide, 0L, 0x40);
- break;
-
- case DS_FN:
- case DS_FN_L:
- #ifdef UNICODE_SUPPORT
-
- if (G.fnfull_bufsize <= length) {
- extent fnbufsiz = FILNAMSIZ;
- if (fnbufsiz <= length)
- fnbufsiz = length + 1;
- if (G.filename_full)
- free(G.filename_full);
- G.filename_full = malloc(fnbufsiz);
- if (G.filename_full == NULL)
- return PK_MEM;
- G.fnfull_bufsize = fnbufsiz;
- }
- if (readbuf(__G__ G.filename_full, length) == 0)
- return PK_EOF;
- G.filename_full[length] = '\0';
-
- if (length >= FILNAMSIZ) {
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(FilenameTooLongTrunc)));
- error = PK_WARN;
- length = FILNAMSIZ - 1;
- }
-
- block_len = 0;
- strncpy(G.filename, G.filename_full, length);
- G.filename[length] = '\0';
- #else
- if (length >= FILNAMSIZ) {
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(FilenameTooLongTrunc)));
- error = PK_WARN;
-
- block_len = length - (FILNAMSIZ - 1);
- length = FILNAMSIZ - 1;
- } else
-
- block_len = 0;
- if (readbuf(__G__ G.filename, length) == 0)
- return PK_EOF;
- G.filename[length] = '\0';
- #endif
-
- Ext_ASCII_TO_Native(G.filename, G.pInfo->hostnum, G.pInfo->hostver,
- G.pInfo->HasUxAtt, (option == DS_FN_L));
- if (G.pInfo->lcflag)
- STRLOWER(G.filename, G.filename);
- if (G.pInfo->vollabel && length > 8 && G.filename[8] == '.') {
- char *p = G.filename+8;
- while (*p++)
- p[-1] = *p;
- }
- if (!block_len)
- break;
-
- Info(slide, 0x401, ((char *)slide, "[ %s ]\n", FnFilter1(G.filename)));
- length = block_len;
-
-
- case SKIP:
-
- seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
- (G.inptr-G.inbuf) + length);
- break;
-
- case EXTRA_FIELD:
- if (G.extra_field != (uch *)NULL)
- free(G.extra_field);
- if ((G.extra_field = (uch *)malloc(length)) == (uch *)NULL) {
- Info(slide, 0x401, ((char *)slide, LoadFarString(ExtraFieldTooLong),
- length));
-
- seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes +
- (G.inptr-G.inbuf) + length);
- } else {
- if (readbuf(__G__ (char *)G.extra_field, length) == 0)
- return PK_EOF;
-
- getZip64Data(__G__ G.extra_field, length);
- #ifdef UNICODE_SUPPORT
- G.unipath_filename = NULL;
- if (G.UzO.U_flag < 2) {
-
- if (G.pInfo->GPFIsUTF8) {
-
- G.unipath_filename = G.filename_full;
- } else {
-
- getUnicodeData(__G__ G.extra_field, length);
- if (G.unipath_filename && strlen(G.unipath_filename) == 0) {
-
- free(G.unipath_filename);
- G.unipath_filename = G.filename_full;
- }
- }
- if (G.unipath_filename) {
- # ifdef UTF8_MAYBE_NATIVE
- if (G.native_is_utf8
- # ifdef UNICODE_WCHAR
- && (!G.unicode_escape_all)
- # endif
- ) {
- strncpy(G.filename, G.unipath_filename, FILNAMSIZ - 1);
-
- if (strlen(G.unipath_filename) >= FILNAMSIZ) {
- G.filename[FILNAMSIZ - 1] = '\0';
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(UFilenameTooLongTrunc)));
- error = PK_WARN;
- }
- }
- # ifdef UNICODE_WCHAR
- else
- # endif
- # endif
- # ifdef UNICODE_WCHAR
- {
- char *fn;
-
- fn = utf8_to_local_string(G.unipath_filename,
- G.unicode_escape_all);
-
- if (strlen(fn) >= FILNAMSIZ) {
- fn[FILNAMSIZ - 1] = '\0';
- Info(slide, 0x401, ((char *)slide,
- LoadFarString(UFilenameTooLongTrunc)));
- error = PK_WARN;
- }
-
- strcpy(G.filename, fn);
- free(fn);
- }
- # endif
- if (G.unipath_filename != G.filename_full)
- free(G.unipath_filename);
- G.unipath_filename = NULL;
- }
- }
- #endif
- }
- break;
- #ifdef AMIGA
-
- case FILENOTE:
- if ((block_len = readbuf(__G__ tmp_fnote, (unsigned)
- MIN(length, 2 * AMIGA_FILENOTELEN - 1))) == 0)
- return PK_EOF;
- if ((length -= block_len) > 0)
- seek_zipf(__G__ G.cur_zipfile_bufstart - G.extra_bytes
- + (G.inptr - G.inbuf) + length);
-
- tmp_fnote[block_len] = '\0';
- while ((short int) --block_len >= 0)
- if ((unsigned) tmp_fnote[block_len] < ' ')
- if (tmp_fnote[block_len+1] == ' ')
- strcpy(tmp_fnote+block_len, tmp_fnote+block_len+1);
- else
- tmp_fnote[block_len] = ' ';
- tmp_fnote[AMIGA_FILENOTELEN - 1] = '\0';
- if (G.filenotes[G.filenote_slot])
- free(G.filenotes[G.filenote_slot]);
- G.filenotes[G.filenote_slot] = NULL;
- if (tmp_fnote[0]) {
- if (!(G.filenotes[G.filenote_slot] = malloc(strlen(tmp_fnote)+1)))
- return PK_MEM;
- strcpy(G.filenotes[G.filenote_slot], tmp_fnote);
- }
- break;
- #endif
- }
- return error;
- }
- ush makeword(b)
- ZCONST uch *b;
- {
-
- return (ush)((b[1] << 8) | b[0]);
- }
- ulg makelong(sig)
- ZCONST uch *sig;
- {
-
- return (((ulg)sig[3]) << 24)
- + (((ulg)sig[2]) << 16)
- + (ulg)((((unsigned)sig[1]) << 8)
- + ((unsigned)sig[0]));
- }
- zusz_t makeint64(sig)
- ZCONST uch *sig;
- {
- #ifdef LARGE_FILE_SUPPORT
-
- return (((zusz_t)sig[7]) << 56)
- + (((zusz_t)sig[6]) << 48)
- + (((zusz_t)sig[4]) << 32)
- + (zusz_t)((((ulg)sig[3]) << 24)
- + (((ulg)sig[2]) << 16)
- + (((unsigned)sig[1]) << 8)
- + (sig[0]));
- #else
- if ((sig[7] | sig[6] | sig[5] | sig[4]) != 0)
- return (zusz_t)0xffffffffL;
- else
- return (zusz_t)((((ulg)sig[3]) << 24)
- + (((ulg)sig[2]) << 16)
- + (((unsigned)sig[1]) << 8)
- + (sig[0]));
- #endif
- }
- char *fzofft(__G__ val, pre, post)
- __GDEF
- zoff_t val;
- ZCONST char *pre;
- ZCONST char *post;
- {
-
-
-
-
- char fmt[16];
-
- fmt[0] = '%';
- fmt[1] = '\0';
- if (pre == FZOFFT_HEX_WID)
- {
- strcat(fmt, FZOFFT_HEX_WID_VALUE);
- }
- else if (pre == FZOFFT_HEX_DOT_WID)
- {
- strcat(fmt, ".");
- strcat(fmt, FZOFFT_HEX_WID_VALUE);
- }
- else if (pre != NULL)
- {
- strcat(fmt, pre);
- }
- strcat(fmt, FZOFFT_FMT);
- if (post == NULL)
- strcat(fmt, "d");
- else
- strcat(fmt, post);
-
- G.fzofft_index = (G.fzofft_index + 1) % FZOFFT_NUM;
-
- sprintf(G.fzofft_buf[G.fzofft_index], fmt, val);
-
- return G.fzofft_buf[G.fzofft_index];
- }
- #if CRYPT
- #ifdef NEED_STR2ISO
- char *str2iso(dst, src)
- char *dst;
- register ZCONST char *src;
- {
- #ifdef INTERN_TO_ISO
- INTERN_TO_ISO(src, dst);
- #else
- register uch c;
- register char *dstp = dst;
- do {
- c = (uch)foreign(*src++);
- *dstp++ = (char)ASCII2ISO(c);
- } while (c != '\0');
- #endif
- return dst;
- }
- #endif
- #ifdef NEED_STR2OEM
- char *str2oem(dst, src)
- char *dst;
- register ZCONST char *src;
- {
- #ifdef INTERN_TO_OEM
- INTERN_TO_OEM(src, dst);
- #else
- register uch c;
- register char *dstp = dst;
- do {
- c = (uch)foreign(*src++);
- *dstp++ = (char)ASCII2OEM(c);
- } while (c != '\0');
- #endif
- return dst;
- }
- #endif
- #endif
- #ifdef ZMEM
-
-
- zvoid *memset(buf, init, len)
- register zvoid *buf;
- register int init;
- register unsigned int len;
- {
- zvoid *start;
- start = buf;
- while (len--)
- *((char *)buf++) = (char)init;
- return start;
- }
- int memcmp(b1, b2, len)
- register ZCONST zvoid *b1;
- register ZCONST zvoid *b2;
- register unsigned int len;
- {
- register int c;
- if (len > 0) do {
- if ((c = (int)(*((ZCONST unsigned char *)b1)++) -
- (int)(*((ZCONST unsigned char *)b2)++)) != 0)
- return c;
- } while (--len > 0)
- return 0;
- }
- zvoid *memcpy(dst, src, len)
- register zvoid *dst;
- register ZCONST zvoid *src;
- register unsigned int len;
- {
- zvoid *start;
- start = dst;
- while (len-- > 0)
- *((char *)dst)++ = *((ZCONST char *)src)++;
- return start;
- }
- #endif
- #ifdef NO_STRNICMP
- int zstrnicmp(s1, s2, n)
- register ZCONST char *s1, *s2;
- register unsigned n;
- {
- for (; n > 0; --n, ++s1, ++s2) {
- if (ToLower(*s1) != ToLower(*s2))
-
- return ((uch)ToLower(*s1) < (uch)ToLower(*s2))? -1 : 1;
- if (*s1 == '\0')
- return 0;
- }
- return 0;
- }
- #endif
- #ifdef REGULUS
- # undef stat
- int zstat(p, s)
- ZCONST char *p;
- struct stat *s;
- {
- return (stat((char *)p,s) >= 0? 0 : (-1));
- }
- #endif
- #ifdef _MBCS
- char *plastchar(ptr, len)
- ZCONST char *ptr;
- extent len;
- {
- unsigned clen;
- ZCONST char *oldptr = ptr;
- while(*ptr != '\0' && len > 0){
- oldptr = ptr;
- clen = CLEN(ptr);
- ptr += clen;
- len -= clen;
- }
- return (char *)oldptr;
- }
- #ifdef NEED_UZMBCLEN
- extent uzmbclen(ptr)
- ZCONST unsigned char *ptr;
- {
- int mbl;
- mbl = mblen((ZCONST char *)ptr, MB_CUR_MAX);
-
- return (extent)(mbl > 0 ? mbl : 1);
- }
- #endif
- #ifdef NEED_UZMBSCHR
- unsigned char *uzmbschr(str, c)
- ZCONST unsigned char *str;
- unsigned int c;
- {
- while(*str != '\0'){
- if (*str == c) {return (unsigned char *)str;}
- INCSTR(str);
- }
- return NULL;
- }
- #endif
- #ifdef NEED_UZMBSRCHR
- unsigned char *uzmbsrchr(str, c)
- ZCONST unsigned char *str;
- unsigned int c;
- {
- unsigned char *match = NULL;
- while(*str != '\0'){
- if (*str == c) {match = (unsigned char *)str;}
- INCSTR(str);
- }
- return match;
- }
- #endif
- #endif
- #ifdef SMALL_MEM
-
- char *fLoadFarString(__GPRO__ const char Far *sz)
- {
- (void)zfstrcpy(G.rgchBigBuffer, sz);
- return G.rgchBigBuffer;
- }
- char *fLoadFarStringSmall(__GPRO__ const char Far *sz)
- {
- (void)zfstrcpy(G.rgchSmallBuffer, sz);
- return G.rgchSmallBuffer;
- }
- char *fLoadFarStringSmall2(__GPRO__ const char Far *sz)
- {
- (void)zfstrcpy(G.rgchSmallBuffer2, sz);
- return G.rgchSmallBuffer2;
- }
- #if (!defined(_MSC_VER) || (_MSC_VER < 600))
- /*************************/
- /* Function zfstrcpy() */ /* portable clone of _fstrcpy() */
- /*************************/
- char Far * Far zfstrcpy(char Far *s1, const char Far *s2)
- {
- char Far *p = s1;
- while ((*s1++ = *s2++) != '\0');
- return p;
- }
- #if (!(defined(SFX) || defined(FUNZIP)))
- /*************************/
- /* Function zfstrcmp() */ /* portable clone of _fstrcmp() */
- /*************************/
- int Far zfstrcmp(const char Far *s1, const char Far *s2)
- {
- int ret;
- while ((ret = (int)(uch)*s1 - (int)(uch)*s2) == 0
- && *s2 != '\0') {
- ++s2; ++s1;
- }
- return ret;
- }
- #endif /* !(SFX || FUNZIP) */
- #endif /* !_MSC_VER || (_MSC_VER < 600) */
- #endif /* SMALL_MEM */
|