1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820 |
- #define __ZIPFILE_C
- #include "zip.h"
- #include "revision.h"
- #ifdef UNICODE_SUPPORT
- # include "crc32.h"
- #endif
- #include <stdlib.h>
- #include <errno.h>
- #include <ctype.h>
- #ifdef VMS
- # include "vms/vms.h"
- # include "vms/vmsmunch.h"
- # include "vms/vmsdefs.h"
- #endif
- #ifdef WIN32
- # define WIN32_LEAN_AND_MEAN
- # include <windows.h>
- #endif
- #ifdef THEOS
-
- ush SH(uch* p) { return ((ush)(uch)((p)[0]) | ((ush)(uch)((p)[1]) << 8)); }
- ulg LG(uch* p) { return ((ulg)(SH(p)) | ((ulg)(SH((p)+2)) << 16)); }
- #else
-
- # define SH(a) ((ush)(((ush)(uch)(a)[0]) | (((ush)(uch)(a)[1]) << 8)))
- # define LG(a) ((ulg)SH(a) | ((ulg)SH((a)+2) << 16))
- # ifdef ZIP64_SUPPORT
- # define LLG(a) ((zoff_t)LG(a) | ((zoff_t)LG((a)+4) << 32))
- # endif
- #endif
- #define PUTSH(a,f) {putc((char)((a) & 0xff),(f)); putc((char)((a) >> 8),(f));}
- #define PUTLG(a,f) {PUTSH((a) & 0xffff,(f)) PUTSH((a) >> 16,(f))}
- #ifdef ZIP64_SUPPORT
- # define PUTLLG(a,f) {PUTLG((a) & 0xffffffff,(f)) PUTLG((a) >> 32,(f))}
- #endif
- #define LOCSIG 0x04034b50L
- #define CENSIG 0x02014b50L
- #define ENDSIG 0x06054b50L
- #define EXTLOCSIG 0x08074b50L
- #define LOCVER 0
- #define LOCFLG 2
- #define LOCHOW 4
- #define LOCTIM 6
- #define LOCDAT 8
- #define LOCCRC 10
- #define LOCSIZ 14
- #define LOCLEN 18
- #define LOCNAM 22
- #define LOCEXT 24
- #define EXTCRC 0
- #define EXTSIZ 4
- #define EXTLEN 8
- #define CENVEM 0
- #define CENVER 2
- #define CENFLG 4
- #define CENHOW 6
- #define CENTIM 8
- #define CENDAT 10
- #define CENCRC 12
- #define CENSIZ 16
- #define CENLEN 20
- #define CENNAM 24
- #define CENEXT 26
- #define CENCOM 28
- #define CENDSK 30
- #define CENATT 32
- #define CENATX 34
- #define CENOFF 38
- #define ENDDSK 0
- #define ENDBEG 2
- #define ENDSUB 4
- #define ENDTOT 6
- #define ENDSIZ 8
- #define ENDOFF 12
- #define ENDCOM 16
- #define ZIP64_EOCDL_SIG 0x07064b50
- #define ZIP64_EOCDL_OFS_SIZE 20
- #define ZIP_UWORD16_MAX 0xFFFF
- #define ZIP_UWORD32_MAX 0xFFFFFFFF
- #define ZIP_EF_HEADER_SIZE 4
- #ifdef ZIP64_SUPPORT
- # define ZIP64_EXTCRC 0
- # define ZIP64_EXTSIZ 4
- # define ZIP64_EXTLEN 12
- # define ZIP64_EOCD_SIG 0x06064b50
- # define ZIP64_EOCD_OFS_SIZE 40
- # define ZIP64_EOCD_OFS_CD_START 48
- # define ZIP64_EOCDL_OFS_SIZE 20
- # define ZIP64_EOCDL_OFS_EOCD_START 8
- # define ZIP64_EOCDL_OFS_TOTALDISKS 16
- # define ZIP64_MIN_VER 45
- # define ZIP64_CENTRAL_DIR_TAIL_SIZE (56 - 8 - 4)
- # define ZIP64_CENTRAL_DIR_TAIL_SIG 0x06064B50L
- # define ZIP64_CENTRAL_DIR_TAIL_END_SIG 0x07064B50L
- # define ZIP64_LARGE_FILE_HEAD_SIZE 32
- # define ZIP64_EF_TAG 0x0001
- # define ZIP64_EFIELD_OFS_OSIZE ZIP_EF_HEADER_SIZE
- # define ZIP64_EFIELD_OFS_CSIZE (ZIP64_EFIELD_OFS_OSIZE + 8)
- # define ZIP64_EFIELD_OFS_OFS (ZIP64_EFIELD_OFS_CSIZE + 8)
- # define ZIP64_EFIELD_OFS_DISK (ZIP64_EFIELD_OFS_OFS + 8)
- local int adjust_zip_local_entry OF((struct zlist far *));
- local void adjust_zip_central_entry OF((struct zlist far *));
- #if 0
- local int remove_local_extra_field OF((struct zlist far *, ulg));
- local int remove_central_extra_field OF((struct zlist far *, ulg));
- #endif
- local int add_central_zip64_extra_field OF((struct zlist far *));
- local int add_local_zip64_extra_field OF((struct zlist far *));
- #endif
- #ifdef UNICODE_SUPPORT
- # define UTF8_PATH_EF_TAG 0x7075
- local int add_Unicode_Path_local_extra_field OF((struct zlist far *));
- local int add_Unicode_Path_cen_extra_field OF((struct zlist far *));
- #endif
- #define UTF8_BIT (1 << 11)
- local void write_ushort_to_mem OF((ush, char *));
- local void write_ulong_to_mem OF((ulg, char *));
- #ifdef ZIP64_SUPPORT
- local void write_int64_to_mem OF((uzoff_t, char *));
- #endif
- #ifdef UNICODE_SUPPORT
- local void write_string_to_mem OF((char *, char *));
- #endif
- #if 0
- local char *get_extra_field OF((ush, char *, unsigned));
- #endif
- #ifdef UNICODE_SUPPORT
- local void read_Unicode_Path_entry OF((struct zlist far *));
- local void read_Unicode_Path_local_entry OF((struct zlist far *));
- #endif
- local void append_ushort_to_mem OF((ush, char **, extent *, extent *));
- local void append_ulong_to_mem OF((ulg, char **, extent *, extent *));
- #ifdef ZIP64_SUPPORT
- local void append_int64_to_mem OF((uzoff_t, char **, extent *, extent *));
- #endif
- local void append_string_to_mem OF((char *, int, char**, extent *, extent *));
- local int find_next_signature OF((FILE *f));
- local int find_signature OF((FILE *, ZCONST char *));
- local int is_signature OF((ZCONST char *, ZCONST char *));
- local int at_signature OF((FILE *, ZCONST char *));
- local int zqcmp OF((ZCONST zvoid *, ZCONST zvoid *));
- #ifdef UNICODE_SUPPORT
- local int zuqcmp OF((ZCONST zvoid *, ZCONST zvoid *));
- #endif
- #if 0
- local int scanzipf_reg OF((FILE *f));
- #endif
- local int scanzipf_regnew OF((void));
- #ifndef UTIL
- local int rqcmp OF((ZCONST zvoid *, ZCONST zvoid *));
- local int zbcmp OF((ZCONST zvoid *, ZCONST zvoid far *));
- # ifdef UNICODE_SUPPORT
- local int zubcmp OF((ZCONST zvoid *, ZCONST zvoid far *));
- # if 0
- local int zuebcmp OF((ZCONST zvoid *, ZCONST zvoid far *));
- # endif
- # endif
- local void zipoddities OF((struct zlist far *));
- # if 0
- local int scanzipf_fix OF((FILE *f));
- # endif
- local int scanzipf_fixnew OF((void));
- # ifdef USE_EF_UT_TIME
- local int ef_scan_ut_time OF((char *ef_buf, extent ef_len, int ef_is_cent,
- iztimes *z_utim));
- # endif
- local void cutpath OF((char *p, int delim));
- #endif
- #ifdef HANDLE_AMIGA_SFX
- ulg amiga_sfx_offset;
- #endif
- local int zqcmp(a, b)
- ZCONST zvoid *a, *b;
- {
- char *aname = (*(struct zlist far **)a)->iname;
- char *bname = (*(struct zlist far **)b)->iname;
- return namecmp(aname, bname);
- }
- #ifdef UNICODE_SUPPORT
- local int zuqcmp(a, b)
- ZCONST zvoid *a, *b;
- {
- char *aname = (*(struct zlist far **)a)->iname;
- char *bname = (*(struct zlist far **)b)->iname;
-
- if ((*(struct zlist far **)a)->zuname)
- aname = (*(struct zlist far **)a)->zuname;
- if ((*(struct zlist far **)b)->zuname)
- bname = (*(struct zlist far **)b)->zuname;
- return namecmp(aname, bname);
- }
- #endif
- #ifndef UTIL
- local int rqcmp(a, b)
- ZCONST zvoid *a, *b;
- {
- return namecmp((*(struct zlist far **)b)->iname,
- (*(struct zlist far **)a)->iname);
- }
- local int zbcmp(n, z)
- ZCONST zvoid *n;
- ZCONST zvoid far *z;
- {
- return namecmp((char *)n, ((struct zlist far *)z)->zname);
- }
- #ifdef UNICODE_SUPPORT
- local int zubcmp(n, z)
- ZCONST zvoid *n;
- ZCONST zvoid far *z;
- {
- char *zuname = ((struct zlist far *)z)->zuname;
-
- if (zuname == NULL)
- zuname = ((struct zlist far *)z)->zname;
- return namecmp((char *)n, zuname);
- }
- #if 0
- local int zuebcmp(n, z)
- ZCONST zvoid *n;
- ZCONST zvoid far *z;
- {
- char *zuname = ((struct zlist far *)z)->zuname;
- char *zuename;
- int k;
-
- if (zuname == NULL)
- zuname = ((struct zlist far *)z)->zname;
- zuename = local_to_escape_string(zuname);
- k = namecmp((char *)n, zuename);
- free(zuename);
- return k;
- }
- #endif
- #endif
- struct zlist far *zsearch(n)
- ZCONST char *n;
- {
- zvoid far **p;
- if (zcount) {
- if ((p = search(n, (ZCONST zvoid far **)zsort, zcount, zbcmp)) != NULL)
- return *(struct zlist far **)p;
- #ifdef UNICODE_SUPPORT
- else if (unicode_mismatch != 3 && fix != 2 &&
- (p = search(n, (ZCONST zvoid far **)zusort, zcount, zubcmp)) != NULL)
- return *(struct zlist far **)p;
- #endif
- else
- return NULL;
- }
- return NULL;
- }
- #endif
- #ifndef VMS
- # ifndef PATHCUT
- # define PATHCUT '/'
- # endif
- char *ziptyp(s)
- char *s;
- {
- char *q;
- char *t;
- # ifdef THEOS
- char *r;
- char *disk;
- # endif
- if ((t = malloc(strlen(s) + 5)) == NULL)
- return NULL;
- strcpy(t, s);
- # ifdef __human68k__
- _toslash(t);
- # endif
- # ifdef MSDOS
- for (q = t; *q; INCSTR(q))
- if (*q == '\\')
- *q = '/';
- # endif
- # if defined(__RSXNT__) || defined(WIN32_CRT_OEM)
-
- AnsiToOem(t, t);
- # endif
- if (adjust) return t;
- # ifndef RISCOS
- # ifndef QDOS
- # ifdef AMIGA
- if ((q = MBSRCHR(t, '/')) == NULL)
- q = MBSRCHR(t, ':');
- if (MBSRCHR((q ? q + 1 : t), '.') == NULL)
- # else
- # ifdef THEOS
-
- if ((q = MBSRCHR((q = MBSRCHR(t, PATHCUT)) == NULL ? t : q + 1, '.')) == NULL
- || q[1] == '\0') {
- # else
- # ifdef TANDEM
- if (MBSRCHR((q = MBSRCHR(t, '.')) == NULL ? t : q + 1, ' ') == NULL)
- # else
- if (MBSRCHR((q = MBSRCHR(t, PATHCUT)) == NULL ? t : q + 1, '.') == NULL)
- # endif
- # endif
- # endif
- # ifdef CMS_MVS
- if (strncmp(t,"dd:",3) != 0 && strncmp(t,"DD:",3) != 0)
- # endif
- # ifdef THEOS
-
- if ((r = MBSRCHR(t, ':')) != NULL) {
-
- if ((disk = strdup(r)) == NULL)
- return NULL;
- strcpy(r[-1] == '.' ? r - 1 : r, ".zip");
- strcat(t, disk);
- free(disk);
- } else {
- if (q != NULL && *q == '.')
- strcpy(q, ".zip");
- else
- strcat(t, ".zip");
- }
- }
- # else
- # ifdef TANDEM
- strcat(t, " ZIP");
- # else
- strcat(t, ".zip");
- # endif
- # endif
- # else
- q = LastDir(t);
- if(MBSRCHR(q, '_') == NULL && MBSRCHR(q, '.') == NULL)
- {
- strcat(t, "_zip");
- }
- # endif
- # endif
- return t;
- }
- #endif
- local void write_ushort_to_mem( OFT( ush) usValue,
- OFT( char *)pPtr)
- #ifdef NO_PROTO
- ush usValue;
- char *pPtr;
- #endif
- {
- *pPtr++ = ((char)(usValue) & 0xff);
- *pPtr = ((char)(usValue >> 8) & 0xff);
- }
- local void write_ulong_to_mem(uValue, pPtr)
- ulg uValue;
- char *pPtr;
- {
- write_ushort_to_mem((ush)(uValue & 0xffff), pPtr);
- write_ushort_to_mem((ush)((uValue >> 16) & 0xffff), pPtr + 2);
- }
- #ifdef ZIP64_SUPPORT
- local void write_int64_to_mem(l64Value,pPtr)
- uzoff_t l64Value;
- char *pPtr;
- {
- write_ulong_to_mem((ulg)(l64Value & 0xffffffff),pPtr);
- write_ulong_to_mem((ulg)((l64Value >> 32) & 0xffffffff),pPtr + 4);
- }
- #endif
- #ifdef UNICODE_SUPPORT
- local void write_string_to_mem(strValue, pPtr)
- char *strValue;
- char *pPtr;
- {
- if (strValue != NULL) {
- int ssize = strlen(strValue);
- int i;
- for (i = 0; i < ssize; i++) {
- *(pPtr + i) = *(strValue + i);
- }
- }
- }
- #endif
- #if 0
- local void append_ubyte_to_mem( OFT( unsigned char) ubValue,
- OFT( char **) pPtr,
- OFT( extent *) offset,
- OFT( extent *) blocksize)
- #ifdef NO_PROTO
- unsigned char ubValue;
- char **pPtr;
- extent *offset;
- extent *blocksize;
- #endif
- {
- if (*pPtr == NULL) {
-
- (*blocksize) = 1024;
- *pPtr = (char *) malloc(*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ubyte_to_mem");
- }
- }
-
- else if ((*offset) > (*blocksize) - (1 + 1)) {
-
- (*blocksize) += 1024;
- *pPtr = realloc(*pPtr, *blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ubyte_to_mem");
- }
- }
- *(*pPtr + *offset) = ubValue;
- (*offset)++;
- }
- #endif
- local void append_ushort_to_mem( OFT( ush) usValue,
- OFT( char **) pPtr,
- OFT( extent *) offset,
- OFT( extent *) blocksize)
- #ifdef NO_PROTO
- ush usValue;
- char **pPtr;
- extent *offset;
- extent *blocksize;
- #endif
- {
- if (*pPtr == NULL) {
-
- (*blocksize) = 1024;
- *pPtr = (char *) malloc(*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ushort_to_mem");
- }
- }
-
- else if ((*offset) > (*blocksize) - (1 + 2)) {
-
- (*blocksize) += 1024;
- *pPtr = realloc(*pPtr, (extent)*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ushort_to_mem");
- }
- }
- write_ushort_to_mem(usValue, (*pPtr) + (*offset));
- (*offset) += 2;
- }
- local void append_ulong_to_mem(uValue, pPtr, offset, blocksize)
- ulg uValue;
- char **pPtr;
- extent *offset;
- extent *blocksize;
- {
- if (*pPtr == NULL) {
-
- (*blocksize) = 1024;
- *pPtr = (char *) malloc(*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ulong_to_mem");
- }
- }
- else if ((*offset) > (*blocksize) - (1 + 4)) {
-
- (*blocksize) += 1024;
- *pPtr = realloc(*pPtr, *blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_ulong_to_mem");
- }
- }
- write_ulong_to_mem(uValue, (*pPtr) + (*offset));
- (*offset) += 4;
- }
- #ifdef ZIP64_SUPPORT
- local void append_int64_to_mem(l64Value, pPtr, offset, blocksize)
- uzoff_t l64Value;
- char **pPtr;
- extent *offset;
- extent *blocksize;
- {
- if (*pPtr == NULL) {
-
- (*blocksize) = 1024;
- *pPtr = (char *) malloc(*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_int64_to_mem");
- }
- }
- else if ((*offset) > (*blocksize) - (1 + 8)) {
-
- (*blocksize) += 1024;
- *pPtr = realloc(*pPtr, *blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_int64_to_mem");
- }
- }
- write_int64_to_mem(l64Value, (*pPtr) + (*offset));
- (*offset) += 8;
- }
- #endif
- local void append_string_to_mem(strValue, strLength, pPtr, offset, blocksize)
- char *strValue;
- int strLength;
- char **pPtr;
- extent *offset;
- extent *blocksize;
- {
- if (strValue != NULL) {
- unsigned bsize = 1024;
- unsigned ssize = strLength;
- unsigned i;
- if (ssize > bsize) {
- bsize = ssize;
- }
- if (*pPtr == NULL) {
-
- (*blocksize) = bsize;
- *pPtr = (char *) malloc(*blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_string_to_mem");
- }
- }
- else if ((*offset) + ssize > (*blocksize) - 1) {
-
- (*blocksize) += bsize;
- *pPtr = realloc(*pPtr, *blocksize);
- if (*pPtr == NULL) {
- ziperr(ZE_MEM, "append_string_to_mem");
- }
- }
- for (i = 0; i < ssize; i++) {
- *(*pPtr + *offset + i) = *(strValue + i);
- }
- (*offset) += ssize;
- }
- }
- char *get_extra_field( OFT( ush) tag,
- OFT( char *) pExtra,
- OFT( unsigned) iExtraLen)
- #ifdef NO_PROTO
- ush tag;
- char *pExtra;
- unsigned iExtraLen;
- #endif
- {
- char *pTemp;
- ush usBlockTag;
- ush usBlockSize;
- if( pExtra == NULL )
- return NULL;
- for (pTemp = pExtra; pTemp < pExtra + iExtraLen - ZIP_EF_HEADER_SIZE;)
- {
- usBlockTag = SH(pTemp);
- usBlockSize = SH(pTemp + 2);
- if (usBlockTag == tag)
- return pTemp;
- pTemp += (usBlockSize + ZIP_EF_HEADER_SIZE);
- }
- return NULL;
- }
- char *copy_nondup_extra_fields(oldExtra, oldExtraLen, newExtra, newExtraLen, newLen)
- char *oldExtra;
- unsigned oldExtraLen;
- char *newExtra;
- unsigned newExtraLen;
- unsigned *newLen;
- {
- char *returnExtra = NULL;
- ush returnExtraLen = 0;
- char *tempExtra;
- char *pTemp;
- ush tag;
- ush blocksize;
- if( oldExtra == NULL ) {
-
- if (newExtra == NULL || newExtraLen == 0) {
- *newLen = 0;
- return NULL;
- } else {
- if ((returnExtra = malloc(newExtraLen)) == NULL)
- ZIPERR(ZE_MEM, "extra field copy");
- memcpy(returnExtra, newExtra, newExtraLen);
- returnExtraLen = newExtraLen;
- *newLen = returnExtraLen;
- return returnExtra;
- }
- }
-
- if ((tempExtra = malloc(0xFFFF)) == NULL)
- ZIPERR(ZE_MEM, "extra field copy");
-
- for (pTemp = oldExtra; pTemp < oldExtra + oldExtraLen;)
- {
- tag = SH(pTemp);
- blocksize = SH(pTemp + 2);
- if (get_extra_field(tag, newExtra, newExtraLen) == NULL) {
-
- memcpy(tempExtra + returnExtraLen, pTemp, blocksize + 4);
- returnExtraLen += blocksize + 4;
- }
- pTemp += blocksize + 4;
- }
-
- memcpy(tempExtra + returnExtraLen, newExtra, newExtraLen);
- returnExtraLen += newExtraLen;
-
- if ((returnExtra = malloc(returnExtraLen)) == NULL)
- ZIPERR(ZE_MEM, "extra field copy");
- memcpy(returnExtra, tempExtra, returnExtraLen);
- free(tempExtra);
- *newLen = returnExtraLen;
- return returnExtra;
- }
- #ifdef UNICODE_SUPPORT
- local void read_Unicode_Path_entry(pZipListEntry)
- struct zlist far *pZipListEntry;
- {
- char *pTemp;
- char *UPath;
- char *iname;
- ush ELen;
- uch Version;
- ush ULen;
- ulg chksum = CRCVAL_INITIAL;
- ulg iname_chksum;
-
- pTemp = get_extra_field( UTF8_PATH_EF_TAG, pZipListEntry->cextra, pZipListEntry->cext );
- pZipListEntry->uname = NULL;
- if( pTemp == NULL ) {
- return;
- }
-
- pTemp += 2;
-
- ELen = SH(pTemp);
- pTemp += 2;
-
- Version = (uch) *pTemp;
- pTemp += 1;
- if (Version > 1) {
- zipwarn("Unicode Path Extra Field version > 1 - skipping", pZipListEntry->oname);
- return;
- }
-
- iname_chksum = LG(pTemp);
- pTemp += 4;
-
- if ((iname = malloc(strlen(pZipListEntry->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "write Unicode");
- }
- strcpy(iname, pZipListEntry->iname);
- chksum = crc32(chksum, (uch *)(iname), strlen(iname));
- free(iname);
-
- if (chksum != iname_chksum) {
- printf("unicode_mismatch = %d\n", unicode_mismatch);
- if (unicode_mismatch == 1) {
-
- zipwarn("Unicode does not match path - ignoring Unicode: ", pZipListEntry->oname);
- } else if (unicode_mismatch == 2) {
-
- } else if (unicode_mismatch == 0) {
-
- sprintf(errbuf, "Unicode does not match path: %s\n", pZipListEntry->oname);
- strcat(errbuf,
- " Likely entry name changed but Unicode not updated\n");
- strcat(errbuf,
- " Use -UN=i to ignore errors or n for no Unicode paths");
- zipwarn(errbuf, "");
- ZIPERR(ZE_FORM, "Unicode path error");
- }
- return;
- }
- ULen = ELen - 5;
-
- if (ULen == 0) {
-
- ULen = pZipListEntry->nam;
- if ((UPath = malloc(ULen + 1)) == NULL) {
- return;
- }
- strcpy(UPath, pZipListEntry->name);
- } else {
-
- if ((UPath = malloc(ULen + 1)) == NULL) {
- return;
- }
- strncpy(UPath, pTemp, ULen);
- UPath[ULen] = '\0';
- }
- pZipListEntry->uname = UPath;
- return;
- }
- local void read_Unicode_Path_local_entry(pZipListEntry)
- struct zlist far *pZipListEntry;
- {
- char *pTemp;
- char *UPath;
- char *iname;
- ush ELen;
- uch Version;
- ush ULen;
- ulg chksum = CRCVAL_INITIAL;
- ulg iname_chksum;
-
- pTemp = get_extra_field( UTF8_PATH_EF_TAG, pZipListEntry->extra, pZipListEntry->ext );
- pZipListEntry->uname = NULL;
- if( pTemp == NULL ) {
- return;
- }
-
- pTemp += 2;
-
- ELen = SH(pTemp);
- pTemp += 2;
-
- Version = (uch) *pTemp;
- pTemp += 1;
- if (Version > 1) {
- zipwarn("Unicode Path Extra Field version > 1 - skipping", pZipListEntry->oname);
- return;
- }
-
- iname_chksum = LG(pTemp);
- pTemp += 4;
-
-
- if ((iname = malloc(strlen(pZipListEntry->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "write Unicode");
- }
- strcpy(iname, pZipListEntry->iname);
- chksum = crc32(chksum, (uch *)(iname), strlen(iname));
- free(iname);
-
- if (chksum != iname_chksum) {
- if (unicode_mismatch == 1) {
-
- zipwarn("Unicode does not match path - ignoring Unicode: ", pZipListEntry->oname);
- } else if (unicode_mismatch == 2) {
-
- } else if (unicode_mismatch == 0) {
-
- sprintf(errbuf, "Unicode does not match path: %s\n", pZipListEntry->oname);
- strcat(errbuf,
- " Likely entry name changed but Unicode not updated\n");
- strcat(errbuf,
- " Use -UN=i to ignore errors or n for no Unicode paths");
- zipwarn(errbuf, "");
- ZIPERR(ZE_FORM, "Unicode path error");
- }
- return;
- }
- ULen = ELen - 5;
-
- if (ULen == 0) {
-
- ULen = pZipListEntry->nam;
- if ((UPath = malloc(ULen + 1)) == NULL) {
- return;
- }
- strcpy(UPath, pZipListEntry->name);
- } else {
-
- if ((UPath = malloc(ULen + 1)) == NULL) {
- return;
- }
- strncpy(UPath, pTemp, ULen);
- UPath[ULen] = '\0';
- }
- pZipListEntry->uname = UPath;
- return;
- }
- #endif
- #ifdef ZIP64_SUPPORT
- local void adjust_zip_central_entry(pZipListEntry)
- struct zlist far *pZipListEntry;
- {
- char *pTemp;
-
- zip64_entry = 0;
-
- pTemp = get_extra_field( ZIP64_EF_TAG, pZipListEntry->cextra, pZipListEntry->cext );
- if( pTemp == NULL )
- return;
-
- zip64_entry = 1;
- pTemp += ZIP_EF_HEADER_SIZE;
-
- if (pZipListEntry->len == ZIP_UWORD32_MAX)
- {
- pZipListEntry->len = LLG(pTemp);
- pTemp += 8;
- }
- if (pZipListEntry->siz == ZIP_UWORD32_MAX)
- {
- pZipListEntry->siz = LLG(pTemp);
- pTemp += 8;
- }
- if (pZipListEntry->off == ZIP_UWORD32_MAX)
- {
- pZipListEntry->off = LLG(pTemp);
- pTemp += 8;
- }
- if (pZipListEntry->dsk == ZIP_UWORD16_MAX)
- {
- pZipListEntry->dsk = LG(pTemp);
- }
- }
- local int adjust_zip_local_entry(pZipListEntry)
- struct zlist far *pZipListEntry;
- {
- char *pTemp;
-
- zip64_entry = 0;
-
- pTemp = get_extra_field(ZIP64_EF_TAG, pZipListEntry->extra, pZipListEntry->ext );
- if( pTemp == NULL )
- return zip64_entry;
-
- zip64_entry = 1;
- pTemp += ZIP_EF_HEADER_SIZE;
-
- if (pZipListEntry->len == ZIP_UWORD32_MAX)
- {
- pZipListEntry->len = LLG(pTemp);
- pTemp += 8;
- }
- if (pZipListEntry->siz == ZIP_UWORD32_MAX)
- {
- pZipListEntry->siz = LLG(pTemp);
- pTemp += 8;
- }
- return zip64_entry;
- }
- local int add_central_zip64_extra_field(pZipListEntry)
- struct zlist far *pZipListEntry;
- {
- char *pExtraFieldPtr;
- char *pTemp;
- ush usTemp;
- ush efsize = 0;
- ush esize;
- ush oldefsize;
- extent len;
- int used_zip64 = 0;
-
-
- efsize = ZIP_EF_HEADER_SIZE;
- if (pZipListEntry->len > ZIP_UWORD32_MAX || force_zip64 == 1) {
-
- efsize += 8;
- used_zip64 = 1;
- }
- if (pZipListEntry->siz > ZIP_UWORD32_MAX) {
-
- efsize += 8;
- used_zip64 = 1;
- }
- if (pZipListEntry->off > ZIP_UWORD32_MAX) {
-
- efsize += 8;
- used_zip64 = 1;
- }
- if (pZipListEntry->dsk > ZIP_UWORD16_MAX) {
-
- efsize += 4;
- used_zip64 = 1;
- }
- if (used_zip64 && force_zip64 == 0) {
- zipwarn("Large entry support disabled using -fz- but needed", "");
- return ZE_BIG;
- }
-
- if( pZipListEntry->cextra == NULL )
- {
- if (efsize == ZIP_EF_HEADER_SIZE) {
- return ZE_OK;
- }
- if ((pExtraFieldPtr = pZipListEntry->cextra = (char *) malloc(efsize)) == NULL) {
- return ZE_MEM;
- }
- pZipListEntry->cext = efsize;
- }
- else
- {
-
- pExtraFieldPtr = get_extra_field(ZIP64_EF_TAG, pZipListEntry->cextra, pZipListEntry->cext);
- if( pExtraFieldPtr == NULL )
- {
-
- if ((pExtraFieldPtr = (char *) malloc(efsize + pZipListEntry->cext)) == NULL) {
- return ZE_MEM;
- }
-
- memmove(pExtraFieldPtr, pZipListEntry->cextra, pZipListEntry->cext);
- free(pZipListEntry->cextra);
- pZipListEntry->cextra = pExtraFieldPtr;
- pExtraFieldPtr += pZipListEntry->cext;
- pZipListEntry->cext += efsize;
- }
- else
- {
-
- usTemp = SH(pExtraFieldPtr + 2);
-
- if( pZipListEntry->cext == (extent)(usTemp + ZIP_EF_HEADER_SIZE) )
- {
-
- if( pZipListEntry->cext != efsize )
- {
-
- if ((pExtraFieldPtr = (char *) malloc(efsize)) == NULL) {
- return ZE_MEM;
- }
- free(pZipListEntry->cextra);
- pZipListEntry->cextra = pExtraFieldPtr;
- pZipListEntry->cext = efsize;
- }
- }
- else
- {
-
- oldefsize = usTemp + ZIP_EF_HEADER_SIZE;
- if ((pTemp = (char *) malloc(pZipListEntry->cext - oldefsize + efsize)) == NULL) {
- return ZE_MEM;
- }
- len = (extent)(pExtraFieldPtr - pZipListEntry->cextra);
- memcpy(pTemp, pZipListEntry->cextra, len);
- memcpy(pTemp + len, pExtraFieldPtr + oldefsize,
- pZipListEntry->cext - oldefsize - len);
- pZipListEntry->cext -= oldefsize;
- pExtraFieldPtr = pTemp + pZipListEntry->cext;
- pZipListEntry->cext += efsize;
- free(pZipListEntry->cextra);
- pZipListEntry->cextra = pTemp;
- }
- }
- }
-
- write_ushort_to_mem(ZIP64_EF_TAG, pExtraFieldPtr);
- write_ushort_to_mem((ush) (efsize - ZIP_EF_HEADER_SIZE), pExtraFieldPtr + 2);
- esize = ZIP_EF_HEADER_SIZE;
- if (pZipListEntry->len > ZIP_UWORD32_MAX || force_zip64 == 1) {
- write_int64_to_mem(pZipListEntry->len, pExtraFieldPtr + esize);
- esize += 8;
- }
- if (pZipListEntry->siz > ZIP_UWORD32_MAX) {
- write_int64_to_mem(pZipListEntry->siz, pExtraFieldPtr + esize);
- esize += 8;
- }
- if (pZipListEntry->off > ZIP_UWORD32_MAX) {
- write_int64_to_mem(pZipListEntry->off, pExtraFieldPtr + esize);
- esize += 8;
- }
- if (pZipListEntry->dsk > ZIP_UWORD16_MAX) {
- write_ulong_to_mem(pZipListEntry->dsk, pExtraFieldPtr + esize);
- }
-
- return ZE_OK;
- }
- #if 0
- local int remove_local_extra_field(pZEntry, tag)
- struct zlist far *pZEntry;
- ulg tag;
- {
- char *pExtra;
- char *pOldExtra;
- char *pOldTemp;
- char *pTemp;
- ush newEFSize;
- ush usTemp;
- ush blocksize;
-
- pOldExtra = get_extra_field( (ush)tag, pZEntry->extra, pZEntry->ext );
- if (pOldExtra)
- {
-
- blocksize = SH( pOldExtra + 2 );
- newEFSize = pZEntry->ext - blocksize;
- pExtra = (char *) malloc( newEFSize );
- if( pExtra == NULL )
- ziperr(ZE_MEM, "Remove Local Extra Field");
-
- usTemp = (extent) (pOldExtra - pZEntry->extra);
- pTemp = pExtra;
- memcpy( pTemp, pZEntry->extra, usTemp );
-
- pTemp = pExtra + usTemp;
- pOldTemp = pOldExtra + blocksize;
- usTemp = pZEntry->ext - usTemp - blocksize;
- memcpy( pTemp, pOldTemp, usTemp);
-
- pZEntry->ext = newEFSize;
- free(pZEntry->extra);
- pZEntry->extra = pExtra;
- return 1;
- } else {
- return 0;
- }
- }
- local int remove_central_extra_field(pZEntry, tag)
- struct zlist far *pZEntry;
- ulg tag;
- {
- char *pExtra;
- char *pOldExtra;
- char *pOldTemp;
- char *pTemp;
- ush newEFSize;
- ush usTemp;
- ush blocksize;
-
- pOldExtra = get_extra_field( (ush)tag, pZEntry->cextra, pZEntry->cext );
- if (pOldExtra)
- {
-
- blocksize = SH( pOldExtra + 2 );
- newEFSize = pZEntry->cext - blocksize;
- pExtra = (char *) malloc( newEFSize );
- if( pExtra == NULL )
- ziperr(ZE_MEM, "Remove Local Extra Field");
-
- usTemp = (extent) (pOldExtra - pZEntry->cextra);
- pTemp = pExtra;
- memcpy( pTemp, pZEntry->cextra, usTemp );
-
- pTemp = pExtra + usTemp;
- pOldTemp = pOldExtra + blocksize;
- usTemp = pZEntry->cext - usTemp - blocksize;
- memcpy( pTemp, pOldTemp, usTemp);
-
- pZEntry->cext = newEFSize;
- free(pZEntry->cextra);
- pZEntry->cextra = pExtra;
- return 1;
- } else {
- return 0;
- }
- }
- #endif
- local int add_local_zip64_extra_field(pZEntry)
- struct zlist far *pZEntry;
- {
- char *pZ64Extra;
- char *pOldZ64Extra;
- char *pOldTemp;
- char *pTemp;
- ush newEFSize;
- ush usTemp;
- ush blocksize;
- ush Z64LocalLen = ZIP_EF_HEADER_SIZE +
- 8 +
- 8;
-
-
- if (pZEntry->ext == 0 || pZEntry->extra == NULL)
- {
-
- pZ64Extra = pZEntry->extra = (char *) malloc(Z64LocalLen);
- if (pZEntry->extra == NULL) {
- ziperr( ZE_MEM, "Zip64 local extra field" );
- }
- pZEntry->ext = Z64LocalLen;
- }
- else
- {
-
- pOldZ64Extra = get_extra_field( ZIP64_EF_TAG, pZEntry->extra, pZEntry->ext );
- if (pOldZ64Extra == NULL)
- {
-
-
- pZ64Extra = (char *) malloc( Z64LocalLen + pZEntry->ext );
- if (pZ64Extra == NULL)
- ziperr( ZE_MEM, "Zip64 Extra Field" );
-
- memmove( pZ64Extra, pZEntry->extra, pZEntry->ext);
- free( pZEntry->extra );
- pZEntry->extra = pZ64Extra;
- pZ64Extra += pZEntry->ext;
- pZEntry->ext += Z64LocalLen;
- }
- else
- {
-
- blocksize = SH( pOldZ64Extra + 2 );
-
- if (blocksize == Z64LocalLen - ZIP_EF_HEADER_SIZE)
- {
-
- pZ64Extra = pOldZ64Extra;
- }
- else
- {
- newEFSize = pZEntry->ext - (blocksize + ZIP_EF_HEADER_SIZE) + Z64LocalLen;
- pZ64Extra = (char *) malloc( newEFSize );
- if( pZ64Extra == NULL )
- ziperr(ZE_MEM, "Zip64 Extra Field");
-
- usTemp = (extent) (pOldZ64Extra - pZEntry->extra);
- pTemp = pZ64Extra;
- memcpy( pTemp, pZEntry->extra, usTemp );
-
- pTemp = pZ64Extra + usTemp;
- pOldTemp = pOldZ64Extra + ZIP_EF_HEADER_SIZE + blocksize;
- usTemp = pZEntry->ext - usTemp - blocksize;
- memcpy( pTemp, pOldTemp, usTemp);
-
- pZEntry->ext = newEFSize;
- free(pZEntry->extra);
- pZEntry->extra = pZ64Extra;
- pZ64Extra = pTemp + usTemp;
- }
- }
- }
-
- write_ushort_to_mem(ZIP64_EF_TAG, pZ64Extra);
- write_ushort_to_mem((ush) (Z64LocalLen - ZIP_EF_HEADER_SIZE), pZ64Extra + 2);
- write_int64_to_mem(pZEntry->len, pZ64Extra + 2 + 2);
- write_int64_to_mem(pZEntry->siz, pZ64Extra + 2 + 2 + 8);
- return ZE_OK;
- }
- # endif
- #ifdef UNICODE_SUPPORT
- local int add_Unicode_Path_local_extra_field(pZEntry)
- struct zlist far *pZEntry;
- {
- char *pUExtra;
- char *pOldUExtra;
- char *pOldTemp;
- char *pTemp;
- #ifdef WIN32_OEM
- char *inameLocal;
- #endif
- ush newEFSize;
- ush usTemp;
- ush ULen = strlen(pZEntry->uname);
- ush blocksize;
- ulg chksum = CRCVAL_INITIAL;
- ush ULocalLen = ZIP_EF_HEADER_SIZE +
- 1 +
- 4 +
- ULen;
-
-
- if (pZEntry->ext == 0 || pZEntry->extra == NULL)
- {
-
- pUExtra = pZEntry->extra = (char *) malloc(ULocalLen);
- if (pZEntry->extra == NULL) {
- ziperr( ZE_MEM, "UTF-8 Path local extra field" );
- }
- pZEntry->ext = ULocalLen;
- }
- else
- {
-
- pOldUExtra = get_extra_field( UTF8_PATH_EF_TAG, pZEntry->extra, pZEntry->ext );
- if (pOldUExtra == NULL)
- {
-
-
- pUExtra = (char *) malloc( ULocalLen + pZEntry->ext );
- if (pUExtra == NULL)
- ziperr( ZE_MEM, "UTF-8 Path Extra Field" );
-
- memmove( pUExtra, pZEntry->extra, pZEntry->ext);
- free( pZEntry->extra );
- pZEntry->extra = pUExtra;
- pUExtra += pZEntry->ext;
- pZEntry->ext += ULocalLen;
- }
- else
- {
-
- blocksize = SH( pOldUExtra + 2 );
-
- if (blocksize == ULocalLen - ZIP_EF_HEADER_SIZE)
- {
-
- pUExtra = pOldUExtra;
- }
- else
- {
- newEFSize = pZEntry->ext - (blocksize + ZIP_EF_HEADER_SIZE) + ULocalLen;
- pUExtra = (char *) malloc( newEFSize );
- if( pUExtra == NULL )
- ziperr(ZE_MEM, "UTF-8 Path Extra Field");
-
- usTemp = (extent) (pOldUExtra - pZEntry->extra);
- pTemp = pUExtra;
- memcpy( pTemp, pZEntry->extra, usTemp );
-
- pTemp = pUExtra + usTemp;
- pOldTemp = pOldUExtra + ZIP_EF_HEADER_SIZE + blocksize;
- usTemp = pZEntry->ext - usTemp - blocksize;
- memcpy( pTemp, pOldTemp, usTemp);
-
- pZEntry->ext = newEFSize;
- free(pZEntry->extra);
- pZEntry->extra = pUExtra;
- pUExtra = pTemp + usTemp;
- }
- }
- }
-
- #ifdef WIN32_OEM
- if ((inameLocal = malloc(strlen(pZEntry->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "write Unicode");
- }
-
- if ((pZEntry->vem & 0xff00) == 0) {
-
- INTERN_TO_OEM(pZEntry->iname, inameLocal);
- } else {
- strcpy(inameLocal, pZEntry->iname);
- }
- #else
- # define inameLocal (pZEntry->iname)
- #endif
- chksum = crc32(chksum, (uch *)(inameLocal), strlen(inameLocal));
- #ifdef WIN32_OEM
- free(inameLocal);
- #else
- # undef inameLocal
- #endif
-
-
- write_ushort_to_mem(UTF8_PATH_EF_TAG, pUExtra);
-
- write_ushort_to_mem((ush) (ULocalLen - ZIP_EF_HEADER_SIZE), pUExtra + 2);
-
- *(pUExtra + 2 + 2) = 1;
-
- write_ulong_to_mem(chksum, pUExtra + 2 + 2 + 1);
-
- write_string_to_mem(pZEntry->uname, pUExtra + 2 + 2 + 1 + 4);
- return ZE_OK;
- }
- local int add_Unicode_Path_cen_extra_field(pZEntry)
- struct zlist far *pZEntry;
- {
- char *pUExtra;
- char *pOldUExtra;
- char *pOldTemp;
- char *pTemp;
- #ifdef WIN32_OEM
- char *inameLocal;
- #endif
- ush newEFSize;
- ush usTemp;
- ush ULen = strlen(pZEntry->uname);
- ush blocksize;
- ulg chksum = CRCVAL_INITIAL;
- ush UCenLen = ZIP_EF_HEADER_SIZE +
- 1 +
- 4 +
- ULen;
-
-
- if (pZEntry->cext == 0 || pZEntry->cextra == NULL)
- {
-
- pUExtra = pZEntry->cextra = (char *) malloc(UCenLen);
- if (pZEntry->cextra == NULL) {
- ziperr( ZE_MEM, "UTF-8 Path cen extra field" );
- }
- pZEntry->cext = UCenLen;
- }
- else
- {
-
- pOldUExtra = get_extra_field( UTF8_PATH_EF_TAG, pZEntry->cextra, pZEntry->cext );
- if (pOldUExtra == NULL)
- {
-
-
- pUExtra = (char *) malloc( UCenLen + pZEntry->cext );
- if (pUExtra == NULL)
- ziperr( ZE_MEM, "UTF-8 Path Extra Field" );
-
- memmove( pUExtra, pZEntry->cextra, pZEntry->cext);
- free( pZEntry->cextra );
- pZEntry->cextra = pUExtra;
- pUExtra += pZEntry->cext;
- pZEntry->cext += UCenLen;
- }
- else
- {
-
- blocksize = SH( pOldUExtra + 2 );
-
- if (blocksize == UCenLen - ZIP_EF_HEADER_SIZE)
- {
-
- pUExtra = pOldUExtra;
- }
- else
- {
- newEFSize = pZEntry->cext - (blocksize + ZIP_EF_HEADER_SIZE) + UCenLen;
- pUExtra = (char *) malloc( newEFSize );
- if( pUExtra == NULL )
- ziperr(ZE_MEM, "UTF-8 Path Extra Field");
-
- usTemp = (extent) (pOldUExtra - pZEntry->cextra);
- pTemp = pUExtra;
- memcpy( pTemp, pZEntry->cextra, usTemp );
-
- pTemp = pUExtra + usTemp;
- pOldTemp = pOldUExtra + ZIP_EF_HEADER_SIZE + blocksize;
- usTemp = pZEntry->cext - usTemp - blocksize;
- memcpy( pTemp, pOldTemp, usTemp);
-
- pZEntry->cext = newEFSize;
- free(pZEntry->cextra);
- pZEntry->cextra = pUExtra;
- pUExtra = pTemp + usTemp;
- }
- }
- }
-
- #ifdef WIN32_OEM
- if ((inameLocal = malloc(strlen(pZEntry->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "write Unicode");
- }
-
- if ((pZEntry->vem & 0xff00) == 0) {
-
- INTERN_TO_OEM(pZEntry->iname, inameLocal);
- } else {
- strcpy(inameLocal, pZEntry->iname);
- }
- #else
- # define inameLocal (pZEntry->iname)
- #endif
- chksum = crc32(chksum, (uch *)(inameLocal), strlen(inameLocal));
- #ifdef WIN32_OEM
- free(inameLocal);
- #else
- # undef inameLocal
- #endif
-
-
-
- write_ushort_to_mem(UTF8_PATH_EF_TAG, pUExtra);
-
- write_ushort_to_mem((ush) (UCenLen - ZIP_EF_HEADER_SIZE), pUExtra + 2);
-
- *(pUExtra + 2 + 2) = 1;
-
- write_ulong_to_mem(chksum, pUExtra + 2 + 2 + 1);
-
- write_string_to_mem(pZEntry->uname, pUExtra + 2 + 2 + 1 + 4);
- return ZE_OK;
- }
- #endif
- zoff_t ffile_size OF((FILE *));
- zoff_t ffile_size( file)
- FILE *file;
- {
- int sts;
- size_t siz;
- zoff_t ofs;
- char waste[ 4];
-
- sts = zfseeko( file, 0, SEEK_END);
- if (sts != 0)
- {
-
- ofs = EOF;
- }
- else
- {
-
- ofs = zftello( file);
- if (ofs < 0)
- {
-
- ofs = EOF;
- }
- else
- {
-
- sts = zfseeko( file, ofs, SEEK_SET);
- if (sts != 0)
- {
-
- ofs = EOF;
- }
- else
- {
-
- siz = fread( waste, 1, 1, file);
- if (feof( file) == 0)
- {
-
- ofs = EOF;
- }
- }
- }
- }
-
-
- #if 0
- #ifdef VAXC
- sts = rewind( file);
- #else
- sts = zfseeko( file, 0, SEEK_SET);
- #endif
- #endif
- rewind(file);
- return ofs;
- }
- #ifndef UTIL
- local void zipoddities(z)
- struct zlist far *z;
- {
- if ((z->vem >> 8) >= NUM_HOSTS)
- {
- sprintf(errbuf, "made by version %d.%d on system type %d: ",
- (ush)(z->vem & 0xff) / (ush)10, (ush)(z->vem & 0xff) % (ush)10,
- z->vem >> 8);
- zipwarn(errbuf, z->oname);
- }
- if (z->ver != 10 && z->ver != 11 && z->ver != 20)
- {
- sprintf(errbuf, "needs unzip %d.%d on system type %d: ",
- (ush)(z->ver & 0xff) / (ush)10,
- (ush)(z->ver & 0xff) % (ush)10, z->ver >> 8);
- zipwarn(errbuf, z->oname);
- }
- if ((fix == 2) && (z->flg != z->lflg))
-
- {
- sprintf(errbuf, "local flags = 0x%04x, central = 0x%04x: ",
- z->lflg, z->flg);
- zipwarn(errbuf, z->oname);
- }
- else if (z->flg & ~0xf && (z->flg & ~0xf0) != UTF8_BIT)
-
- {
- sprintf(errbuf, "undefined bits used in flags = 0x%04x: ", z->flg);
- zipwarn(errbuf, z->oname);
- }
- if (z->how > LAST_KNOWN_COMPMETHOD) {
- sprintf(errbuf, "unknown compression method %u: ", z->how);
- zipwarn(errbuf, z->oname);
- }
- if (z->dsk)
- {
- sprintf(errbuf, "starts on disk %lu: ", z->dsk);
- zipwarn(errbuf, z->oname);
- }
- if (z->att!=ASCII && z->att!=BINARY && z->att!=__EBCDIC)
- {
- sprintf(errbuf, "unknown internal attributes = 0x%04x: ", z->att);
- zipwarn(errbuf, z->oname);
- }
- # if 0
- if (((n = z->vem >> 8) != 3) && n != 2 && n != 13 && z->atx & ~0xffL)
- {
- sprintf(errbuf, "unknown external attributes = 0x%08lx: ", z->atx);
- zipwarn(errbuf, z->oname);
- }
- # endif
-
- #if 0
- if (z->ext || z->cext)
- {
- # if 0
- if (z->ext && z->cext && z->extra != z->cextra)
- {
- sprintf(errbuf,
- "local extra (%ld bytes) != central extra (%ld bytes): ",
- (ulg)z->ext, (ulg)z->cext);
- if (noisy) fprintf(mesg, "\tzip info: %s%s\n", errbuf, z->oname);
- }
- # if (!defined(RISCOS) && !defined(CMS_MVS))
-
- else if (noisy)
- # else
-
- else if (noisy && ((z->vem >> 8) != (OS_CODE >> 8)))
- # endif
- # endif
- {
- fprintf(mesg, "zip info: %s has %ld bytes of %sextra data\n",
- z->oname, z->ext ? (ulg)z->ext : (ulg)z->cext,
- z->ext ? (z->cext ? "" : "local ") : "central ");
- }
- }
- #endif
- }
- #if 0
- local int scanzipf_fix(f)
- FILE *f;
- {
- ulg a = 0L;
- char b[CENHEAD];
- ush flg;
- int m;
- extent n;
- uzoff_t p;
- uzoff_t s;
- struct zlist far * far *x;
- struct zlist far *z;
- #ifndef ZIP64_SUPPORT
- if (ffile_size( f) == EOF)
- return ZE_ZIP64;
- #endif
-
- # ifndef UTIL
- filetime(zipfile, &a, (zoff_t*)&s, NULL);
- # endif
- x = &zfiles;
- p = 0;
- # ifdef HANDLE_AMIGA_SFX
- amiga_sfx_offset = 0L;
- # endif
-
- for (;;) {
-
- while ((m = getc(f)) != EOF && m != 0x50)
- {
- # ifdef HANDLE_AMIGA_SFX
- if (p == 0 && m == 0)
- amiga_sfx_offset = 1L;
- else if (amiga_sfx_offset) {
- if ((p == 1 && m != 0) || (p == 2 && m != 3)
- || (p == 3 && (uch) m != 0xF3))
- amiga_sfx_offset = 0L;
- }
- # endif
- p++;
- }
-
- b[0] = (char) m;
-
- if (fread(b+1, 3, 1, f) != 1 || (s = LG(b)) == LOCSIG)
- break;
-
-
- if (zfseeko(f, -3L, SEEK_CUR))
- return ferror(f) ? ZE_READ : ZE_EOF;
-
- p++;
- }
- zipbeg = p;
- # ifdef HANDLE_AMIGA_SFX
- if (amiga_sfx_offset && zipbeg >= 12 && (zipbeg & 3) == 0
- && fseek(f, -12L, SEEK_CUR) == 0 && fread(b, 12, 1, f) == 1
- && LG(b + 4) == 0xF1030000 )
- amiga_sfx_offset = zipbeg - 4;
- else
- amiga_sfx_offset = 0L;
- # endif
-
- while (LG(b) == LOCSIG)
- {
- if ((z = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL ||
- zcount + 1 < zcount)
- return ZE_MEM;
- if (fread(b, LOCHEAD, 1, f) != 1) {
- farfree((zvoid far *)z);
- break;
- }
- z->ver = SH(LOCVER + b);
- z->vem = (ush)(dosify ? 20 : OS_CODE + Z_MAJORVER * 10 + Z_MINORVER);
- z->dosflag = dosify;
- flg = z->flg = z->lflg = SH(LOCFLG + b);
- z->how = SH(LOCHOW + b);
- z->tim = LG(LOCTIM + b);
- z->crc = LG(LOCCRC + b);
- z->siz = LG(LOCSIZ + b);
- z->len = LG(LOCLEN + b);
- n = z->nam = SH(LOCNAM + b);
- z->cext = z->ext = SH(LOCEXT + b);
- z->com = 0;
- z->dsk = 0;
- z->att = 0;
- z->atx = dosify ? a & 0xff : a;
- z->mark = 0;
- z->trash = 0;
-
-
- s = fix > 1 ? 0L : z->siz;
-
- z->zname = z->name = z->iname = z->extra = z->cextra = z->comment = NULL;
- z->oname = NULL;
- #ifdef UNICODE_SUPPORT
- z->uname = z->zuname = z->ouname = NULL;
- #endif
-
- *x = z;
- z->nxt = NULL;
- x = &z->nxt;
-
- if (n == 0)
- {
- sprintf(errbuf, "%lu", (ulg)zcount + 1);
- zipwarn("zero-length name for entry #", errbuf);
- # ifndef DEBUG
- return ZE_FORM;
- # endif
- }
- if ((z->iname = malloc(n+1)) == NULL ||
- (z->ext && (z->extra = malloc(z->ext)) == NULL))
- return ZE_MEM;
- if (fread(z->iname, n, 1, f) != 1 ||
- (z->ext && fread(z->extra, z->ext, 1, f) != 1))
- return ferror(f) ? ZE_READ : ZE_EOF;
- # ifdef ZIP64_SUPPORT
-
-
-
-
- zip64_entry = adjust_zip_local_entry(z);
-
- s = fix > 1 ? 0L : z->siz;
- # endif
- if (s && zfseeko(f, (zoff_t)s, SEEK_CUR))
- return ferror(f) ? ZE_READ : ZE_EOF;
-
- z->iname[n] = '\0';
- z->zname = in2ex(z->iname);
- if (z->zname == NULL)
- return ZE_MEM;
- z->name = z->zname;
- z->cextra = z->extra;
- if (noisy) fprintf(mesg, "zip: reading %s\n", z->zname);
-
- z->off = p;
- p += 4 + LOCHEAD + n + z->ext + s;
- zcount++;
-
- if ((flg & 8) != 0) {
-
- if (s == 0) {
- for (;;) {
- while ((m = getc(f)) != EOF && m != 0x50) ;
- b[0] = (char) m;
- if (fread(b+1, 15, 1, f) != 1 || LG(b) == EXTLOCSIG)
- break;
- if (zfseeko(f, -15L, SEEK_CUR))
- return ferror(f) ? ZE_READ : ZE_EOF;
- }
- # ifdef ZIP64_SUPPORT
- if (zip64_entry) {
-
- s = LG(4 + ZIP64_EXTSIZ + b);
- } else {
- s = LG(4 + EXTSIZ + b);
- }
- # else
- s = LG(4 + EXTSIZ + b);
- # endif
- p += s;
- if ((uzoff_t) zftello(f) != p+16L) {
- zipwarn("bad extended local header for ", z->zname);
- return ZE_FORM;
- }
- } else {
-
- Assert(p == zftello(f), "bad compressed size with extended header");
- if (zfseeko(f, p, SEEK_SET) || fread(b, 16, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- if (LG(b) != EXTLOCSIG) {
- zipwarn("extended local header not found for ", z->zname);
- return ZE_FORM;
- }
- }
-
-
- # ifdef ZIP64_SUPPORT
- z->crc = LG(4 + ZIP64_EXTCRC + b);
- z->siz = s;
- z->len = LG(4 + ZIP64_EXTLEN + b);
- # else
- z->crc = LG(4 + EXTCRC + b);
- z->siz = s;
- z->len = LG(4 + EXTLEN + b);
- # endif
- p += 16L;
- }
- else if (fix > 1) {
-
- for (;;) {
- while ((m = getc(f)) != EOF && m != 0x50) p++;
- b[0] = (char) m;
- if (fread(b+1, 3, 1, f) != 1 || (s = LG(b)) == LOCSIG || s == CENSIG)
- break;
- if (zfseeko(f, -3L, SEEK_CUR))
- return ferror(f) ? ZE_READ : ZE_EOF;
- p++;
- }
- s = p - (z->off + 4 + LOCHEAD + n + z->ext);
- if (s != z->siz) {
- fprintf(mesg, " compressed size %s, actual size %s for %s\n",
- zip_fzofft(z->siz, NULL, "u"), zip_fzofft(s, NULL, "u"),
- z->zname);
- z->siz = s;
- }
-
- continue;
- }
-
- if (fread(b, 4, 1, f) != 1)
- break;
- }
- s = p;
- if (LG(b) != CENSIG && noisy) {
- fprintf(mesg, "zip warning: %s %s truncated.\n", zipfile,
- fix > 1 ? "has been" : "would be");
- if (fix == 1) {
- fprintf(mesg,
- "Retry with option -qF to truncate, with -FF to attempt full recovery\n");
- ZIPERR(ZE_FORM, NULL);
- }
- }
- cenbeg = s;
- if (zipbeg && noisy)
- fprintf(mesg, "%s: adjusting offsets for a preamble of %s bytes\n",
- zipfile, zip_fzofft(zipbeg, NULL, "u"));
- return ZE_OK;
- }
- #endif
- #endif
- int readlocal(localz, z)
- struct zlist far **localz;
- struct zlist far *z;
- {
- char buf[LOCHEAD + 1];
- struct zlist far *locz;
- #ifndef UTIL
- ulg start_disk = 0;
- uzoff_t start_offset = 0;
- char *split_path;
- start_disk = z->dsk;
- start_offset = z->off;
-
- if (start_disk != current_in_disk) {
- if (in_file) {
- fclose(in_file);
- in_file = NULL;
- }
- }
- current_in_disk = start_disk;
-
- split_path = get_in_split_path(in_path, current_in_disk);
- if (in_file == NULL) {
- while ((in_file = zfopen(split_path, FOPR)) == NULL) {
-
-
- if (ask_for_split_read_path(start_disk) != ZE_OK) {
- return ZE_ABORT;
- }
- free(split_path);
- split_path = get_in_split_path(in_path, start_disk);
- }
- }
- #endif
-
- if (zfseeko(in_file, z->off, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive fseek: ", strerror(errno));
- return ZE_READ;
- }
- if (!at_signature(in_file, "PK\03\04")) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("Did not find entry for ", z->iname);
- return ZE_FORM;
- }
-
- if (fread(buf, LOCHEAD, 1, in_file) != 1) {
- int f = ferror(in_file);
- zipwarn("reading local entry: ", strerror(errno));
- fclose(in_file);
- return f ? ZE_READ : ZE_EOF;
- }
-
- if ((locz = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL) {
- zipwarn("reading entry", "");
- fclose(in_file);
- return ZE_MEM;
- }
- locz->ver = SH(LOCVER + buf);
- locz->lflg = SH(LOCFLG + buf);
- locz->how = SH(LOCHOW + buf);
- locz->tim = LG(LOCTIM + buf);
- locz->crc = LG(LOCCRC + buf);
- locz->nam = SH(LOCNAM + buf);
- locz->ext = SH(LOCEXT + buf);
-
- locz->zname = locz->name = locz->iname = locz->extra = NULL;
- locz->oname = NULL;
- #ifdef UNICODE_SUPPORT
- locz->uname = NULL;
- locz->zuname = NULL;
- locz->ouname = NULL;
- #endif
-
- if ((locz->iname = malloc(locz->nam+1)) == NULL ||
- (locz->ext && (locz->extra = malloc(locz->ext)) == NULL))
- return ZE_MEM;
- if (fread(locz->iname, locz->nam, 1, in_file) != 1 ||
- (locz->ext && fread(locz->extra, locz->ext, 1, in_file) != 1))
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- locz->iname[z->nam] = '\0';
- #ifdef UNICODE_SUPPORT
- if (unicode_mismatch != 3)
- read_Unicode_Path_local_entry(locz);
- #endif
- #ifdef WIN32
- {
-
- unsigned hostver = (z->vem & 0xff);
- Ext_ASCII_TO_Native(locz->iname, (z->vem >> 8), hostver,
- ((z->atx & 0xffff0000L) != 0), TRUE);
- }
- #endif
- if ((locz->name = malloc(locz->nam+1)) == NULL)
- return ZE_MEM;
- strcpy(locz->name, locz->iname);
- #ifdef ZIP64_SUPPORT
- zip64_entry = adjust_zip_local_entry(locz);
- #endif
-
- if (locz->ver != z->ver) {
- sprintf(errbuf, "Local Version Needed (%d) does not match CD (%d): ", locz->ver, z->ver);
- zipwarn(errbuf, z->iname);
- }
- if (locz->lflg != z->flg) {
- zipwarn("Local Entry Flag does not match CD: ", z->iname);
- }
- if (locz->crc != z->crc) {
- zipwarn("Local Entry CRC does not match CD: ", z->iname);
- }
-
- locz->len = z->len;
- locz->siz = z->siz;
- *localz = locz;
- return ZE_OK;
- }
- #if 0
- local int scanzipf_reg(f)
- FILE *f;
- {
- char b[CENHEAD];
- extent n;
- struct zlist far * far *x;
- struct zlist far *z;
- char *t;
- char far *u;
- int found;
- char *buf;
- # ifdef ZIP64_SUPPORT
- ulg u4;
- char bf[8];
- uzoff_t u8;
- uzoff_t censiz;
- uzoff_t z64eocd;
- # else
- ush flg;
- int m;
- # endif
- zoff_t deltaoff = 0;
- #ifndef ZIP64_SUPPORT
-
- if (ffile_size( f) == EOF)
- return ZE_ZIP64;
- #endif
- buf = malloc(4096 + 4);
- if (buf == NULL)
- return ZE_MEM;
- #ifdef HANDLE_AMIGA_SFX
- amiga_sfx_offset = (fread(buf, 1, 4, f) == 4 && LG(buf) == 0xF3030000);
-
- #endif
-
- zfseeko(f, 0, SEEK_SET);
- read_split_archive = (fread(buf, 1, 4, f) == 4 && LG(buf) == 0x08074b50L);
- found = 0;
- t = &buf[4096];
- t[1] = '\0';
- t[2] = '\0';
- t[3] = '\0';
-
-
- if (zfseeko(f, -4096L, SEEK_END) == 0) {
- zipbeg = (uzoff_t) (zftello(f) + 4096L);
-
- while (!found && zipbeg >= 4096) {
- zipbeg -= 4096L;
- buf[4096] = t[1];
- buf[4097] = t[2];
- buf[4098] = t[3];
- fread(buf, 1, 4096, f);
- zfseeko(f, -8192L, SEEK_CUR);
- t = &buf[4095];
- while (t >= buf) {
-
- if (LG(t) == ENDSIG) {
- found = 1;
- zipbeg += (uzoff_t) (t - buf);
- zfseeko(f, (zoff_t) zipbeg + 4L, SEEK_SET);
- break;
- }
- --t;
- }
- }
- }
- else
-
- zipbeg = 4096L;
- if (!found && zipbeg > 0) {
- size_t s;
- zfseeko(f, 0L, SEEK_SET);
- clearerr(f);
- s = fread(buf, 1, (size_t) zipbeg, f);
-
- buf[s] = t[1];
- buf[s + 1] = t[2];
- buf[s + 2] = t[3];
- t = &buf[s - 1];
- while (t >= buf) {
-
- if (LG(t) == ENDSIG) {
- found = 1;
- zipbeg = (ulg) (t - buf);
- zfseeko(f, (zoff_t) zipbeg + 4L, SEEK_SET);
- break;
- }
- --t;
- }
- }
- free(buf);
- if (!found) {
- zipwarn("missing end signature--probably not a zip file (did you", "");
- zipwarn("remember to use binary mode when you transferred it?)", "");
- return ZE_FORM;
- }
- #ifndef ZIP64_SUPPORT
-
-
- if (zfseeko(f, -24, SEEK_CUR) != 0) {
- perror("fseek");
- return ZE_FORM;
- }
-
- if (fread(b, 20, 1, f) != 1) {
- return ZE_READ;
- }
-
- if (LG(b) == ZIP64_EOCDL_SIG) {
- zipwarn("found Zip64 signature - this may be a Zip64 archive", "");
- zipwarn("PKZIP 4.5 or later needed - set ZIP64_SUPPORT in Zip 3", "");
- return ZE_ZIP64;
- }
-
- if (fread(b, 4, 1, f) != 1) {
- zipwarn("unable to read after relative seek", "");
- return ZE_READ;
- }
- if (LG(b) != ENDSIG) {
- zipwarn("unable to relative seek in archive", "");
- return ZE_FORM;
- }
- #if 0
- if (fseek(f, -4, SEEK_CUR) != 0) {
- perror("fseek");
- return ZE_FORM;
- }
- #endif
- #endif
-
- if (fread(b, ENDHEAD, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- if (SH(ENDDSK + b) || SH(ENDBEG + b) ||
- SH(ENDSUB + b) != SH(ENDTOT + b))
- zipwarn("multiple disk information ignored", "");
- zcomlen = SH(ENDCOM + b);
- if (zcomlen)
- {
- if ((zcomment = malloc(zcomlen)) == NULL)
- return ZE_MEM;
- if (fread(zcomment, zcomlen, 1, f) != 1)
- {
- free((zvoid *)zcomment);
- zcomment = NULL;
- return ferror(f) ? ZE_READ : ZE_EOF;
- }
- #ifdef EBCDIC
- if (zcomment)
- memtoebc(zcomment, zcomment, zcomlen);
- #endif
- }
- #ifdef ZIP64_SUPPORT
-
-
- cenbeg = zipbeg - ZIP64_EOCDL_OFS_SIZE;
-
-
- if (zipbeg >= ZIP64_EOCDL_OFS_SIZE) {
-
- if (zfseeko(f, cenbeg, SEEK_SET)) {
- zipwarn("end of file seeking Z64EOCDL", "");
- return ZE_FORM;
- }
- if (fread(bf, 4, 1, f) != 1) {
- ziperr(ZE_FORM, "read error");
- }
- u4 = LG(bf);
- if (u4 == ZIP64_EOCDL_SIG) {
-
-
- zfseeko(f, cenbeg + ZIP64_EOCDL_OFS_TOTALDISKS, SEEK_SET);
- if (fread(bf, 4, 1, f) != 1) {
- ziperr(ZE_FORM, "read error");
- }
- u4 = LG(bf);
- if (u4 != 1) {
- ziperr(ZE_FORM, "multiple disk archives not yet supported");
- }
-
- zfseeko(f, cenbeg + ZIP64_EOCDL_OFS_EOCD_START, SEEK_SET);
- if (fread(bf, 8, 1, f) != 1) {
- ziperr(ZE_FORM, "read error");
- }
- z64eocd = LLG(bf);
- if (zfseeko(f, z64eocd, SEEK_SET)) {
- ziperr(ZE_FORM, "error searching for Z64 EOCD Record");
- }
- if (fread(bf, 4, 1, f) != 1) {
- ziperr(ZE_FORM, "read error");
- }
- u4 = LG(bf);
- if (u4 != ZIP64_EOCD_SIG) {
- ziperr(ZE_FORM, "Z64 EOCD not found but Z64 EOCD Locator exists");
- }
-
- zfseeko(f, z64eocd + ZIP64_EOCD_OFS_SIZE, SEEK_SET);
- if (fread(bf, 8, 1, f) != 1) {
- ziperr(ZE_FORM, "read error");
- }
- censiz = LLG(bf);
-
- zfseeko(f, z64eocd + ZIP64_EOCD_OFS_CD_START, SEEK_SET);
- if (fread(bf, 8, 1, f) == (size_t) -1) {
- ziperr(ZE_FORM, "read error");
- }
- cenbeg = LLG(bf);
- u8 = z64eocd - cenbeg;
- deltaoff = adjust ? u8 - censiz : 0L;
- } else {
-
- censiz = LG(ENDSIZ + b);
- cenbeg = LG(b + ENDOFF);
- u8 = zipbeg - censiz;
- deltaoff = adjust ? u8 - censiz : 0L;
- }
- }
- #else
-
- cenbeg = zipbeg - LG(ENDSIZ + b);
-
- deltaoff = adjust ? cenbeg - LG(b + ENDOFF) : 0L;
- #endif
- if (zipbeg < ZIP64_EOCDL_OFS_SIZE) {
-
- return ZE_OK;
- }
- if (zfseeko(f, cenbeg, SEEK_SET) != 0) {
- perror("fseek");
- return ZE_FORM;
- }
- x = &zfiles;
- if (fread(b, 4, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- while (LG(b) == CENSIG) {
-
- if (fread(b, CENHEAD, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- if ((z = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL)
- return ZE_MEM;
- z->vem = SH(CENVEM + b);
- for (u = (char far *)(&(z->ver)), n = 0; n < (CENNAM-CENVER); n++)
- u[n] = b[CENVER + n];
- z->nam = SH(CENNAM + b);
- z->cext = SH(CENEXT + b);
- z->com = SH(CENCOM + b);
- z->dsk = SH(CENDSK + b);
- z->att = SH(CENATT + b);
- z->atx = LG(CENATX + b);
- z->off = LG(CENOFF + b) + deltaoff;
- z->dosflag = (z->vem & 0xff00) == 0;
-
- z->zname = z->name = z->iname = z->extra = z->cextra = z->comment = NULL;
- z->oname = NULL;
- #ifdef UNICODE_SUPPORT
- z->uname = NULL;
- z->zuname = NULL;
- z->ouname = NULL;
- #endif
-
- *x = z;
- z->nxt = NULL;
- x = &z->nxt;
-
- if (z->nam == 0)
- {
- sprintf(errbuf, "%lu", (ulg)zcount + 1);
- zipwarn("zero-length name for entry #", errbuf);
- #ifndef DEBUG
- farfree((zvoid far *)z);
- return ZE_FORM;
- #endif
- }
- if ((z->iname = malloc(z->nam+1)) == NULL ||
- (z->cext && (z->cextra = malloc(z->cext)) == NULL) ||
- (z->com && (z->comment = malloc(z->com)) == NULL))
- return ZE_MEM;
- if (fread(z->iname, z->nam, 1, f) != 1 ||
- (z->cext && fread(z->cextra, z->cext, 1, f) != 1) ||
- (z->com && fread(z->comment, z->com, 1, f) != 1))
- return ferror(f) ? ZE_READ : ZE_EOF;
- z->iname[z->nam] = '\0';
- #ifdef EBCDIC
- if (z->com)
- memtoebc(z->comment, z->comment, z->com);
- #endif
- #ifdef ZIP64_SUPPORT
-
-
-
-
-
-
- z->len = LG(CENLEN + b);
- z->siz = LG(CENSIZ + b);
- z->crc = LG(CENCRC + b);
- z->tim = LG(CENTIM + b);
- z->how = SH(CENHOW + b);
- z->flg = SH(CENFLG + b);
- z->ver = SH(CENVER + b);
-
-
-
-
- adjust_zip_central_entry(z);
- #endif
-
- if (z->off < zipbeg)
- zipbeg = z->off;
- zcount++;
-
- if (fread(b, 4, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- }
-
- z = zfiles;
- while (z != NULL) {
-
- if (zfseeko(f, z->off, SEEK_SET) != 0 || fread(b, 4, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- if (LG(b) == LOCSIG) {
- if (fread(b, LOCHEAD, 1, f) != 1)
- return ferror(f) ? ZE_READ : ZE_EOF;
- z->lflg = SH(LOCFLG + b);
- n = SH(LOCNAM + b);
- z->ext = SH(LOCEXT + b);
-
- if (n != z->nam)
- {
- #ifdef EBCDIC
- strtoebc(z->iname, z->iname);
- #endif
- zipwarn("name lengths in local and central differ for ", z->iname);
- return ZE_FORM;
- }
- if ((t = malloc(z->nam)) == NULL)
- return ZE_MEM;
- if (fread(t, z->nam, 1, f) != 1)
- {
- free((zvoid *)t);
- return ferror(f) ? ZE_READ : ZE_EOF;
- }
- if (memcmp(t, z->iname, z->nam))
- {
- free((zvoid *)t);
- #ifdef EBCDIC
- strtoebc(z->iname, z->iname);
- #endif
- zipwarn("names in local and central differ for ", z->iname);
- return ZE_FORM;
- }
- free((zvoid *)t);
- if (z->ext)
- {
- if ((z->extra = malloc(z->ext)) == NULL)
- return ZE_MEM;
- if (fread(z->extra, z->ext, 1, f) != 1)
- {
- free((zvoid *)(z->extra));
- return ferror(f) ? ZE_READ : ZE_EOF;
- }
- if (z->ext == z->cext && memcmp(z->extra, z->cextra, z->ext) == 0)
- {
- free((zvoid *)(z->extra));
- z->extra = z->cextra;
- }
- }
- #ifdef ZIP64_SUPPORT
-
- #else
-
-
- if ((z->lflg & 8) != 0)
- {
- char buf2[16];
- ulg s;
- s = LG(LOCSIZ + b);
- if (s == 0)
- s = LG((CENSIZ-CENVER) + (char far *)(&(z->ver)));
- if (zfseeko(f, (z->off + (4+LOCHEAD) + z->nam + z->ext + s), SEEK_SET)
- || (fread(buf2, 16, 1, f) != 1))
- return ferror(f) ? ZE_READ : ZE_EOF;
- if (LG(buf2) != EXTLOCSIG)
- {
- # ifdef EBCDIC
- strtoebc(z->iname, z->iname);
- # endif
- zipwarn("extended local header not found for ", z->iname);
- return ZE_FORM;
- }
-
- for (n = 0; n < 12; n++)
- b[LOCCRC+n] = buf2[4+n];
- }
-
-
- u = (char far *)(&(z->ver));
- flg = SH((CENFLG-CENVER) + u);
- u[CENFLG-CENVER+1] &= 0x1f;
- b[LOCFLG+1] &= 0x1f;
- for (m = 0, n = 0; n < LOCNAM; n++) {
- if (b[n] != u[n])
- {
- if (!m)
- {
- zipwarn("local and central headers differ for ", z->iname);
- m = 1;
- }
- if (noisy)
- {
- sprintf(errbuf, " offset %u--local = %02x, central = %02x",
- (unsigned)n, (uch)b[n], (uch)u[n]);
- zipwarn(errbuf, "");
- }
- }
- }
- if (m && !adjust)
- return ZE_FORM;
-
- z->len = LG((CENLEN-CENVER) + u);
- z->siz = LG((CENSIZ-CENVER) + u);
- z->crc = LG((CENCRC-CENVER) + u);
- z->tim = LG((CENTIM-CENVER) + u);
- z->how = SH((CENHOW-CENVER) + u);
- z->flg = flg;
- z->ver = SH((CENVER-CENVER) + u);
- #endif
-
- z->mark = 0;
- z->trash = 0;
- #ifdef UNICODE_SUPPORT
- if (unicode_mismatch != 3) {
- read_Unicode_Path_entry(z);
- if (z->uname) {
-
- z->name = utf8_to_local_string(z->uname);
- # ifdef EBCDIC
-
- strtoebc(z->zname, z->name);
- # else
- if ((z->zname = malloc(strlen(z->name) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "scanzipf_reg");
- }
- strcpy(z->zname, z->name);
- # endif
- z->oname = local_to_display_string(z->zname);
- } else {
-
- if ((z->name = malloc(strlen(z->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "scanzipf_reg");
- }
- strcpy(z->name, z->iname);
- if ((z->zname = malloc(strlen(z->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "scanzipf_reg");
- }
- strcpy(z->zname, z->iname);
- z->oname = local_to_display_string(z->iname);
- }
- }
- #else
- # ifdef UTIL
- z->name = z->iname;
- # ifdef EBCDIC
- if ((z->zname = malloc(z->nam+1)) == NULL)
- return ZE_MEM;
- strtoebc(z->zname, z->iname);
- # else
- z->zname = z->iname;
- # endif
- # else
- z->zname = in2ex(z->iname);
- if (z->zname == NULL)
- return ZE_MEM;
- z->name = z->zname;
- # endif
- if ((z->oname = malloc(strlen(z->zname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "scanzipf_reg");
- }
- strcpy(z->oname, z->zname);
- #endif
- }
- else {
- #ifdef EBCDIC
- strtoebc(z->iname, z->iname);
- #endif
- zipwarn("local header not found for ", z->iname);
- return ZE_FORM;
- }
- #ifndef UTIL
- if (verbose && fix == 0)
- zipoddities(z);
- #endif
- z = z->nxt;
- }
- if (zipbeg && noisy)
- fprintf(mesg, "%s: %s a preamble of %s bytes\n",
- zipfile, adjust ? "adjusting offsets for" : "found",
- zip_fzofft(zipbeg, NULL, "u"));
- #ifdef HANDLE_AMIGA_SFX
- if (zipbeg < 12 || (zipbeg & 3) != 0 )
- amiga_sfx_offset = 0;
- else if (amiga_sfx_offset) {
- char buf2[16];
- if (!fseek(f, zipbeg - 12, SEEK_SET) && fread(buf2, 12, 1, f) == 1) {
- if (LG(buf2 + 4) == 0xF1030000 )
-
- amiga_sfx_offset = zipbeg - 4;
- else
- amiga_sfx_offset = 0L;
- }
- }
- #endif
- return ZE_OK;
- }
- #endif
- local char sigbuf[4];
- #if 0
- char *copy_sig(copyto, copyfrom)
- char *copyto;
- char *copyfrom;
- {
- int i;
- for (i = 0; i < 4; i++) {
- copyto[i] = copyfrom[i];
- }
- return copyto;
- }
- #endif
- local int find_next_signature(f)
- FILE *f;
- {
- int m;
-
-
- m = getc(f);
-
- while (m != EOF)
- {
- if (m == 0x50 ) {
-
- sigbuf[0] = (char) m;
- if ((m = getc(f)) == EOF)
- break;
- if (m != 0x4b ) {
-
- ungetc(m, f);
- } else {
-
- sigbuf[1] = (char) m;
- if ((m = getc(f)) == EOF)
- break;
- if (m == 0x50 ) {
-
- ungetc(m, f);
- continue;
- } else if (m >= 16) {
-
- continue;
- }
- sigbuf[2] = (char) m;
- if ((m = getc(f)) == EOF)
- break;
- if (m == 0x50 ) {
-
- ungetc(m, f);
- continue;
- } else if (m >= 16) {
-
- continue;
- }
- sigbuf[3] = (char) m;
-
- return 1;
- }
- }
- m = getc(f);
- }
- if (ferror(f)) {
- return 0;
- }
-
- return 0;
- }
- local int find_signature(f, signature)
- FILE *f;
- ZCONST char *signature;
- {
- int i;
- char sig[4];
-
- for (i = 0; i < 4; i++)
- sig[i] = signature[i];
-
- if (sig[0] == 'P')
- sig[0] = 0x50;
- if (sig[1] == 'K')
- sig[1] = 0x4b;
- while (!feof(f)) {
- if (!find_next_signature(f)) {
- return 0;
- } else {
- for (i = 0; i < 4; i++) {
- if (sig[i] != sigbuf[i]) {
-
- break;
- }
- }
- if (i == 4) {
-
- return 1;
- }
- }
- }
- return 0;
- }
- local int is_signature(sig1, sig2)
- ZCONST char *sig1;
- ZCONST char *sig2;
- {
- int i;
- char tsig1[4];
- char tsig2[4];
- for (i = 0; i < 4; i++) {
- tsig1[i] = sig1[i];
- tsig2[i] = sig2[i];
- }
-
- if (tsig1[0] == 'P')
- tsig1[0] = 0x50;
- if (tsig1[1] == 'K')
- tsig1[1] = 0x4b;
- if (tsig2[0] == 'P')
- tsig2[0] = 0x50;
- if (tsig2[1] == 'K')
- tsig2[1] = 0x4b;
- for (i = 0; i < 4; i++) {
- if (tsig1[i] != tsig2[i]) {
-
- break;
- }
- }
- if (i == 4) {
-
- return 1;
- }
- return 0;
- }
- local int at_signature(f, signature)
- FILE *f;
- ZCONST char *signature;
- {
- int i;
- extent m;
- char sig[4];
- char b[4];
- for (i = 0; i < 4; i++)
- sig[i] = signature[i];
-
- if (sig[0] == 'P')
- sig[0] = 0x50;
- if (sig[1] == 'K')
- sig[1] = 0x4b;
- m = fread(b, 1, 4, f);
- if (m != 4) {
- return 0;
- } else {
- for (i = 0; i < 4; i++) {
- if (sig[i] != b[i]) {
-
- break;
- }
- }
- if (i == 4) {
-
- return 1;
- }
- }
- return 0;
- }
- #ifndef UTIL
- local int scanzipf_fixnew()
- {
-
- # if CENHEAD > ENDHEAD
- # define FIXSCAN_BUFSIZE CENHEAD
- # else
- # define FIXSCAN_BUFSIZE ENDHEAD
- # endif
- char scbuf[FIXSCAN_BUFSIZE];
- char *split_path;
- ulg eocdr_disk;
- uzoff_t eocdr_offset;
- uzoff_t current_offset = 0;
- uzoff_t offset = 0;
- int skip_disk = 0;
- int skipped_disk = 0;
- int r = 0;
- uzoff_t s;
- struct zlist far * far *x;
- struct zlist far *z;
- int plen;
- char *in_path_ext;
- int in_central_directory = 0;
- struct zlist far *cz;
- uzoff_t cd_total_entries = 0;
- ulg in_cd_start_disk;
- uzoff_t in_cd_start_offset;
- total_disks = 1000000;
-
-
-
- plen = strlen(in_path);
- #ifdef VMS
-
- plen -= strlen(vms_file_version(in_path));
- #endif
- in_path_ext = zipfile + plen - 4;
- if (plen >= 4 &&
- in_path_ext[0] == '.' &&
- toupper(in_path_ext[1]) == 'Z' &&
- in_path_ext[2] >= '0' && in_path_ext[2] <= '9' &&
- in_path_ext[3] >= '0' && in_path_ext[3] <= '9' &&
- (plen == 4 || (in_path_ext[4] >= '0' && in_path_ext[4] <= '9'))) {
-
- strcpy(errbuf, "if archive to fix is split archive, need to provide\n");
- strcat(errbuf, " path of the last split with .zip extension,\n");
- strcat(errbuf, " even if it doesn't exist (zip will ask for splits)");
- zipwarn(errbuf, "");
- return ZE_FORM;
- }
- if ((in_file = zfopen(in_path, FOPR)) == NULL) {
- zipwarn("could not open input archive: ", in_path);
- }
- else
- {
- #ifndef ZIP64_SUPPORT
-
- if (ffile_size( in_file) == EOF) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("input file requires Zip64 support: ", in_path);
- return ZE_ZIP64;
- }
- #endif
-
-
- if (zfseeko(in_file, -0x40000L, SEEK_END) != 0) {
-
- if (zfseeko(in_file, 0L, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", in_path);
- return ZE_READ;
- }
- }
-
- if (!find_signature(in_file, "PK\05\06")) {
-
- strcpy(errbuf, "Missing end (EOCDR) signature - either this archive\n");
- strcat(errbuf, " is not readable or the end is damaged");
- zipwarn(errbuf, "");
- }
- else
- {
-
- eocdr_offset = (uzoff_t) zftello(in_file);
-
- while (find_signature(in_file, "PK\05\06")) {
- eocdr_offset = (uzoff_t) zftello(in_file);
- }
-
-
- if (zfseeko(in_file, eocdr_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", in_path);
- return ZE_READ;
- }
-
- s = fread(scbuf, 1, ENDHEAD, in_file);
-
- if (s < ENDHEAD) {
- sprintf(errbuf, "End record (EOCDR) only %s bytes - assume truncated",
- zip_fzofft(s, NULL, "u"));
- zipwarn(errbuf, "");
- }
- else
- {
-
- eocdr_disk = (ulg)SH(scbuf);
- total_disks = eocdr_disk + 1;
-
- current_in_disk = total_disks - 1;
-
- in_cd_start_disk = (ulg)SH(scbuf + 2);
- in_cd_start_offset = (uzoff_t)LG(scbuf + 12);
- cd_total_entries = (uzoff_t)SH(scbuf + 6);
-
- if (total_disks < 0x10000 && in_cd_start_disk > total_disks) {
- zipwarn("End record (EOCDR) has bad disk numbers - ignoring EOCDR", "");
- total_disks = 0;
- }
- else
- {
-
- zcomlen = SH(scbuf + ENDCOM);
- if (zcomlen)
- {
- if ((zcomment = malloc(zcomlen + 1)) == NULL)
- return ZE_MEM;
- if (fread(zcomment, zcomlen, 1, in_file) != 1)
- {
- free((zvoid *)zcomment);
- zcomment = NULL;
- zipwarn("zipfile comment truncated - ignoring", "");
- } else {
- zcomment[zcomlen] = '\0';
- }
- #ifdef EBCDIC
- if (zcomment)
- memtoebc(zcomment, zcomment, zcomlen);
- #endif
- }
- }
- if (total_disks != 1)
- sprintf(errbuf, " Found end record (EOCDR) - says expect %lu splits", total_disks);
- else
- sprintf(errbuf, " Found end record (EOCDR) - says expect single disk archive");
- zipmessage(errbuf, "");
- if (zcomment)
- zipmessage(" Found archive comment", "");
- }
- }
-
-
-
- if (total_disks == 0) {
- int issig;
-
- if (zfseeko(in_file, 0, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", in_path);
- return ZE_READ;
- }
-
- issig = find_next_signature(in_file);
- if (issig) {
- current_in_offset = zftello(in_file);
- if (current_in_offset == 4 && is_signature(sigbuf, "PK\03\03")) {
-
-
- issig = find_next_signature(in_file);
- } else if (current_in_offset <= 4 && is_signature(sigbuf, "PK\03\03")) {
-
- total_disks = 99999;
- }
- }
- if (issig && total_disks == 0) {
- current_in_offset = zftello(in_file);
- if (current_in_offset == 8 && is_signature(sigbuf, "PK\03\04")) {
-
- printf("Is this a single-disk archive? (y/n): ");
- fflush(stdout);
- if (fgets(errbuf, 100, stdin) != NULL) {
- if (errbuf[0] == 'y' || errbuf[0] == 'Y') {
- total_disks = 1;
- zipmessage(" Assuming single-disk archive", "");
- }
- }
- }
- }
- }
- if (!noisy)
-
- total_disks = 1;
- if (total_disks == 1000000) {
-
- printf("Is this a single-disk archive? (y/n): ");
- fflush(stdout);
- if (fgets(errbuf, 100, stdin) != NULL) {
- if (errbuf[0] == 'y' || errbuf[0] == 'Y') {
- total_disks = 1;
- zipmessage(" Assuming single-disk archive", "");
- }
- }
- }
- if (total_disks == 1000000) {
-
- total_disks = 100000;
- }
- }
-
-
-
-
- if (noisy && in_file) {
- fclose(in_file);
- in_file = NULL;
- }
-
- zipmessage("Scanning for entries...", "");
- for (current_in_disk = 0; current_in_disk < total_disks; current_in_disk++) {
-
- split_path = get_in_split_path(in_path, current_in_disk);
-
- if (in_file == NULL) {
-
- while ((in_file = zfopen(split_path, FOPR)) == NULL) {
- int result;
-
-
- result = ask_for_split_read_path(current_in_disk);
- if (result == ZE_ABORT) {
- zipwarn("could not find split: ", split_path);
- return ZE_ABORT;
- } else if (result == ZE_EOF) {
- zipmessage_nl("", 1);
- zipwarn("user ended reading - closing archive", "");
- return ZE_EOF;
- } else if (result == ZE_FORM) {
-
- zipmessage_nl("", 1);
- sprintf(errbuf, "skipping disk %lu ...\n", current_in_disk);
- zipwarn(errbuf, "");
- skip_disk = 1;
- break;
- }
- split_path = get_in_split_path(in_path, current_in_disk);
- }
- if (skip_disk) {
-
- skip_disk = 0;
- skipped_disk = 1;
- continue;
- }
- }
- if (skipped_disk) {
-
- }
-
-
- while (find_next_signature(in_file)) {
- current_in_offset = zftello(in_file);
- if (is_signature(sigbuf, "PK\05\06")) {
-
- sprintf(errbuf, "EOCDR found (%2lu %6s)...",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 1);
- } else if (is_signature(sigbuf, "PK\06\06")) {
-
- sprintf(errbuf, "Zip64 EOCDR found (%2lu %6s)...",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 1);
- } else if (is_signature(sigbuf, "PK\06\07")) {
-
- sprintf(errbuf, "Zip64 EOCDL found (%2lu %6s)...",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 1);
- } else if (is_signature(sigbuf, "PK\03\04")) {
-
- if (verbose) {
- sprintf(errbuf, " Local (%2lu %6s):",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 0);
- }
-
- if ((z = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL) {
- zipwarn("reading central directory", "");
- return ZE_MEM;
- }
- z->vem = 0;
- z->ver = 0;
- z->flg = 0;
- z->how = 0;
- z->tim = 0;
- z->crc = 0;
- z->siz = 0;
- z->len = 0;
- z->nam = 0;
- z->cext = 0;
- z->com = 0;
- z->dsk = 0;
- z->att = 0;
- z->atx = 0;
- z->off = 0;
- z->dosflag = 0;
-
- z->zname = z->name = z->iname = z->extra = z->cextra = z->comment = NULL;
- z->oname = NULL;
- #ifdef UNICODE_SUPPORT
- z->uname = z->zuname = z->ouname = NULL;
- #endif
-
- r = zipcopy(z);
- if (in_central_directory) {
- sprintf(errbuf, "Entry after central directory found (%2lu %6s)...",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 1);
- in_central_directory = 0;
- }
- if (r == ZE_EOF)
-
- break;
- else if (r == ZE_OK) {
- zcount++;
- files_total++;
- bytes_total += z->siz;
-
- if (zfiles == NULL)
-
- x = &zfiles;
-
- *x = z;
- z->nxt = NULL;
- x = &z->nxt;
- }
- } else if (is_signature(sigbuf, "PK\01\02")) {
-
-
- if (in_central_directory == 0) {
- zipmessage("Central Directory found...", "");
-
- if (zcount)
- {
- struct zlist far * far *x;
- struct zlist far *z;
- int i = 0;
- extent zl_size = zcount * sizeof(struct zlist far *);
- if (zl_size / sizeof(struct zlist far *) != zcount ||
- (x = zsort = (struct zlist far **)malloc(zl_size)) == NULL)
- return ZE_MEM;
- for (z = zfiles; z != NULL; z = z->nxt)
- x[i++] = z;
- qsort((char *)zsort, zcount, sizeof(struct zlist far *), zqcmp);
-
- }
- }
- if (verbose) {
- sprintf(errbuf, " Cen (%2lu %6s): ",
- current_in_disk + 1, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipmessage_nl(errbuf, 0);
- }
- in_central_directory = 1;
-
-
-
- if (fread(scbuf, CENHEAD, 1, in_file) != 1) {
- zipwarn("reading central directory: ", strerror(errno));
- zipwarn("bad archive - error reading central directory", "");
- zipwarn("skipping this entry...", "");
- continue;
- }
- if ((cz = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL) {
- zipwarn("reading central directory", "");
- return ZE_MEM;
- }
- cz->vem = SH(CENVEM + scbuf);
- cz->ver = SH(CENVER + scbuf);
- cz->flg = SH(CENFLG + scbuf);
- cz->how = SH(CENHOW + scbuf);
- cz->tim = LG(CENTIM + scbuf);
- cz->crc = LG(CENCRC + scbuf);
- cz->siz = LG(CENSIZ + scbuf);
- cz->len = LG(CENLEN + scbuf);
- cz->nam = SH(CENNAM + scbuf);
- cz->cext = SH(CENEXT + scbuf);
- cz->com = SH(CENCOM + scbuf);
- cz->dsk = SH(CENDSK + scbuf);
- cz->att = SH(CENATT + scbuf);
- cz->atx = LG(CENATX + scbuf);
- cz->off = LG(CENOFF + scbuf);
- cz->dosflag = (cz->vem & 0xff00) == 0;
-
- cz->zname = cz->name = cz->iname = cz->extra = cz->cextra = NULL;
- cz->comment = cz->oname = NULL;
- #ifdef UNICODE_SUPPORT
- cz->uname = cz->zuname = cz->ouname = NULL;
- #endif
-
- if (cz->nam == 0)
- {
- sprintf(errbuf, "%lu", (ulg)zcount + 1);
- zipwarn("zero-length name for entry #", errbuf);
- zipwarn("skipping this entry...", "");
- continue;
- }
- if ((cz->iname = malloc(cz->nam+1)) == NULL ||
- (cz->cext && (cz->cextra = malloc(cz->cext + 1)) == NULL) ||
- (cz->com && (cz->comment = malloc(cz->com + 1)) == NULL))
- return ZE_MEM;
- if (fread(cz->iname, cz->nam, 1, in_file) != 1 ||
- (cz->cext && fread(cz->cextra, cz->cext, 1, in_file) != 1) ||
- (cz->com && fread(cz->comment, cz->com, 1, in_file) != 1)) {
- zipwarn("error reading entry: ", strerror(errno));
- zipwarn("skipping this entry...", "");
- continue;
- }
- cz->iname[cz->nam] = '\0';
-
- z = zsearch(cz->iname);
- if (z && z->tim == cz->tim) {
-
- if (verbose) {
-
- sprintf(errbuf, "updating: %s", cz->iname);
- zipmessage_nl(errbuf, 0);
- }
- if (z->crc != cz->crc) {
- sprintf(errbuf, "local (%lu) and cen (%lu) crc mismatch", z->crc, cz->crc);
- zipwarn(errbuf, "");
- }
- z->vem = cz->vem;
-
-
-
-
-
-
-
-
- z->cext = cz->cext;
- z->com = cz->com;
- z->cextra = cz->cextra;
- z->comment = cz->comment;
-
- z->att = cz->att;
- z->atx = cz->atx;
-
- z->dosflag = cz->dosflag;
- #ifdef UNICODE_SUPPORT
- if (unicode_mismatch != 3 && z->uname == NULL) {
- if (z->flg & UTF8_BIT) {
-
- if ((z->uname = malloc(strlen(z->iname) + 1)) == NULL) {
- ZIPERR(ZE_MEM, "reading archive");
- }
- strcpy(z->uname, z->iname);
- } else {
-
- read_Unicode_Path_entry(z);
- }
- }
- #endif
- #ifdef WIN32
-
- {
- unsigned hostver = (z->vem & 0xff);
- Ext_ASCII_TO_Native(z->iname, (z->vem >> 8), hostver,
- ((z->atx & 0xffff0000L) != 0), FALSE);
- }
- #endif
- #ifdef EBCDIC
- if (z->com)
- memtoebc(z->comment, z->comment, z->com);
- #endif
- #ifdef WIN32
-
- {
- unsigned hostver = (z->vem & 0xff);
- Ext_ASCII_TO_Native(z->comment, (z->vem >> 8), hostver,
- ((z->atx & 0xffff0000L) != 0), FALSE);
- }
- #endif
- #ifdef ZIP64_SUPPORT
-
-
-
-
-
-
-
-
-
-
-
- #endif
-
- #ifndef UTIL
- if (verbose)
- zipoddities(z);
- #endif
- current_offset = zftello(y);
- if (zfseeko(y, z->off, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("writing archive seek: ", strerror(errno));
- return ZE_WRITE;
- }
- if (putlocal(z, PUTLOCAL_REWRITE) != ZE_OK)
- zipwarn("Error rewriting local header", "");
- if (zfseeko(y, current_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("write archive seek: ", strerror(errno));
- return ZE_WRITE;
- }
- offset = zftello(y);
- if (current_offset != offset) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("seek after local: ", strerror(errno));
- return ZE_WRITE;
- }
- if (verbose)
- zipmessage_nl("", 1);
- } else {
-
- sprintf(errbuf, "no local entry: %s", cz->iname);
- zipmessage_nl(errbuf, 1);
- }
- } else if (zfiles == NULL && is_signature(sigbuf, "PK\07\010")) {
-
- if (total_disks == 1) {
- zipmessage(" Found spanning marker, but did not expect split (multi-disk) archive...", "");
- } else if (total_disks > 1) {
- zipmessage(" Found spanning marker - expected as this is split (multi-disk) archive...", "");
- } else {
- zipmessage(" Found spanning marker - could be split archive...", "");
- }
- } else {
-
- int c;
- char errbuftemp[40];
- strcpy(errbuf, "unexpected signature ");
- for (c = 0; c < 4; c++) {
- sprintf(errbuftemp, "%02x ", sigbuf[c]);
- strcat(errbuf, errbuftemp);
- }
- sprintf(errbuftemp, "on disk %lu at %s\n", current_in_disk,
- zip_fzofft(current_in_offset - 4, NULL, "u"));
- strcat(errbuf, errbuftemp);
- zipwarn(errbuf, "");
- zipwarn("skipping this signature...", "");
- }
- }
-
- if (in_file)
- fclose(in_file);
- in_file = NULL;
- free(split_path);
- if (r == ZE_EOF)
-
- break;
- }
- return ZE_OK;
- }
- #endif
- local int scanzipf_regnew()
- {
-
- # if CENHEAD > ENDHEAD
- # define SCAN_BUFSIZE CENHEAD
- # else
- # define SCAN_BUFSIZE ENDHEAD
- # endif
- #ifdef ZIP64_SUPPORT
- # if EC64REC > SCAN_BUFSIZE
- # undef SCAN_BUFSIZE
- # define SCAN_BUFSIZE EC64REC
- # endif
- # if EC64LOC > SCAN_BUFSIZE
- # undef SCAN_BUFSIZE
- # define SCAN_BUFSIZE EC64LOC
- # endif
- #endif
- char scbuf[SCAN_BUFSIZE];
- char *split_path;
- ulg eocdr_disk;
- uzoff_t eocdr_offset;
- # ifdef ZIP64_SUPPORT
- ulg z64eocdr_disk;
- uzoff_t z64eocdr_offset;
- uzoff_t z64eocdr_size;
- ush version_made;
- ush version_needed = 0;
- zoff_t zip64_eocdr_start;
- zoff_t z64eocdl_offset;
- # endif
- uzoff_t cd_total_entries;
- ulg in_cd_start_disk;
- uzoff_t in_cd_start_offset;
- uzoff_t adjust_offset = 0;
- uzoff_t cd_total_size = 0;
- int first_CD = 1;
- int zipbegset = 0;
- int skip_disk = 0;
- int skipped_disk = 0;
- uzoff_t s;
- struct zlist far * far *x;
- struct zlist far *z;
-
- if ((in_file = zfopen(in_path, FOPR)) == NULL) {
- zipwarn("could not open input archive", in_path);
- return ZE_OPEN;
- }
- #ifndef ZIP64_SUPPORT
-
- if (ffile_size( in_file) == EOF) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("input file requires Zip64 support: ", in_path);
- return ZE_ZIP64;
- }
- #endif
-
-
- if ((zfseeko(in_file, -0x20000L, SEEK_END) != 0) ||
-
- (zftello(in_file) == (zoff_t)-1L)) {
-
- if (zfseeko(in_file, 0L, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", in_path);
- return ZE_READ;
- }
- }
-
- if (!find_signature(in_file, "PK\05\06")) {
-
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("bad archive - missing end signature", "");
- zipwarn("(If downloaded, was binary mode used? If not, the", "");
- zipwarn(" archive may be scrambled and not recoverable)", "");
- zipwarn("Can't use -F to fix (try -FF)", "");
- } else{
- zipwarn("missing end signature--probably not a zip file (did you", "");
- zipwarn("remember to use binary mode when you transferred it?)", "");
- zipwarn("(if you are trying to read a damaged archive try -F)", "");
- }
- return ZE_FORM;
- }
-
- eocdr_offset = (uzoff_t) zftello(in_file);
-
- while (find_signature(in_file, "PK\05\06")) {
-
- eocdr_offset = (uzoff_t) zftello(in_file);
- }
-
-
- if (zfseeko(in_file, eocdr_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", in_path);
- return ZE_READ;
- }
-
- s = fread(scbuf, 1, ENDHEAD, in_file);
-
- eocdr_disk = (ulg)SH(scbuf);
- total_disks = eocdr_disk + 1;
-
- current_in_disk = total_disks - 1;
-
- in_cd_start_disk = (ulg)SH(scbuf + ENDBEG);
- in_cd_start_offset = (uzoff_t)LG(scbuf + ENDOFF);
- cd_total_entries = (uzoff_t)SH(scbuf + ENDTOT);
- cd_total_size = (uzoff_t)LG(scbuf + ENDSIZ);
-
- zcomlen = SH(scbuf + ENDCOM);
- if (zcomlen)
- {
- if ((zcomment = malloc(zcomlen + 1)) == NULL)
- return ZE_MEM;
- if (fread(zcomment, zcomlen, 1, in_file) != 1)
- {
- free((zvoid *)zcomment);
- zcomment = NULL;
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- }
- zcomment[zcomlen] = '\0';
- #ifdef EBCDIC
- if (zcomment)
- memtoebc(zcomment, zcomment, zcomlen);
- #endif
- }
- if (cd_total_entries == 0) {
-
- fclose(in_file);
- in_file = NULL;
- return ZE_OK;
- }
-
- if (total_disks != 1) {
-
- int plen = strlen(in_path);
- char *in_path_ext;
- if (adjust) {
- zipwarn("Adjusting split archives not yet supported", "");
- return ZE_FORM;
- }
- #ifdef VMS
-
- plen -= strlen(vms_file_version(in_path));
- #endif
- in_path_ext = zipfile + plen - 4;
- if (plen < 4 ||
- in_path_ext[0] != '.' ||
- toupper(in_path_ext[1]) != 'Z' ||
- toupper(in_path_ext[2]) != 'I' ||
- toupper(in_path_ext[3]) != 'P') {
- zipwarn("archive name must end in .zip for splits", "");
- fclose(in_file);
- in_file = NULL;
- return ZE_PARMS;
- }
- }
-
- if ((total_disks != 1 || split_method) && !show_files &&
- strcmp(in_path, out_path) == 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("cannot update a split archive (use --out option)", "");
- return ZE_PARMS;
- }
-
- if (fix == 1 && strcmp(in_path, out_path) == 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("must use --out when fixing an archive", "");
- return ZE_PARMS;
- }
-
-
- if ((fix == 1 && total_disks == 1) || adjust) {
- zoff_t cd_start;
- # ifdef ZIP64_SUPPORT
- zoff_t zip64_eocdr_start;
- # endif
-
- if (in_cd_start_offset != 0xFFFFFFFF && cd_total_size != 0xFFFFFFFF) {
-
-
- cd_start = eocdr_offset - cd_total_size - 24 - 56;
- if (zfseeko(in_file, cd_start, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("could not seek back to start of central directory: ", strerror(errno));
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("reading archive fseek: ", strerror(errno));
- }
- return ZE_FORM;
- }
- if (find_signature(in_file, "PK\01\02")) {
-
- adjust_offset = zftello(in_file) - 4 - in_cd_start_offset;
- } else {
- zipwarn("central dir not where expected - could not adjust offsets", "");
- zipwarn("(try -FF)", "");
- return ZE_FORM;
- }
- } else {
-
-
-
-
- if (zfseeko(in_file, eocdr_offset - 24, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("could not seek back to Zip64 EOCDL: ", strerror(errno));
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("reading archive fseek: ", strerror(errno));
- }
- return ZE_FORM;
- }
- if (at_signature(in_file, "PK\06\07"))
- #ifndef ZIP64_SUPPORT
- {
- fclose(in_file);
- in_file = NULL;
- zipwarn("found Zip64 signature - this may be a Zip64 archive", "");
- zipwarn("Need PKZIP 4.5 or later compatible zip", "");
- zipwarn("Set ZIP64_SUPPORT in Zip 3", "");
- return ZE_ZIP64;
- }
- #else
- {
- z64eocdl_offset = zftello(in_file) - 4;
-
- if (fread(scbuf, EC64LOC, 1, in_file) != 1) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive: ", strerror(errno));
- return ZE_READ;
- }
-
- if (!at_signature(in_file, "PK\05\06")) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to read EOCD after seek: ", in_path);
- return ZE_READ;
- }
-
- z64eocdr_disk = LG(scbuf);
- z64eocdr_offset = LLG(scbuf + 4);
- total_disks = LG(scbuf + 12);
-
- if (total_disks != 1) {
- zipwarn("Adjusting split archives not supported: ", in_path);
- zipwarn("(try -FF)", "");
- return ZE_FORM;
- }
-
- if (zfseeko(in_file, z64eocdr_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive fseek: ", strerror(errno));
- return ZE_FORM;
- }
-
- if (at_signature(in_file, "PK\06\06")) {
-
- } else {
-
- zip64_eocdr_start = z64eocdl_offset - 24 - 56;
- if (zfseeko(in_file, zip64_eocdr_start, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("could not seek back to Zip64 EOCDR: ", strerror(errno));
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("reading archive fseek: ", strerror(errno));
- }
- return ZE_FORM;
- }
- if (find_next_signature(in_file) && is_signature(sigbuf, "PK\06\06")) {
-
- adjust_offset = zftello(in_file) - 4 - z64eocdr_offset;
- } else {
- zipwarn("Could not determine offset of entries", "");
- zipwarn("(try -FF)", "");
- return ZE_FORM;
- }
- }
- }
- #endif
- }
- if (noisy) {
- if (adjust_offset) {
- sprintf(errbuf, "Zip entry offsets appear off by %s bytes - correcting...",
- zip_fzofft(adjust_offset, NULL, NULL));
- } else {
- sprintf(errbuf, "Zip entry offsets do not need adjusting");
- }
- zipmessage(errbuf, "");
- }
- }
-
-
-
- if (zfseeko(in_file, eocdr_offset - 24, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("bad archive - could not seek back to Zip64 EOCDL: ", strerror(errno));
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("reading archive fseek: ", strerror(errno));
- }
- return ZE_FORM;
- }
- if (at_signature(in_file, "PK\06\07"))
- #ifndef ZIP64_SUPPORT
- {
- fclose(in_file);
- in_file = NULL;
- zipwarn("found Zip64 signature - this may be a Zip64 archive", "");
- zipwarn("Need PKZIP 4.5 or later compatible zip", "");
- zipwarn("Set ZIP64_SUPPORT in Zip 3", "");
- return ZE_ZIP64;
- }
- #else
- {
- z64eocdl_offset = zftello(in_file) - 4;
-
- if (fread(scbuf, EC64LOC, 1, in_file) != 1) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive: ", strerror(errno));
- return ZE_READ;
- }
-
- if (!at_signature(in_file, "PK\05\06")) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to read EOCD after seek: ", in_path);
- return ZE_READ;
- }
-
- z64eocdr_disk = LG(scbuf);
- z64eocdr_offset = LLG(scbuf + 4) + adjust_offset;
- total_disks = LG(scbuf + 12);
-
- current_in_disk = total_disks - 1;
-
- if (z64eocdr_disk != total_disks - 1) {
-
-
- fclose(in_file);
- in_file = NULL;
-
- split_path = get_in_split_path(in_path, z64eocdr_disk);
- while ((in_file = zfopen(split_path, FOPR)) == NULL) {
-
-
- if (ask_for_split_read_path(z64eocdr_disk) != ZE_OK) {
- return ZE_ABORT;
- }
- free(split_path);
- split_path = get_in_split_path(in_path, z64eocdr_disk);
- }
- free(split_path);
- }
- current_in_disk = z64eocdr_disk;
-
- if (zfseeko(in_file, z64eocdr_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive fseek: ", strerror(errno));
- return ZE_FORM;
- }
-
- if (!at_signature(in_file, "PK\06\06")) {
-
- zip64_eocdr_start = z64eocdl_offset - 24 - 56;
- if (zfseeko(in_file, zip64_eocdr_start, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("bad archive - could not seek back to Zip64 EOCDR: ", strerror(errno));
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("reading archive fseek: ", strerror(errno));
- }
- return ZE_FORM;
- }
- if (find_next_signature(in_file) && is_signature(sigbuf, "PK\06\06")) {
-
- adjust_offset = zftello(in_file) - 4 - z64eocdr_offset;
- zipwarn("Zip64 EOCDR not found where expected - compensating", "");
- zipwarn("(try -A to adjust offsets)", "");
- } else {
- fclose(in_file);
- in_file = NULL;
- if (fix == 1) {
- zipwarn("bad archive - Zip64 EOCDR not found in split: ", in_path);
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("Zip64 End Of Central Directory Record not found: ", in_path);
- }
- return ZE_FORM;
- }
- }
-
-
-
- s = fread(scbuf, 1, EC64REC, in_file);
- if (s < EC64REC) {
- if (fix == 1) {
- zipwarn("bad archive - Zip64 EOCDR bad or truncated", "");
- zipwarn("(try -FF)", "");
- } else {
- zipwarn("Zip64 EOCD Record bad or truncated", "");
- }
- fclose(in_file);
- in_file = NULL;
- return ZE_FORM;
- }
- z64eocdr_size = LLG(scbuf);
- version_made = SH(scbuf + 8);
- version_needed = SH(scbuf + 10);
- in_cd_start_disk = LG(scbuf + 16);
- cd_total_entries = LLG(scbuf + 28);
- in_cd_start_offset = LLG(scbuf + 44) + adjust_offset;
- if (version_needed > 46) {
- int major = version_needed / 10;
- int minor = version_needed - (major * 10);
- sprintf(errbuf, "This archive requires version %d.%d", major, minor);
- zipwarn(errbuf, "");
- zipwarn("Zip currently only supports up to version 4.6 archives", "");
- zipwarn("(up to 4.5 if bzip2 is not compiled in)", "");
- if (fix == 1)
- zipwarn("If -F fails try -FF to try to salvage something", "");
- else if (fix == 2)
- zipwarn("Attempting to salvage what can", "");
- else {
- zipwarn("Try -F to attempt to read anyway", "");
- fclose(in_file);
- in_file = NULL;
- return ZE_FORM;
- }
- }
- }
- #endif
-
-
- in_cd_start_offset += adjust_offset;
- cenbeg = in_cd_start_offset;
- zipbegset = 0;
- zipbeg = 0;
- first_CD = 1;
-
- if (current_in_disk != in_cd_start_disk) {
-
- fclose(in_file);
- in_file = NULL;
- }
-
- for (current_in_disk = in_cd_start_disk;
- current_in_disk < total_disks;
- current_in_disk++) {
-
- if (current_in_disk == total_disks - 1) {
-
- if ((split_path = malloc(strlen(in_path) + 1)) == NULL) {
- zipwarn("reading archive: ", in_path);
- return ZE_MEM;
- }
- strcpy(split_path, in_path);
- } else {
-
- split_path = get_in_split_path(in_path, current_in_disk);
- }
-
- if (in_file == NULL) {
-
- while ((in_file = zfopen(split_path, FOPR)) == NULL) {
- int result;
-
-
- result = ask_for_split_read_path(current_in_disk);
- if (result == ZE_ABORT) {
- zipwarn("could not find split: ", split_path);
- return ZE_ABORT;
- } else if (result == ZE_FORM) {
-
- sprintf(errbuf, "skipping disk %lu ...\n", current_in_disk);
- zipwarn(errbuf, "");
- skip_disk = 1;
- break;
- }
- if (current_in_disk == total_disks - 1) {
-
- if ((split_path = malloc(strlen(in_path) + 1)) == NULL) {
- zipwarn("reading archive: ", in_path);
- return ZE_MEM;
- }
- strcpy(split_path, in_path);
- } else {
-
- split_path = get_in_split_path(zipfile, current_in_disk);
- }
- }
- if (skip_disk) {
-
- skip_disk = 0;
- skipped_disk = 1;
- continue;
- }
- }
- if (skipped_disk) {
-
- first_CD = 0;
- } else {
-
- if (first_CD) {
- if (zfseeko(in_file, in_cd_start_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("unable to seek in input file ", split_path);
- return ZE_READ;
- }
- first_CD = 0;
- x = &zfiles;
- }
- }
-
-
- while (find_next_signature(in_file)) {
- current_in_offset = zftello(in_file);
- if (is_signature(sigbuf, "PK\05\06")) {
-
-
- break;
- } else if (is_signature(sigbuf, "PK\06\06")) {
-
-
- break;
- } else if (!is_signature(sigbuf, "PK\01\02")) {
-
-
- if (fix == 1) {
- int c;
- char errbuftemp[40];
- strcpy(errbuf, "bad archive - unexpected signature ");
- for (c = 0; c < 4; c++) {
- sprintf(errbuftemp, "%02x ", sigbuf[c]);
- strcat(errbuf, errbuftemp);
- }
- sprintf(errbuftemp, "on disk %lu at %s\n", current_in_disk,
- zip_fzofft(current_in_offset - 4, NULL, "u"));
- strcat(errbuf, errbuftemp);
- zipwarn(errbuf, "");
- zipwarn("skipping this signature...", "");
- continue;
- } else {
- sprintf(errbuf, "unexpected signature on disk %lu at %s\n",
- current_in_disk, zip_fzofft(current_in_offset - 4, NULL, "u"));
- zipwarn(errbuf, "");
- zipwarn("archive not in correct format: ", split_path);
- zipwarn("(try -F to attempt recovery)", "");
- fclose(in_file);
- in_file = NULL;
- return ZE_FORM;
- }
- }
-
- if (verbose && fix == 1) {
- fprintf(mesg, "central directory header signature on disk %lu at %s\n",
- current_in_disk, zip_fzofft(current_in_offset - 4, NULL, "u"));
- }
-
- if (fread(scbuf, CENHEAD, 1, in_file) != 1) {
- zipwarn("reading central directory: ", strerror(errno));
- if (fix == 1) {
- zipwarn("bad archive - error reading central directory", "");
- zipwarn("skipping this entry...", "");
- continue;
- } else {
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- }
- }
- if ((z = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL) {
- zipwarn("reading central directory", "");
- return ZE_MEM;
- }
- z->vem = SH(CENVEM + scbuf);
- z->ver = SH(CENVER + scbuf);
- z->flg = SH(CENFLG + scbuf);
- z->how = SH(CENHOW + scbuf);
- z->tim = LG(CENTIM + scbuf);
- z->crc = LG(CENCRC + scbuf);
- z->siz = LG(CENSIZ + scbuf);
- z->len = LG(CENLEN + scbuf);
- z->nam = SH(CENNAM + scbuf);
- z->cext = SH(CENEXT + scbuf);
- z->com = SH(CENCOM + scbuf);
- z->dsk = SH(CENDSK + scbuf);
- z->att = SH(CENATT + scbuf);
- z->atx = LG(CENATX + scbuf);
- z->off = LG(CENOFF + scbuf);
- z->dosflag = (z->vem & 0xff00) == 0;
-
- z->zname = z->name = z->iname = z->extra = z->cextra = z->comment = NULL;
- z->oname = NULL;
- #ifdef UNICODE_SUPPORT
- z->uname = z->zuname = z->ouname = NULL;
- #endif
-
- if (z->nam == 0)
- {
- sprintf(errbuf, "%lu", (ulg)zcount + 1);
- zipwarn("zero-length name for entry #", errbuf);
- if (fix == 1) {
- zipwarn("skipping this entry...", "");
- continue;
- }
- #ifndef DEBUG
- return ZE_FORM;
- #endif
- }
- if ((z->iname = malloc(z->nam+1)) == NULL ||
- (z->cext && (z->cextra = malloc(z->cext)) == NULL) ||
- (z->com && (z->comment = malloc(z->com)) == NULL))
- return ZE_MEM;
- if (fread(z->iname, z->nam, 1, in_file) != 1 ||
- (z->cext && fread(z->cextra, z->cext, 1, in_file) != 1) ||
- (z->com && fread(z->comment, z->com, 1, in_file) != 1)) {
- if (fix == 1) {
- zipwarn("error reading entry: ", strerror(errno));
- zipwarn("skipping this entry...", "");
- continue;
- }
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- }
- z->iname[z->nam] = '\0';
- #ifdef UNICODE_SUPPORT
- if (unicode_mismatch != 3) {
- if (z->flg & UTF8_BIT) {
- char *iname;
-
- if ((z->uname = malloc(strlen(z->iname) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->uname, z->iname);
-
- iname = utf8_to_local_string(z->uname);
- if (iname) {
- free(z->iname);
- z->iname = iname;
- }
- else
- zipwarn("illegal UTF-8 name: ", z->uname);
- } else {
-
- read_Unicode_Path_entry(z);
- }
- }
- #endif
- #ifdef WIN32
-
- {
- unsigned hostver = (z->vem & 0xff);
- Ext_ASCII_TO_Native(z->iname, (z->vem >> 8), hostver,
- ((z->atx & 0xffff0000L) != 0), FALSE);
- }
- #endif
- #ifdef EBCDIC
- if (z->com)
- memtoebc(z->comment, z->comment, z->com);
- #endif
- #ifdef WIN32
-
- {
- unsigned hostver = (z->vem & 0xff);
- Ext_ASCII_TO_Native(z->comment, (z->vem >> 8), hostver,
- ((z->atx & 0xffff0000L) != 0), FALSE);
- }
- #endif
- #ifdef ZIP64_SUPPORT
-
-
-
-
-
-
-
-
-
-
- adjust_zip_central_entry(z);
- #endif
-
- if ((fix ==1 && total_disks == 1) || adjust) z->off += adjust_offset;
-
- if (z->dsk == 0 && (!zipbegset || z->off < zipbeg)) {
- zipbeg = z->off;
- zipbegset = 1;
- }
- zcount++;
-
- z->mark = 0;
- z->trash = 0;
- #if defined(UNICODE_SUPPORT) && !defined(UTIL)
- z->zname = in2ex(z->iname);
- if (z->zname == NULL)
- return ZE_MEM;
- if ((z->name = malloc(strlen(z->zname) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->name, z->zname);
- z->oname = local_to_display_string(z->iname);
- # ifdef WIN32
- z->namew = NULL;
- z->inamew = NULL;
- z->znamew = NULL;
- # endif
- if (unicode_mismatch != 3) {
- if (z->uname) {
-
- char *name;
-
- name = utf8_to_local_string(z->uname);
- if (name == NULL) {
-
-
- if ((name = malloc(strlen(z->iname) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(name, z->iname);
- }
- # ifdef EBCDIC
-
- strtoebc(z->zuname, name);
- # else
- if ((z->zuname = malloc(strlen(name) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->zuname, name);
-
- if (unicode_escape_all) {
- char *ouname;
-
- ouname = utf8_to_escape_string(z->uname);
- if (ouname)
- z->ouname = ouname;
- else {
- if ((z->ouname = malloc(strlen(name) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->ouname, name);
- }
- } else {
- if ((z->ouname = malloc(strlen(name) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->ouname, name);
- }
- # ifdef WIN32
- if (!no_win32_wide) {
- z->inamew = utf8_to_wchar_string(z->uname);
- z->znamew = in2exw(z->inamew);
- if (z->znamew == NULL)
- return ZE_MEM;
- }
- local_to_oem_string(z->ouname, z->ouname);
-
- if ((z->wuname = malloc(strlen(z->ouname) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->wuname, z->ouname);
- oem_to_local_string(z->wuname, z->wuname);
- # endif
- # endif
- } else {
-
- # ifdef WIN32
- if (!no_win32_wide) {
- z->inamew = local_to_wchar_string(z->iname);
- z->znamew = in2exw(z->inamew);
- if (z->znamew == NULL)
- return ZE_MEM;
- }
- # endif
- }
- }
- #else
- # ifdef UTIL
- z->name = z->iname;
- # ifdef EBCDIC
- if ((z->zname = malloc(z->nam+1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strtoebc(z->zname, z->iname);
- # else
- z->zname = z->iname;
- # endif
- # else
- z->zname = in2ex(z->iname);
- if (z->zname == NULL)
- return ZE_MEM;
- z->name = z->zname;
- # endif
- if ((z->oname = malloc(strlen(z->zname) + 1)) == NULL) {
- zipwarn("could not allocate memory: scanzipf_reg", "");
- return ZE_MEM;
- }
- strcpy(z->oname, z->zname);
- #endif
- #ifndef UTIL
- if (verbose && fix == 0)
- zipoddities(z);
- #endif
-
- *x = z;
- z->nxt = NULL;
- x = &z->nxt;
- }
-
- fclose(in_file);
- in_file = NULL;
- free(split_path);
- if (!is_signature(sigbuf, "PK\01\02")) {
-
- break;
- }
- }
- if (zcount != cd_total_entries) {
- sprintf(errbuf, "expected %s entries but found %s",
- zip_fzofft(cd_total_entries, NULL, "u"),
- zip_fzofft(zcount, NULL, "u"));
- zipwarn(errbuf, "");
- return ZE_FORM;
- }
- return ZE_OK;
- }
- int readzipfile()
- {
- FILE *f;
- int retval;
- int readable;
-
- zipbeg = 0;
- zfiles = NULL;
- zcount = 0;
- zcomlen = 0;
- retval = ZE_OK;
- f = NULL;
- zipfile_exists = 0;
-
- #ifdef VMS
- if (zipfile == NULL || !(*zipfile) || !strcmp(zipfile, "-"))
- return ZE_OK;
- {
- int rtype;
- if ((VMSmunch(zipfile, GET_RTYPE, (char *)&rtype) == RMS$_NORMAL) &&
- (rtype == FAT$C_VARIABLE)) {
- fprintf(mesg,
- "\n Error: zipfile is in variable-length record format. Please\n\
- run \"bilf b %s\" to convert the zipfile to fixed-length\n\
- record format.\n\n", zipfile);
- return ZE_FORM;
- }
- }
- readable = ((f = zfopen(zipfile, FOPR)) != NULL);
- #else
- readable = (zipfile != NULL && *zipfile && strcmp(zipfile, "-"));
- if (readable) {
- readable = ((f = zfopen(zipfile, FOPR)) != NULL);
- }
- #endif
-
- if (!readable) {
- if (!zip_to_stdout && fix != 2 && strcmp(in_path, out_path)) {
-
- if (fix == 1)
- zipwarn("No .zip file found\n ",
- "(If all you have are splits (.z01, .z02, ...) and no .zip, try -FF)");
- ZIPERR(ZE_OPEN, zipfile);
- }
- } else {
- zipfile_exists = 1;
- }
- #ifdef MVS
-
- if (readable)
- {
- char c;
- fclose(f);
-
- if ((f = zfopen(zipfile, "ab")) == NULL) {
- ZIPERR(ZE_OPEN, zipfile);
- }
- fclose(f);
-
- if ((f = zfopen(zipfile, FOPR)) == NULL) {
- ZIPERR(ZE_OPEN, zipfile);
- }
- if (fread(&c, 1, 1, f) != 1) {
-
- readable = 0;
- fclose(f);
- }
- else{
- fseek(f, 0, SEEK_SET);
- }
- }
- #endif
-
-
- #ifndef UTIL
- if (fix == 2) {
- scanzipf_fixnew();
- }
- else
- #endif
- if (readable)
- {
-
- fclose(f);
- # ifndef UTIL
- retval = (fix == 2 && !adjust) ? scanzipf_fixnew() : scanzipf_regnew();
- # else
- retval = scanzipf_regnew();
- # endif
- }
- if (fix != 2 && readable)
- {
-
- if (zcount)
- {
- struct zlist far * far *x;
- struct zlist far *z;
- extent zl_size = zcount * sizeof(struct zlist far *);
- if (zl_size / sizeof(struct zlist far *) != zcount ||
- (x = zsort = (struct zlist far **)malloc(zl_size)) == NULL)
- return ZE_MEM;
- for (z = zfiles; z != NULL; z = z->nxt)
- *x++ = z;
- qsort((char *)zsort, zcount, sizeof(struct zlist far *), zqcmp);
- #ifdef UNICODE_SUPPORT
-
- if (zl_size / sizeof(struct zlist far *) != zcount ||
- (x = zusort = (struct zlist far **)malloc(zl_size)) == NULL)
- return ZE_MEM;
- for (z = zfiles; z != NULL; z = z->nxt)
- *x++ = z;
- qsort((char *)zusort, zcount, sizeof(struct zlist far *), zuqcmp);
- #endif
- }
- }
-
- return retval;
- }
- int putlocal(z, rewrite)
- struct zlist far *z;
- int rewrite;
- {
-
- char *block = NULL;
- extent offset = 0;
- extent blocksize = 0;
- #ifdef UNICODE_SUPPORT
- ush nam = z->nam;
- int use_uname = 0;
- #endif
- #ifdef ZIP64_SUPPORT
- int streaming_in = 0;
- int was_zip64 = 0;
-
- streaming_in = (strcmp(z->name, "-") == 0);
- if (!rewrite) {
- zip64_entry = 0;
-
- if (z->siz > ZIP_UWORD32_MAX || z->len > ZIP_UWORD32_MAX ||
- force_zip64 == 1 || (force_zip64 != 0 && streaming_in))
- {
-
- if (force_zip64 == 0) {
- zipwarn("Entry too big:", z->oname);
- ZIPERR(ZE_BIG, "Large entry support disabled with -fz- but needed");
- }
- zip64_entry = 1;
- if (z->ver < ZIP64_MIN_VER)
- z->ver = ZIP64_MIN_VER;
- was_zip64 = 1;
- }
- } else {
-
- was_zip64 = zip64_entry;
- zip64_entry = 0;
- if (z->siz > ZIP_UWORD32_MAX || z->len > ZIP_UWORD32_MAX ||
- force_zip64 == 1 || (force_zip64 != 0 && streaming_in))
- {
-
- zip64_entry = 1;
- }
- if (force_zip64 == 0 && zip64_entry) {
-
- zipwarn("Entry too big:", z->oname);
- ZIPERR(ZE_BIG, "Large entry support disabled with -fz- but entry needs");
- }
-
- if (was_zip64 == 0 && zip64_entry == 1) {
-
- zipwarn("Entry too big:", z->oname);
- if (force_zip64 == 0) {
- ZIPERR(ZE_BIG, "Compressed/stored entry unexpectedly large - do not use -fz-");
- } else {
- ZIPERR(ZE_BIG, "Poor compression resulted in unexpectedly large entry - try -fz");
- }
- }
- if (zip64_entry) {
-
-
- zip64_archive = 1;
- if (z->ver < ZIP64_MIN_VER)
- z->ver = ZIP64_MIN_VER;
- } else {
-
- zip64_entry = 0;
- }
- if (was_zip64 && zip64_entry != 1) {
- z->ver = 20;
- }
- }
- #endif
-
- #ifdef ZIP64_SUPPORT
- if (zip64_entry || was_zip64)
-
- add_local_zip64_extra_field( z );
- #endif
- #ifdef UNICODE_SUPPORT
- # if 0
-
-
- z->flg &= ~UTF8_BIT;
- z->lflg &= ~UTF8_BIT;
- # endif
- if (z->uname) {
-
- if (utf8_force || using_utf8) {
- z->lflg |= UTF8_BIT;
- z->flg |= UTF8_BIT;
- }
- if (z->flg & UTF8_BIT) {
-
- use_uname = 1;
- nam = strlen(z->uname);
- } else {
-
- add_Unicode_Path_local_extra_field(z);
- }
- } else {
-
- z->flg &= ~UTF8_BIT;
- z->lflg &= ~UTF8_BIT;
- }
- #endif
- append_ulong_to_mem(LOCSIG, &block, &offset, &blocksize);
- append_ushort_to_mem(z->ver, &block, &offset, &blocksize);
- append_ushort_to_mem(z->lflg, &block, &offset, &blocksize);
- append_ushort_to_mem(z->how, &block, &offset, &blocksize);
- append_ulong_to_mem(z->tim, &block, &offset, &blocksize);
- append_ulong_to_mem(z->crc, &block, &offset, &blocksize);
- #ifdef ZIP64_SUPPORT
-
- if (zip64_entry) {
- append_ulong_to_mem(0xFFFFFFFF, &block, &offset, &blocksize);
- append_ulong_to_mem(0xFFFFFFFF, &block, &offset, &blocksize);
- } else {
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- }
- #else
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- #endif
- #ifdef UNICODE_SUPPORT
- append_ushort_to_mem(nam, &block, &offset, &blocksize);
- #else
- append_ushort_to_mem(z->nam, &block, &offset, &blocksize);
- #endif
- append_ushort_to_mem(z->ext, &block, &offset, &blocksize);
- #ifdef UNICODE_SUPPORT
- if (use_uname) {
-
- append_string_to_mem(z->uname, nam, &block, &offset, &blocksize);
- } else
- #endif
- #ifdef WIN32_OEM
-
- if ((z->vem & 0xff00) == 0)
- {
- char *oem;
- if ((oem = malloc(strlen(z->iname) + 1)) == NULL)
- ZIPERR(ZE_MEM, "putlocal oem");
- INTERN_TO_OEM(z->iname, oem);
- append_string_to_mem(oem, z->nam, &block, &offset, &blocksize);
- free(oem);
- } else {
- append_string_to_mem(z->iname, z->nam, &block, &offset, &blocksize);
- }
- #else
- append_string_to_mem(z->iname, z->nam, &block, &offset, &blocksize);
- #endif
- if (z->ext) {
- append_string_to_mem(z->extra, z->ext, &block, &offset, &blocksize);
- }
-
- if (rewrite == PUTLOCAL_REWRITE) {
-
-
- if (split_method == 1) {
- if (fwrite(block, 1, offset, current_local_file) != offset) {
- free(block);
- return ZE_TEMP;
- }
-
- if (current_local_disk != current_disk) {
- close_split(current_local_disk, current_local_file, current_local_tempname);
- current_local_file = NULL;
- free(current_local_tempname);
- }
- } else {
-
- if (fwrite(block, 1, offset, y) != offset) {
- free(block);
- return ZE_TEMP;
- }
- }
- } else {
-
-
- if (bfwrite(block, 1, offset, BFWRITE_LOCALHEADER) != offset) {
- free(block);
- return ZE_TEMP;
- }
- }
- free(block);
- return ZE_OK;
- }
- int putextended(z)
- struct zlist far *z;
-
- {
-
- char *block = NULL;
- extent offset = 0;
- extent blocksize = 0;
- append_ulong_to_mem(EXTLOCSIG, &block, &offset, &blocksize);
- append_ulong_to_mem(z->crc, &block, &offset, &blocksize);
- #ifdef ZIP64_SUPPORT
- if (zip64_entry) {
-
- append_int64_to_mem(z->siz, &block, &offset, &blocksize);
- append_int64_to_mem(z->len, &block, &offset, &blocksize);
-
- } else {
-
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- }
- #else
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- #endif
-
- if (bfwrite(block, 1, offset, BFWRITE_HEADER) != offset) {
- free(block);
- return ZE_TEMP;
- }
- free(block);
- return ZE_OK;
- }
- int putcentral(z)
- struct zlist far *z;
- {
-
-
- char *block = NULL;
- extent offset = 0;
- extent blocksize = 0;
- uzoff_t off = 0;
- ush nam = z->nam;
- #ifdef UNICODE_SUPPORT
- int use_uname = 0;
- #endif
- #ifdef ZIP64_SUPPORT
- int iRes;
- #endif
- #ifdef UNICODE_SUPPORT
- if (z->uname) {
- if (utf8_force) {
- z->flg |= UTF8_BIT;
- }
- if (z->flg & UTF8_BIT) {
-
- use_uname = 1;
- nam = strlen(z->uname);
- } else {
- add_Unicode_Path_cen_extra_field(z);
- }
- } else {
-
- z->flg &= ~UTF8_BIT;
- z->lflg &= ~UTF8_BIT;
- }
- #endif
- off = z->off;
- #ifdef ZIP64_SUPPORT
- if (z->siz > ZIP_UWORD32_MAX || z->len > ZIP_UWORD32_MAX ||
- z->off > ZIP_UWORD32_MAX || z->dsk > ZIP_UWORD16_MAX || (force_zip64 == 1))
- {
- iRes = add_central_zip64_extra_field(z);
- if( iRes != ZE_OK )
- return iRes;
- }
- append_ulong_to_mem(CENSIG, &block, &offset, &blocksize);
- append_ushort_to_mem(z->vem, &block, &offset, &blocksize);
- append_ushort_to_mem(z->ver, &block, &offset, &blocksize);
- append_ushort_to_mem(z->flg, &block, &offset, &blocksize);
- append_ushort_to_mem(z->how, &block, &offset, &blocksize);
- append_ulong_to_mem(z->tim, &block, &offset, &blocksize);
- append_ulong_to_mem(z->crc, &block, &offset, &blocksize);
- if (z->siz > ZIP_UWORD32_MAX)
- {
-
- append_ulong_to_mem(ZIP_UWORD32_MAX, &block, &offset, &blocksize);
- }
- else
- {
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- }
-
- if (z->len > ZIP_UWORD32_MAX || (force_zip64 == 1))
- {
-
- append_ulong_to_mem(ZIP_UWORD32_MAX, &block, &offset, &blocksize);
- }
- else
- {
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- }
- append_ushort_to_mem(nam, &block, &offset, &blocksize);
- append_ushort_to_mem(z->cext, &block, &offset, &blocksize);
- append_ushort_to_mem(z->com, &block, &offset, &blocksize);
- if (z->dsk > ZIP_UWORD16_MAX)
- {
-
- append_ushort_to_mem((ush)ZIP_UWORD16_MAX, &block, &offset, &blocksize);
- }
- else
- {
- append_ushort_to_mem((ush)z->dsk, &block, &offset, &blocksize);
- }
- append_ushort_to_mem(z->att, &block, &offset, &blocksize);
- append_ulong_to_mem(z->atx, &block, &offset, &blocksize);
- if (off > ZIP_UWORD32_MAX)
- {
-
- append_ulong_to_mem(ZIP_UWORD32_MAX, &block, &offset, &blocksize);
- }
- else
- {
- append_ulong_to_mem((ulg)off, &block, &offset, &blocksize);
- }
- #else
- append_ulong_to_mem(CENSIG, &block, &offset, &blocksize);
- append_ushort_to_mem(z->vem, &block, &offset, &blocksize);
- append_ushort_to_mem(z->ver, &block, &offset, &blocksize);
- append_ushort_to_mem(z->flg, &block, &offset, &blocksize);
- append_ushort_to_mem(z->how, &block, &offset, &blocksize);
- append_ulong_to_mem(z->tim, &block, &offset, &blocksize);
- append_ulong_to_mem(z->crc, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->siz, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)z->len, &block, &offset, &blocksize);
- append_ushort_to_mem(nam, &block, &offset, &blocksize);
- append_ushort_to_mem(z->cext, &block, &offset, &blocksize);
- append_ushort_to_mem(z->com, &block, &offset, &blocksize);
- append_ushort_to_mem((ush)z->dsk, &block, &offset, &blocksize);
- append_ushort_to_mem(z->att, &block, &offset, &blocksize);
- append_ulong_to_mem(z->atx, &block, &offset, &blocksize);
- append_ulong_to_mem((ulg)off, &block, &offset, &blocksize);
- #endif
- #ifdef EBCDIC
- if (z->com)
- memtoasc(z->comment, z->comment, z->com);
- #endif
- #ifdef UNICODE_SUPPORT
- if (use_uname) {
-
- append_string_to_mem(z->uname, nam, &block, &offset, &blocksize);
- } else
- #endif
- #ifdef WIN32_OEM
-
- if ((z->vem & 0xff00) == 0)
- {
- char *oem;
- if ((oem = malloc(strlen(z->iname) + 1)) == NULL)
- ZIPERR(ZE_MEM, "putcentral oem");
- INTERN_TO_OEM(z->iname, oem);
- append_string_to_mem(oem, z->nam, &block, &offset, &blocksize);
- free(oem);
- } else {
- append_string_to_mem(z->iname, z->nam, &block, &offset, &blocksize);
- }
- #else
- append_string_to_mem(z->iname, z->nam, &block, &offset, &blocksize);
- #endif
- if (z->cext) {
- append_string_to_mem(z->cextra, z->cext, &block, &offset, &blocksize);
- }
- if (z->com) {
- #ifdef WIN32_OEM
-
- if ((z->vem & 0xff00) == 0)
- {
- char *oem;
- if ((oem = malloc(strlen(z->comment) + 1)) == NULL)
- ZIPERR(ZE_MEM, "putcentral oem comment");
- INTERN_TO_OEM(z->comment, oem);
- append_string_to_mem(oem, z->com, &block, &offset, &blocksize);
- free(oem);
- } else {
- append_string_to_mem(z->comment, z->com, &block, &offset, &blocksize);
- }
- #else
- append_string_to_mem(z->comment, z->com, &block, &offset, &blocksize);
- #endif
- }
-
- if (bfwrite(block, 1, offset, BFWRITE_CENTRALHEADER) != offset) {
- free(block);
- return ZE_TEMP;
- }
- free(block);
- return ZE_OK;
- }
- int putend( OFT( uzoff_t) n,
- OFT( uzoff_t) s,
- OFT( uzoff_t) c,
- OFT( extent) m,
- OFT( char *) z
- )
- #ifdef NO_PROTO
- uzoff_t n;
- uzoff_t s;
- uzoff_t c;
- extent m;
- char *z;
- #endif
- {
- #ifdef ZIP64_SUPPORT
- ush vem;
- int iNeedZip64 = 0;
- char *block = NULL;
- extent offset = 0;
- extent blocksize = 0;
-
-
-
-
-
-
-
-
-
-
-
-
-
- zip64_eocd_disk = current_disk;
- zip64_eocd_offset = bytes_this_split;
- if( n > ZIP_UWORD16_MAX || s > ZIP_UWORD32_MAX || c > ZIP_UWORD32_MAX ||
- zip64_archive )
- {
- ++iNeedZip64;
-
-
-
- append_ulong_to_mem((ulg)ZIP64_CENTRAL_DIR_TAIL_SIG, &block, &offset, &blocksize);
-
-
-
- append_int64_to_mem((zoff_t)ZIP64_CENTRAL_DIR_TAIL_SIZE, &block, &offset, &blocksize);
-
- vem = OS_CODE + Z_MAJORVER * 10 + Z_MINORVER;
- append_ushort_to_mem(vem, &block, &offset, &blocksize);
-
-
- append_ushort_to_mem(ZIP64_MIN_VER, &block, &offset, &blocksize);
-
- append_ulong_to_mem(current_disk, &block, &offset, &blocksize);
-
- append_ulong_to_mem(cd_start_disk, &block, &offset, &blocksize);
-
- append_int64_to_mem(cd_entries_this_disk, &block, &offset, &blocksize);
-
- append_int64_to_mem(n, &block, &offset, &blocksize);
-
- append_int64_to_mem(s, &block, &offset, &blocksize);
-
- append_int64_to_mem(cd_start_offset, &block, &offset, &blocksize);
-
-
-
-
- append_ulong_to_mem(ZIP64_CENTRAL_DIR_TAIL_END_SIG, &block, &offset, &blocksize);
-
- append_ulong_to_mem(zip64_eocd_disk, &block, &offset, &blocksize);
-
-
- append_int64_to_mem(zip64_eocd_offset, &block, &offset, &blocksize);
-
-
- append_ulong_to_mem(current_disk + 1, &block, &offset, &blocksize);
- }
-
- append_ulong_to_mem(ENDSIG, &block, &offset, &blocksize);
-
-
-
- if (current_disk < 0xFFFF)
- append_ushort_to_mem((ush)current_disk, &block, &offset, &blocksize);
- else
- append_ushort_to_mem((ush)0xFFFF, &block, &offset, &blocksize);
-
- if (cd_start_disk == (ulg)-1)
- cd_start_disk = 0;
- if (cd_start_disk < 0xFFFF)
- append_ushort_to_mem((ush)cd_start_disk, &block, &offset, &blocksize);
- else
- append_ushort_to_mem((ush)0xFFFF, &block, &offset, &blocksize);
-
- if (cd_entries_this_disk < 0xFFFF)
- append_ushort_to_mem((ush)cd_entries_this_disk, &block, &offset, &blocksize);
- else
- append_ushort_to_mem((ush)0xFFFF, &block, &offset, &blocksize);
-
- if (total_cd_entries < 0xFFFF)
- append_ushort_to_mem((ush)total_cd_entries, &block, &offset, &blocksize);
- else
- append_ushort_to_mem((ush)0xFFFF, &block, &offset, &blocksize);
- if( s > ZIP_UWORD32_MAX )
-
- append_ulong_to_mem(ZIP_UWORD32_MAX, &block, &offset, &blocksize);
- else
-
- append_ulong_to_mem((ulg)s, &block, &offset, &blocksize);
- if(force_zip64 == 1 || cd_start_offset > ZIP_UWORD32_MAX)
-
- append_ulong_to_mem(ZIP_UWORD32_MAX, &block, &offset, &blocksize);
- else
-
- append_ulong_to_mem((ulg)cd_start_offset, &block, &offset, &blocksize);
- #else
- char *block = NULL;
- extent offset = 0;
- extent blocksize = 0;
-
- append_ulong_to_mem(ENDSIG, &block, &offset, &blocksize);
-
- append_ushort_to_mem((ush)current_disk, &block, &offset, &blocksize);
-
- append_ushort_to_mem((ush)cd_start_disk, &block, &offset, &blocksize);
-
- append_ushort_to_mem((ush)cd_entries_this_disk, &block, &offset, &blocksize);
-
- append_ushort_to_mem((ush)n, &block, &offset, &blocksize);
-
- append_ulong_to_mem((ulg)s, &block, &offset, &blocksize);
-
- append_ulong_to_mem((ulg)cd_start_offset, &block, &offset, &blocksize);
- #endif
-
- append_ushort_to_mem((ush)m, &block, &offset, &blocksize);
-
- #ifdef EBCDIC
- memtoasc(z, z, m);
- #endif
- if (m) {
-
- append_string_to_mem(z, m, &block, &offset, &blocksize);
- }
-
- if (bfwrite(block, 1, offset, BFWRITE_HEADER) != offset) {
- free(block);
- return ZE_TEMP;
- }
- free(block);
- #ifdef HANDLE_AMIGA_SFX
- if (amiga_sfx_offset && zipbeg ) {
- s = zftello(y);
- while (s & 3) s++, putc(0, f);
- PUTLG(0xF2030000 , f);
- c = (s - amiga_sfx_offset - 4) / 4;
- if (zfseeko(y, amiga_sfx_offset, SEEK_SET) != 0)
- return ZE_TEMP;
- c = ((c >> 24) & 0xFF) | ((c >> 8) & 0xFF00)
- | ((c & 0xFF00) << 8) | ((c & 0xFF) << 24);
- PUTLG(c, y);
- zfseeko(y, 0, SEEK_END);
- }
- #endif
- return ZE_OK;
- }
- int zipcopy(z)
- struct zlist far *z;
- {
- uzoff_t n;
- ulg e = 0;
- ulg start_disk = 0;
- uzoff_t start_offset = 0;
- char *split_path;
- char buf[LOCHEAD + 1];
- struct zlist far *localz;
- int r;
- Trace((stderr, "zipcopy %s\n", z->zname));
-
- if (fix != 2) {
- start_disk = z->dsk;
- start_offset = z->off;
-
-
- if (start_disk != current_in_disk) {
- if (in_file) {
- fclose(in_file);
- in_file = NULL;
- }
- }
- current_in_disk = start_disk;
-
- split_path = get_in_split_path(in_path, current_in_disk);
- if (in_file == NULL) {
- while ((in_file = zfopen(split_path, FOPR)) == NULL) {
-
- if (!noisy) {
- ZIPERR(ZE_OPEN, split_path);
- }
-
- r = ask_for_split_read_path(start_disk);
- if (r == ZE_ABORT) {
-
- return ZE_ABORT;
- } else if ((fix == 1 || fix == 2) && r == ZE_FORM) {
-
- return ZE_FORM;
- }
- free(split_path);
- split_path = get_in_split_path(in_path, start_disk);
- }
- }
- if (zfseeko(in_file, start_offset, SEEK_SET) != 0) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("reading archive fseek: ", strerror(errno));
- return ZE_READ;
- }
- }
- if (fix != 2 && !at_signature(in_file, "PK\03\04")) {
- fclose(in_file);
- in_file = NULL;
- zipwarn("Did not find entry for ", z->iname);
- return ZE_FORM;
- }
-
- if (fread(buf, LOCHEAD, 1, in_file) != 1) {
- int f = ferror(in_file);
- zipwarn("reading local entry: ", strerror(errno));
- if (fix != 2)
- fclose(in_file);
- return f ? ZE_READ : ZE_EOF;
- }
-
- if ((localz = (struct zlist far *)farmalloc(sizeof(struct zlist))) == NULL) {
- zipwarn("reading entry", "");
- if (fix != 2)
- fclose(in_file);
- return ZE_MEM;
- }
- localz->ver = SH(LOCVER + buf);
- localz->lflg = SH(LOCFLG + buf);
- localz->how = SH(LOCHOW + buf);
- localz->tim = LG(LOCTIM + buf);
- localz->crc = LG(LOCCRC + buf);
- localz->nam = SH(LOCNAM + buf);
- localz->ext = SH(LOCEXT + buf);
- if (fix == 2) {
- localz->siz = LG(LOCSIZ + buf);
- localz->len = LG(LOCLEN + buf);
- }
- if (fix == 2) {
-
- ush os = localz->ver >> 8;
- ush pkver = localz->ver - os;
-
- if (os > 40) {
- sprintf(errbuf, "Illegal host system mapping in local header: %d", os);
- zipwarn(errbuf, "");
- zipwarn("Skipping: ", z->iname);
- return ZE_FORM;
- }
-
-
- if (pkver > 100) {
- sprintf(errbuf, "Illegal PK version mapping in local header: %d", pkver);
- zipwarn(errbuf, "");
- zipwarn("Skipping: ", z->iname);
- return ZE_FORM;
- }
-
-
- if (localz->how > 200) {
- sprintf(errbuf, "Unrecognized compression method in local header: %d", localz->how);
- zipwarn(errbuf, "");
- zipwarn("Skipping: ", z->iname);
- return ZE_FORM;
- }
-
- }
-
- localz->zname = localz->name = localz->iname = localz->extra = NULL;
- localz->oname = NULL;
- #ifdef UNICODE_SUPPORT
- localz->uname = NULL;
- #endif
-
- if ((localz->iname = malloc(localz->nam+1)) == NULL ||
- (localz->ext && (localz->extra = malloc(localz->ext)) == NULL))
- return ZE_MEM;
- if (fread(localz->iname, localz->nam, 1, in_file) != 1 ||
- (localz->ext && fread(localz->extra, localz->ext, 1, in_file) != 1))
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- localz->iname[localz->nam] = '\0';
- if ((localz->name = malloc(localz->nam+1)) == NULL)
- return ZE_MEM;
- strcpy(localz->name, localz->iname);
- #ifdef ZIP64_SUPPORT
- zip64_entry = adjust_zip_local_entry(localz);
- #endif
- localz->vem = 0;
- if (fix != 2) {
-
- localz->vem = z->vem;
- #ifdef UNICODE_SUPPORT
- if (unicode_mismatch != 3) {
- if (z->flg & UTF8_BIT) {
- char *iname;
-
- localz->uname = localz->iname;
- iname = utf8_to_local_string(localz->uname);
- if (iname == NULL) {
-
- if ((localz->iname = malloc(strlen(localz->uname) + 1)) == NULL) {
- return ZE_MEM;
- }
- strcpy(localz->iname, localz->uname);
- } else {
-
- localz->iname = iname;
- }
- } else {
-
- read_Unicode_Path_local_entry(localz);
- }
- }
- #endif
- #ifdef WIN32_OEM
-
- if ((z->vem & 0xff00) == 0)
-
- oem_to_local_string(localz->iname, localz->iname);
- #endif
- }
- if (fix == 2) {
- # ifdef WIN32
- # ifdef UNICODE_SUPPORT
- localz->namew = NULL;
- localz->inamew = NULL;
- localz->znamew = NULL;
- z->namew = NULL;
- z->inamew = NULL;
- z->znamew = NULL;
- # endif
- # endif
-
- z->flg = localz->lflg;
- z->len = localz->len;
- z->siz = localz->siz;
- } else {
-
- if (localz->ver != z->ver) {
- zipwarn("Local Version Needed To Extract does not match CD: ", z->iname);
- }
- if (localz->lflg != z->flg) {
- zipwarn("Local Entry Flag does not match CD: ", z->iname);
- }
- if (!(z->flg & 8)) {
- if (localz->crc != z->crc) {
- zipwarn("Local Entry CRC does not match CD: ", z->iname);
- }
- }
- if (fix != 3 && strcmp(localz->iname, z->iname) != 0) {
- zipwarn("Local Entry name does not match CD: ", z->iname);
- }
-
- localz->len = z->len;
- localz->siz = z->siz;
- }
- #if 0
- if (fix > 1) {
- if (zfseeko(in_file, z->off + n, SEEK_SET))
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- if (fix > 2) {
-
- z->nam = strlen(z->iname);
- n = (uzoff_t)((LOCHEAD) + (ulg)z->nam + (ulg)z->ext);
- }
-
- if (putlocal(z, PUTLOCAL_WRITE) != ZE_OK)
- return ZE_TEMP;
- z->off = tempzn;
- tempzn += n;
- n = z->siz;
- } else {
- if (zfseeko(in_file, z->off, SEEK_SET))
- return ferror(in_file) ? ZE_READ : ZE_EOF;
- z->off = tempzn;
- n += z->siz;
- }
- #endif
-
- if (fix == 3) {
-
- localz->nam = z->nam = strlen(z->iname);
-
- free(localz->iname);
- if ((localz->iname = malloc(strlen(z->iname) + 1)) == NULL) {
- zipwarn("out of memory in zipcopy", "");
- return ZE_MEM;
- }
- strcpy(localz->iname, z->iname);
- }
-
- z->dsk = current_disk;
- z->off = bytes_this_split;
-
-
- if (fix != 2 && !(z->flg & 1)) {
-
- localz->flg = z->flg &= ~8;
- z->lflg = localz->lflg &= ~8;
- }
- e = 0;
- if (z->lflg & 8) {
- #ifdef ZIP64_SUPPORT
- if (zip64_entry)
- e = 24;
- else
- #endif
- e = 16;
- }
-
- n = 4 + (uzoff_t)((LOCHEAD) + (ulg)(localz->nam) + (ulg)(localz->ext));
- n += e + z->siz;
- tempzn += n;
-
- if (fix == 2) {
- if ((z->oname = malloc(strlen(localz->iname) + 1)) == NULL) {
- return ZE_MEM;
- }
- strcpy(z->oname, localz->iname);
- #ifndef UTIL
- # ifdef WIN32
-
- _INTERN_OEM(z->oname);
- # endif
- #endif
- sprintf(errbuf, " copying: %s ", z->oname);
- zipmessage_nl(errbuf, 0);
- }
- if (fix == 2)
- z->crc = localz->crc;
- else
- localz->crc = z->crc;
- if (putlocal(localz, PUTLOCAL_WRITE) != ZE_OK)
- return ZE_TEMP;
-
-
- if (fix == 2 && localz->lflg & 8)
-
- r = bfcopy((uzoff_t) -2);
- else
- r = bfcopy(localz->siz);
- if (r == ZE_ABORT) {
- if (localz->ext) free(localz->extra);
- if (localz->nam) free(localz->iname);
- if (localz->nam) free(localz->name);
- #ifdef UNICODE_SUPPORT
- if (localz->uname) free(localz->uname);
- #endif
- free(localz);
- ZIPERR(ZE_ABORT, "Could not find split");
- }
- if (r == ZE_EOF || skip_this_disk) {
-
- zipwarn("aborting: ", z->oname);
- if (r == ZE_OK)
- r = ZE_FORM;
- if (fix == 2) {
- #ifdef DEBUG
- zoff_t here = zftello(y);
- #endif
-
- skip_this_disk = 0;
-
- if (zfseeko(y, current_local_offset, SEEK_SET) != 0) {
- ZIPERR(ZE_WRITE, "seek failed on output file");
- }
- bytes_this_split = current_local_offset;
- tempzn = current_local_offset;
- }
-
- if (localz->ext) free(localz->extra);
- if (localz->nam) free(localz->iname);
- if (localz->nam) free(localz->name);
- #ifdef UNICODE_SUPPORT
- if (localz->uname) free(localz->uname);
- #endif
- free(localz);
- return r;
- }
- if (fix == 2 && z->flg & 8) {
-
-
- if (des_good) {
-
- localz->crc = des_crc;
- localz->siz = des_csize;
- localz->len = des_usize;
- } else {
-
- zipwarn("no end of stream entry found: ", z->oname);
- zipwarn("rewinding and scanning for later entries", "");
-
- if (zfseeko(y, current_local_offset, SEEK_SET) != 0){
- }
-
- if (localz->ext) free(localz->extra);
- if (localz->nam) free(localz->iname);
- if (localz->nam) free(localz->name);
- #ifdef UNICODE_SUPPORT
- if (localz->uname) free(localz->uname);
- #endif
- free(localz);
- return ZE_FORM;
- }
- }
- if (z->flg & 8) {
- putextended(localz);
- }
-
- if (split_method == 1 && current_local_disk != current_disk) {
- close_split(current_local_disk, current_local_file, current_local_tempname);
- current_local_file = NULL;
- free(current_local_tempname);
- }
-
-
- if (fix == 2) {
- z->ver = localz->ver;
- z->how = localz->how;
- z->tim = localz->tim;
- z->crc = localz->crc;
- z->lflg = localz->lflg;
- z->flg = localz->lflg;
- z->len = localz->len;
- z->siz = localz->siz;
- z->nam = localz->nam;
- z->ext = localz->ext;
- z->extra = localz->extra;
-
- z->cext = localz->ext;
- z->cextra = NULL;
- if (localz->ext) {
- if ((z->cextra = malloc(localz->ext + 1)) == NULL) {
- return ZE_MEM;
- }
- strcpy(z->cextra, localz->extra);
- }
- z->com = 0;
- z->att = 0;
- z->atx = 0;
- z->name = localz->name;
- z->iname = localz->iname;
- #ifdef UNICODE_SUPPORT
- z->uname = localz->uname;
- #endif
- if ((z->zname = malloc(localz->nam + 1)) == NULL) {
- return ZE_MEM;
- }
- strcpy(z->zname, z->iname);
- } else {
- if (localz->ext) free(localz->extra);
- if (localz->nam) free(localz->iname);
- if (localz->nam) free(localz->name);
- #ifdef UNICODE_SUPPORT
- if (localz->uname) free(localz->uname);
- #endif
- free(localz);
- }
- if (fix == 2) {
- sprintf(errbuf, " (%s bytes)", zip_fzofft(z->siz, NULL, "u"));
- zipmessage_nl(errbuf, 1);
- if (r == ZE_READ) {
- zipwarn("entry truncated: ", z->oname);
- sprintf(errbuf, "expected compressed/stored size %s, actual %s",
- zip_fzofft(localz->siz, NULL, "u"), zip_fzofft(bytes_this_entry, NULL, "u"));
- zipwarn(errbuf, "");
- }
- }
- return r;
- }
- #ifndef UTIL
- #ifdef USE_EF_UT_TIME
- local int ef_scan_ut_time(ef_buf, ef_len, ef_is_cent, z_utim)
- char *ef_buf;
- extent ef_len;
- int ef_is_cent;
- iztimes *z_utim;
- {
- int flags = 0;
- unsigned eb_id;
- extent eb_len;
- int have_new_type_eb = FALSE;
- if (ef_len == 0 || ef_buf == NULL)
- return 0;
- Trace((stderr,"\nef_scan_ut_time: scanning extra field of length %u\n",
- (unsigned)ef_len));
- while (ef_len >= EB_HEADSIZE) {
- eb_id = SH(EB_ID + ef_buf);
- eb_len = SH(EB_LEN + ef_buf);
- if (eb_len > (ef_len - EB_HEADSIZE)) {
-
- Trace((stderr,"ef_scan_ut_time: block length %u > rest ef_size %u\n",
- (unsigned)eb_len, (unsigned)(ef_len - EB_HEADSIZE)));
- break;
- }
- switch (eb_id) {
- case EF_TIME:
- flags &= ~0x00ff;
- have_new_type_eb = TRUE;
- if ( eb_len >= EB_UT_MINLEN && z_utim != NULL) {
- unsigned eb_idx = EB_UT_TIME1;
- Trace((stderr,"ef_scan_ut_time: Found TIME extra field\n"));
- flags |= (ef_buf[EB_HEADSIZE+EB_UT_FLAGS] & 0x00ff);
- if ((flags & EB_UT_FL_MTIME)) {
- if ((eb_idx+4) <= eb_len) {
- z_utim->mtime = LG((EB_HEADSIZE+eb_idx) + ef_buf);
- eb_idx += 4;
- Trace((stderr," Unix EF modtime = %ld\n", z_utim->mtime));
- } else {
- flags &= ~EB_UT_FL_MTIME;
- Trace((stderr," Unix EF truncated, no modtime\n"));
- }
- }
- if (ef_is_cent) {
- break;
- }
- if (flags & EB_UT_FL_ATIME) {
- if ((eb_idx+4) <= eb_len) {
- z_utim->atime = LG((EB_HEADSIZE+eb_idx) + ef_buf);
- eb_idx += 4;
- Trace((stderr," Unix EF acctime = %ld\n", z_utim->atime));
- } else {
- flags &= ~EB_UT_FL_ATIME;
- }
- }
- if (flags & EB_UT_FL_CTIME) {
- if ((eb_idx+4) <= eb_len) {
- z_utim->ctime = LG((EB_HEADSIZE+eb_idx) + ef_buf);
-
- Trace((stderr," Unix EF cretime = %ld\n", z_utim->ctime));
- } else {
- flags &= ~EB_UT_FL_CTIME;
- }
- }
- }
- break;
- case EF_IZUNIX2:
- if (!have_new_type_eb) {
- flags &= ~0x00ff;
- have_new_type_eb = TRUE;
- }
- break;
- case EF_IZUNIX:
- if (eb_len >= EB_UX_MINLEN) {
- Trace((stderr,"ef_scan_ut_time: Found IZUNIX extra field\n"));
- if (have_new_type_eb) {
- break;
- }
- z_utim->atime = LG((EB_HEADSIZE+EB_UX_ATIME) + ef_buf);
- z_utim->mtime = LG((EB_HEADSIZE+EB_UX_MTIME) + ef_buf);
- Trace((stderr," Unix EF access time = %ld\n",z_utim->atime));
- Trace((stderr," Unix EF modif. time = %ld\n",z_utim->mtime));
- flags |= (EB_UT_FL_MTIME | EB_UT_FL_ATIME);
- }
- break;
- case EF_THEOS:
- break;
- default:
- break;
- }
-
- ef_buf += (eb_len + EB_HEADSIZE);
- ef_len -= (eb_len + EB_HEADSIZE);
- }
- return flags;
- }
- int get_ef_ut_ztime(z, z_utim)
- struct zlist far *z;
- iztimes *z_utim;
- {
- int r;
- #ifdef IZ_CHECK_TZ
- if (!zp_tz_is_valid) return 0;
- #endif
-
- r = ef_scan_ut_time(z->extra, z->ext, FALSE, z_utim);
-
- if (!r && z->cext > 0 && z->cextra != z->extra)
- r = ef_scan_ut_time(z->cextra, z->cext, TRUE, z_utim);
- return r;
- }
- #endif
- local void cutpath(p, delim)
- char *p;
- int delim;
- {
- char *r;
- #ifdef VMS
- if ((r = MBSRCHR(p, ']')) != NULL)
- {
- *r = 0;
- if ((r = MBSRCHR(p, '.')) != NULL)
- {
- *r = ']';
- strcat(r, ".DIR;1");
- } else {
- *p = 0;
- }
- } else {
- if ((r = MBSRCHR(p, delim)) != NULL)
- *r = 0;
- else
- *p = 0;
- }
- #else
- if ((r = MBSRCHR(p, delim)) != NULL)
- *r = 0;
- else
- *p = 0;
- #endif
- }
- int trash()
- {
- extent i;
- extent n;
- struct zlist far **s;
- struct zlist far *z;
-
- n = 0;
- for (z = zfiles; z != NULL; z = z->nxt)
- if (z->mark == 1 || z->trash)
- {
- z->mark = 1;
- if (z->iname[z->nam - 1] != (char)0x2f) {
- if (verbose)
- fprintf(mesg, "zip diagnostic: deleting file %s\n", z->name);
- if (destroy(z->name)) {
- zipwarn("error deleting ", z->name);
- }
-
- if (!dirnames) {
- cutpath(z->name, '/');
-
-
-
-
- cutpath(z->iname, 0x2f);
- z->nam = strlen(z->iname);
- if (z->nam > 0) {
- z->iname[z->nam - 1] = (char)0x2f;
- z->iname[z->nam++] = '\0';
- }
- if (z->nam > 0) n++;
- }
- } else {
- n++;
- }
- }
-
- if (n)
- {
- if ((s = (struct zlist far **)malloc(n*sizeof(struct zlist far *))) ==
- NULL)
- return ZE_MEM;
- n = 0;
- for (z = zfiles; z != NULL; z = z->nxt) {
- if (z->mark && z->nam > 0 && z->iname[z->nam - 1] == (char)0x2f
- && (n == 0 || strcmp(z->name, s[n-1]->name) != 0)) {
- s[n++] = z;
- }
- }
-
- qsort((char *)s, n, sizeof(struct zlist far *), rqcmp);
- for (i = 0; i < n; i++) {
- char *p = s[i]->name;
- if (*p == '\0') continue;
- if (p[strlen(p) - 1] == '/') {
- p[strlen(p) - 1] = '\0';
- }
- if (i == 0 || strcmp(s[i]->name, s[i-1]->name) != 0) {
- if (verbose) {
- fprintf(mesg, "deleting directory %s (if empty) \n",
- s[i]->name);
- }
- deletedir(s[i]->name);
- }
- }
- free((zvoid *)s);
- }
- return ZE_OK;
- }
- #endif
|