aosvs.c 54 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586
  1. /*
  2. Copyright (c) 1990-2009 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2009-Jan-02 or later
  4. (the contents of which are also included in unzip.h) for terms of use.
  5. If, for some reason, all these files are missing, the Info-ZIP license
  6. also may be found at: ftp://ftp.info-zip.org/pub/infozip/license.html
  7. */
  8. /*---------------------------------------------------------------------------
  9. aosvs.c
  10. AOS/VS-specific routines for use with Info-ZIP's UnZip 5.2 and later.
  11. [GRR: copied from unix.c -> undoubtedly has unnecessary stuff: delete at will]
  12. Contains: readdir()
  13. do_wild()
  14. open_outfile()
  15. mapattr()
  16. mapname()
  17. checkdir()
  18. close_outfile()
  19. version() <-- GRR: needs work! (Unix, not AOS/VS)
  20. zvs_create()
  21. zvs_credir()
  22. ux_to_vs_name()
  23. dgdate()
  24. ---------------------------------------------------------------------------*/
  25. #define UNZIP_INTERNAL
  26. #include "unzip.h"
  27. #include "aosvs/aosvs.h"
  28. #include <packets/create.h>
  29. #include <sys_calls.h>
  30. #include <paru.h>
  31. #define symlink(resname,linkname) \
  32. zvs_create(linkname,-1L,-1L,-1L,ux_to_vs_name(vs_resname,resname),$FLNK,-1,-1)
  33. * file type */
  34. #ifdef DIRENT
  35. # include <dirent.h>
  36. #else
  37. # ifdef SYSV
  38. # ifdef SYSNDIR
  39. # include <sys/ndir.h>
  40. # else
  41. # include <ndir.h>
  42. # endif
  43. # else /* !SYSV */
  44. # ifndef NO_SYSDIR
  45. # include <sys/dir.h>
  46. # endif
  47. # endif /* ?SYSV */
  48. # ifndef dirent
  49. # define dirent direct
  50. # endif
  51. #endif /* ?DIRENT */
  52. static int created_dir; /* used in mapname(), checkdir() */
  53. static int renamed_fullpath; /* ditto */
  54. static ZEXTRAFLD zzextrafld; /* buffer for extra field containing
  55. * ?FSTAT packet & ACL buffer */
  56. static char vs_resname[2*$MXPL];
  57. static char vs_path[2*$MXPL]; /* buf for AOS/VS pathname */
  58. static char Vs_path[512]; /* should be big enough [GRR: ?] */
  59. static P_CTIM zztimeblock; /* time block for file creation */
  60. static ZVSCREATE_STRU zzcreatepacket; /* packet for sys_create(), any
  61. /***************************/
  62. /* Strings used in aosvs.c */
  63. /***************************/
  64. static ZCONST char Far CannotDeleteOldFile[] =
  65. "error: cannot delete old %s\n";
  66. static ZCONST char Far CannotCreateFile[] = "error: cannot create %s\n";
  67. #ifndef SFX
  68. #ifdef NO_DIR /* for AT&T 3B1 */
  69. #define opendir(path) fopen(path,"r")
  70. #define closedir(dir) fclose(dir)
  71. typedef FILE DIR;
  72. /*
  73. * Apparently originally by Rich Salz.
  74. * Cleaned up and modified by James W. Birdsall.
  75. */
  76. struct dirent *readdir(dirp)
  77. DIR *dirp;
  78. {
  79. static struct dirent entry;
  80. if (dirp == NULL)
  81. return NULL;
  82. for (;;)
  83. if (fread(&entry, sizeof (struct dirent), 1, dirp) == 0)
  84. return (struct dirent *)NULL;
  85. else if (entry.d_ino)
  86. return &entry;
  87. } /* end function readdir() */
  88. #endif /* NO_DIR */
  89. /**********************/
  90. /* Function do_wild() */ /* for porting: dir separator; match(ignore_case) */
  91. /**********************/
  92. char *do_wild(__G__ wildspec)
  93. __GDEF
  94. ZCONST char *wildspec; /* only used first time on a given dir */
  95. {
  96. static DIR *wild_dir = (DIR *)NULL;
  97. static ZCONST char *wildname;
  98. static char *dirname, matchname[FILNAMSIZ];
  99. static int notfirstcall=FALSE, have_dirname, dirnamelen;
  100. struct dirent *file;
  101. /* Even when we're just returning wildspec, we *always* do so in
  102. * matchname[]--calling routine is allowed to append four characters
  103. * to the returned string, and wildspec may be a pointer to argv[].
  104. */
  105. if (!notfirstcall) { /* first call: must initialize everything */
  106. notfirstcall = TRUE;
  107. if (!iswild(wildspec)) {
  108. strncpy(matchname, wildspec, FILNAMSIZ);
  109. matchname[FILNAMSIZ-1] = '\0';
  110. have_dirname = FALSE;
  111. dir = NULL;
  112. return matchname;
  113. }
  114. /* break the wildspec into a directory part and a wildcard filename */
  115. if ((wildname = strrchr(wildspec, '/')) == (ZCONST char *)NULL) {
  116. dirname = ".";
  117. dirnamelen = 1;
  118. have_dirname = FALSE;
  119. wildname = wildspec;
  120. } else {
  121. ++wildname; /* point at character after '/' */
  122. dirnamelen = wildname - wildspec;
  123. if ((dirname = (char *)malloc(dirnamelen+1)) == (char *)NULL) {
  124. Info(slide, 0x201, ((char *)slide,
  125. "warning: cannot allocate wildcard buffers\n"));
  126. strncpy(matchname, wildspec, FILNAMSIZ);
  127. matchname[FILNAMSIZ-1] = '\0';
  128. return matchname; /* but maybe filespec was not a wildcard */
  129. }
  130. strncpy(dirname, wildspec, dirnamelen);
  131. dirname[dirnamelen] = '\0'; /* terminate for strcpy below */
  132. have_dirname = TRUE;
  133. }
  134. if ((wild_dir = opendir(dirname)) != (DIR *)NULL) {
  135. while ((file = readdir(wild_dir)) != (struct dirent *)NULL) {
  136. Trace((stderr, "do_wild: readdir returns %s\n",
  137. FnFilter1(file->d_name)));
  138. if (file->d_name[0] == '.' && wildname[0] != '.')
  139. continue; /* Unix: '*' and '?' do not match leading dot */
  140. if (match(file->d_name, wildname, 0 WISEP) && /* 0=case sens.*/
  141. /* skip "." and ".." directory entries */
  142. strcmp(file->d_name, ".") && strcmp(file->d_name, "..")) {
  143. Trace((stderr, "do_wild: match() succeeds\n"));
  144. if (have_dirname) {
  145. strcpy(matchname, dirname);
  146. strcpy(matchname+dirnamelen, file->d_name);
  147. } else
  148. strcpy(matchname, file->d_name);
  149. return matchname;
  150. }
  151. }
  152. /* if we get to here directory is exhausted, so close it */
  153. closedir(wild_dir);
  154. wild_dir = (DIR *)NULL;
  155. }
  156. /* return the raw wildspec in case that works (e.g., directory not
  157. * searchable, but filespec was not wild and file is readable) */
  158. strncpy(matchname, wildspec, FILNAMSIZ);
  159. matchname[FILNAMSIZ-1] = '\0';
  160. return matchname;
  161. }
  162. /* last time through, might have failed opendir but returned raw wildspec */
  163. if (wild_dir == (DIR *)NULL) {
  164. notfirstcall = FALSE; /* nothing left to try--reset for new wildspec */
  165. if (have_dirname)
  166. free(dirname);
  167. return (char *)NULL;
  168. }
  169. /* If we've gotten this far, we've read and matched at least one entry
  170. * successfully (in a previous call), so dirname has been copied into
  171. * matchname already.
  172. */
  173. while ((file = readdir(wild_dir)) != (struct dirent *)NULL) {
  174. Trace((stderr, "do_wild: readdir returns %s\n",
  175. FnFilter1(file->d_name)));
  176. if (file->d_name[0] == '.' && wildname[0] != '.')
  177. continue; /* Unix: '*' and '?' do not match leading dot */
  178. if (match(file->d_name, wildname, 0 WISEP)) { /* 0 == case sens. */
  179. Trace((stderr, "do_wild: match() succeeds\n"));
  180. if (have_dirname) {
  181. /* strcpy(matchname, dirname); */
  182. strcpy(matchname+dirnamelen, file->d_name);
  183. } else
  184. strcpy(matchname, file->d_name);
  185. return matchname;
  186. }
  187. }
  188. closedir(wild_dir); /* have read at least one entry; nothing left */
  189. wild_dir = (DIR *)NULL;
  190. notfirstcall = FALSE; /* reset for new wildspec */
  191. if (have_dirname)
  192. free(dirname);
  193. return (char *)NULL;
  194. } /* end function do_wild() */
  195. #endif /* !SFX */
  196. /***************************/
  197. /* Function open_outfile() */
  198. /***************************/
  199. int open_outfile(__G) /* return 1 if fail */
  200. __GDEF
  201. {
  202. int errc = 1; /* init to show no success with AOS/VS info */
  203. long dmm, ddd, dyy, dhh, dmin, dss;
  204. #ifdef DLL
  205. if (G.redirect_data)
  206. return redirect_outfile(__G)==FALSE;
  207. #endif
  208. if (stat(G.filename, &G.statbuf) == 0 && unlink(G.filename) < 0) {
  209. Info(slide, 0x401, ((char *)slide, LoadFarString(CannotDeleteOldFile),
  210. FnFilter1(G.filename)));
  211. return 1;
  212. }
  213. /*---------------------------------------------------------------------------
  214. If the file didn't already exist, we created it earlier. But we just
  215. deleted it, which we still had to do in case we are overwriting an exis-
  216. ting file. So we must create it now, again, to set the creation time
  217. properly. (The creation time is the best functional approximation of
  218. the Unix mtime. Really!)
  219. If we stored this with an AOS/VS Zip that set the extra field to contain
  220. the ?FSTAT packet and the ACL, we should use info from the ?FSTAT call
  221. now. Otherwise (or if that fails), we should create anyway as best we
  222. can from the normal Zip info.
  223. In theory, we should look through an entire series of extra fields that
  224. might exist for the same file, but we're not going to bother. If we set
  225. up other types of extra fields, or if other environments we run into may
  226. add their own stuff to existing entries in Zip files, we'll have to.
  227. Note that all the packet types for sys_fstat() are the same size & mostly
  228. have the same structure, with some fields being unused, etc. Ditto for
  229. sys_create(). Thus, we assume a normal one here, not a dir/cpd or device
  230. or IPC file, & make little adjustments as necessary. We will set ACLs
  231. later (to reduce the chance of lacking access to what we create now); note
  232. that for links the resolution name should be stored in the ACL field (once
  233. we get Zip recognizing links OK).
  234. ---------------------------------------------------------------------------*/
  235. if (G.extra_field != NULL) {
  236. memcpy((char *) &zzextrafld, G.extra_field, sizeof(zzextrafld));
  237. if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  238. sizeof(zzextrafld.extra_header_id)) &&
  239. !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel),
  240. sizeof(zzextrafld.extra_sentinel))
  241. {
  242. zzcreatepacket.norm_create_packet.cftyp_format =
  243. zzextrafld.fstat_packet.norm_fstat_packet.styp_format;
  244. zzcreatepacket.norm_create_packet.cftyp_entry =
  245. zzextrafld.fstat_packet.norm_fstat_packet.styp_type;
  246. /* for DIRS/CPDs, the next one will give the hash frame size; for
  247. * IPCs it will give the port number */
  248. zzcreatepacket.norm_create_packet.ccps =
  249. zzextrafld.fstat_packet.norm_fstat_packet.scps;
  250. zzcreatepacket.norm_create_packet.ctim = &zztimeblock;
  251. zztimeblock.tcth = zzextrafld.fstat_packet.norm_fstat_packet.stch;
  252. /* access & modification times default to current */
  253. zztimeblock.tath.long_time = zztimeblock.tmth.long_time = -1;
  254. /* give it current process's ACL unless link; then give it
  255. * resolution name */
  256. zzcreatepacket.norm_create_packet.cacp = (char *)(-1);
  257. if (zzcreatepacket.norm_create_packet.cftyp_entry == $FLNK)
  258. zzcreatepacket.norm_create_packet.cacp = zzextrafld.aclbuf;
  259. zzcreatepacket.dir_create_packet.cmsh =
  260. zzextrafld.fstat_packet.dir_fstat_packet.scsh;
  261. if (zzcreatepacket.norm_create_packet.cftyp_entry != $FCPD) {
  262. /* element size for normal files */
  263. zzcreatepacket.norm_create_packet.cdel =
  264. zzextrafld.fstat_packet.norm_fstat_packet.sdeh;
  265. }
  266. zzcreatepacket.norm_create_packet.cmil =
  267. zzextrafld.fstat_packet.norm_fstat_packet.smil;
  268. if ((errc = sys_create(ux_to_vs_name(vs_path, G.filename),
  269. &zzcreatepacket)) != 0)
  270. Info(slide, 0x201, ((char *)slide,
  271. "error creating %s with AOS/VS info -\n\
  272. will try again with ordinary Zip info\n",
  273. FnFilter1(G.filename)));
  274. }
  275. }
  276. /* do it the hard way if no AOS/VS info was stored or if we had problems */
  277. if (errc) {
  278. /* skip restoring time stamps on user's request */
  279. if (uO.D_flag <= 1) {
  280. dyy = (G.lrec.last_mod_dos_datetime >> 25) + 1980;
  281. dmm = (G.lrec.last_mod_dos_datetime >> 21) & 0x0f;
  282. ddd = (G.lrec.last_mod_dos_datetime >> 16) & 0x1f;
  283. dhh = (G.lrec.last_mod_dos_datetime >> 11) & 0x1f;
  284. dmin = (G.lrec.last_mod_dos_datetime >> 5) & 0x3f;
  285. dss = (G.lrec.last_mod_dos_datetime << 1) & 0x3e;
  286. }
  287. if (zvs_create(G.filename,
  288. (uO.D_flag <= 1
  289. ? (((ulg)dgdate(dmm, ddd, dyy)) << 16) |
  290. (dhh*1800L + dmin*30L + dss/2L)
  291. : -1L),
  292. -1L, -1L, (char *) -1, -1, -1, -1))
  293. {
  294. Info(slide, 0x201, ((char *)slide, "error: %s: cannot create\n",
  295. FnFilter1(G.filename)));
  296. return 1;
  297. }
  298. }
  299. Trace((stderr, "open_outfile: doing fopen(%s) for writing\n",
  300. FnFilter1(G.filename)));
  301. if ((G.outfile = fopen(G.filename, FOPW)) == (FILE *)NULL) {
  302. Info(slide, 0x401, ((char *)slide, LoadFarString(CannotCreateFile),
  303. FnFilter1(G.filename)));
  304. return 1;
  305. }
  306. Trace((stderr, "open_outfile: fopen(%s) for writing succeeded\n",
  307. FnFilter1(G.filename)));
  308. #ifdef USE_FWRITE
  309. #ifdef _IOFBF /* make output fully buffered (works just about like write()) */
  310. setvbuf(G.outfile, (char *)slide, _IOFBF, WSIZE);
  311. #else
  312. setbuf(G.outfile, (char *)slide);
  313. #endif
  314. #endif /* USE_FWRITE */
  315. return 0;
  316. } /* end function open_outfile() */
  317. /**********************/
  318. /* Function mapattr() */
  319. /**********************/
  320. int mapattr(__G)
  321. __GDEF
  322. {
  323. ulg tmp = G.crec.external_file_attributes;
  324. G.pInfo->file_attr = 0;
  325. /* initialized to 0 for check in "default" branch below... */
  326. switch (G.pInfo->hostnum) {
  327. case AMIGA_:
  328. tmp = (unsigned)(tmp>>17 & 7); /* Amiga RWE bits */
  329. G.pInfo->file_attr = (unsigned)(tmp<<6 | tmp<<3 | tmp);
  330. break;
  331. case THEOS_:
  332. tmp &= 0xF1FFFFFFL;
  333. if ((tmp & 0xF0000000L) != 0x40000000L)
  334. tmp &= 0x01FFFFFFL; /* not a dir, mask all ftype bits */
  335. else
  336. tmp &= 0x41FFFFFFL; /* leave directory bit as set */
  337. /* fall through! */
  338. case UNIX_:
  339. case VMS_:
  340. case ACORN_:
  341. case ATARI_:
  342. case ATHEOS_:
  343. case BEOS_:
  344. case QDOS_:
  345. case TANDEM_:
  346. G.pInfo->file_attr = (unsigned)(tmp >> 16);
  347. if (G.pInfo->file_attr != 0 || !G.extra_field) {
  348. return 0;
  349. } else {
  350. /* Some (non-Info-ZIP) implementations of Zip for Unix and
  351. * VMS (and probably others ??) leave 0 in the upper 16-bit
  352. * part of the external_file_attributes field. Instead, they
  353. * store file permission attributes in some extra field.
  354. * As a work-around, we search for the presence of one of
  355. * these extra fields and fall back to the MSDOS compatible
  356. * part of external_file_attributes if one of the known
  357. * e.f. types has been detected.
  358. * Later, we might implement extraction of the permission
  359. * bits from the VMS extra field. But for now, the work-around
  360. * should be sufficient to provide "readable" extracted files.
  361. * (For ASI Unix e.f., an experimental remap from the e.f.
  362. * mode value IS already provided!)
  363. */
  364. ush ebID;
  365. unsigned ebLen;
  366. uch *ef = G.extra_field;
  367. unsigned ef_len = G.crec.extra_field_length;
  368. int r = FALSE;
  369. while (!r && ef_len >= EB_HEADSIZE) {
  370. ebID = makeword(ef);
  371. ebLen = (unsigned)makeword(ef+EB_LEN);
  372. if (ebLen > (ef_len - EB_HEADSIZE))
  373. /* discoverd some e.f. inconsistency! */
  374. break;
  375. switch (ebID) {
  376. case EF_ASIUNIX:
  377. if (ebLen >= (EB_ASI_MODE+2)) {
  378. G.pInfo->file_attr =
  379. (unsigned)makeword(ef+(EB_HEADSIZE+EB_ASI_MODE));
  380. /* force stop of loop: */
  381. ef_len = (ebLen + EB_HEADSIZE);
  382. break;
  383. }
  384. /* else: fall through! */
  385. case EF_PKVMS:
  386. /* "found nondecypherable e.f. with perm. attr" */
  387. r = TRUE;
  388. default:
  389. break;
  390. }
  391. ef_len -= (ebLen + EB_HEADSIZE);
  392. ef += (ebLen + EB_HEADSIZE);
  393. }
  394. if (!r)
  395. return 0;
  396. }
  397. /* fall through! */
  398. /* all remaining cases: expand MSDOS read-only bit into write perms */
  399. case FS_FAT_:
  400. /* PKWARE's PKZip for Unix marks entries as FS_FAT_, but stores the
  401. * Unix attributes in the upper 16 bits of the external attributes
  402. * field, just like Info-ZIP's Zip for Unix. We try to use that
  403. * value, after a check for consistency with the MSDOS attribute
  404. * bits (see below).
  405. */
  406. G.pInfo->file_attr = (unsigned)(tmp >> 16);
  407. /* fall through! */
  408. case FS_HPFS_:
  409. case FS_NTFS_:
  410. case MAC_:
  411. case TOPS20_:
  412. default:
  413. /* Ensure that DOS subdir bit is set when the entry's name ends
  414. * in a '/'. Some third-party Zip programs fail to set the subdir
  415. * bit for directory entries.
  416. */
  417. if ((tmp & 0x10) == 0) {
  418. extent fnlen = strlen(G.filename);
  419. if (fnlen > 0 && G.filename[fnlen-1] == '/')
  420. tmp |= 0x10;
  421. }
  422. /* read-only bit --> write perms; subdir bit --> dir exec bit */
  423. tmp = !(tmp & 1) << 1 | (tmp & 0x10) >> 4;
  424. if ((G.pInfo->file_attr & 0700) == (unsigned)(0400 | tmp<<6))
  425. /* keep previous G.pInfo->file_attr setting, when its "owner"
  426. * part appears to be consistent with DOS attribute flags!
  427. */
  428. return 0;
  429. G.pInfo->file_attr = (unsigned)(0444 | tmp<<6 | tmp<<3 | tmp);
  430. break;
  431. } /* end switch (host-OS-created-by) */
  432. /* for originating systems with no concept of "group," "other," "system": */
  433. umask( (int)(tmp=umask(0)) ); /* apply mask to expanded r/w(/x) perms */
  434. G.pInfo->file_attr &= ~tmp;
  435. return 0;
  436. } /* end function mapattr() */
  437. /************************/
  438. /* Function mapname() */
  439. /************************/
  440. int mapname(__G__ renamed)
  441. __GDEF
  442. int renamed;
  443. /*
  444. * returns:
  445. * MPN_OK - no problem detected
  446. * MPN_INF_TRUNC - caution (truncated filename)
  447. * MPN_INF_SKIP - info "skip entry" (dir doesn't exist)
  448. * MPN_ERR_SKIP - error -> skip entry
  449. * MPN_ERR_TOOLONG - error -> path is too long
  450. * MPN_NOMEM - error (memory allocation failed) -> skip entry
  451. * [also MPN_VOL_LABEL, MPN_CREATED_DIR]
  452. */
  453. {
  454. char pathcomp[FILNAMSIZ]; /* path-component buffer */
  455. char *pp, *cp=(char *)NULL; /* character pointers */
  456. char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  457. #ifdef ACORN_FTYPE_NFS
  458. char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */
  459. RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */
  460. #endif
  461. int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */
  462. int error = MPN_OK;
  463. register unsigned workch; /* hold the character being tested */
  464. /*---------------------------------------------------------------------------
  465. Initialize various pointers and counters and stuff.
  466. ---------------------------------------------------------------------------*/
  467. if (G.pInfo->vollabel)
  468. return MPN_VOL_LABEL; /* can't set disk volume labels in Unix */
  469. /* can create path as long as not just freshening, or if user told us */
  470. G.create_dirs = (!uO.fflag || renamed);
  471. created_dir = FALSE; /* not yet */
  472. /* user gave full pathname: don't prepend rootpath */
  473. renamed_fullpath = (renamed && (*G.filename == '/'));
  474. if (checkdir(__G__ (char *)NULL, INIT) == MPN_NOMEM)
  475. return MPN_NOMEM; /* initialize path buffer, unless no memory */
  476. *pathcomp = '\0'; /* initialize translation buffer */
  477. pp = pathcomp; /* point to translation buffer */
  478. if (uO.jflag) /* junking directories */
  479. cp = (char *)strrchr(G.filename, '/');
  480. if (cp == (char *)NULL) /* no '/' or not junking dirs */
  481. cp = G.filename; /* point to internal zipfile-member pathname */
  482. else
  483. ++cp; /* point to start of last component of path */
  484. /*---------------------------------------------------------------------------
  485. Begin main loop through characters in filename.
  486. ---------------------------------------------------------------------------*/
  487. while ((workch = (uch)*cp++) != 0) {
  488. switch (workch) {
  489. case '/': /* can assume -j flag not given */
  490. *pp = '\0';
  491. if (strcmp(pathcomp, ".") == 0) {
  492. /* don't bother appending "./" to the path */
  493. *pathcomp = '\0';
  494. } else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) {
  495. /* "../" dir traversal detected, skip over it */
  496. *pathcomp = '\0';
  497. killed_ddot = TRUE; /* set "show message" flag */
  498. }
  499. /* when path component is not empty, append it now */
  500. if (*pathcomp != '\0' &&
  501. ((error = checkdir(__G__ pathcomp, APPEND_DIR))
  502. & MPN_MASK) > MPN_INF_TRUNC)
  503. return error;
  504. pp = pathcomp; /* reset conversion buffer for next piece */
  505. lastsemi = (char *)NULL; /* leave direct. semi-colons alone */
  506. break;
  507. case ';': /* VMS version (or DEC-20 attrib?) */
  508. lastsemi = pp;
  509. *pp++ = ';'; /* keep for now; remove VMS ";##" */
  510. break; /* later, if requested */
  511. #ifdef ACORN_FTYPE_NFS
  512. case ',': /* NFS filetype extension */
  513. lastcomma = pp;
  514. *pp++ = ','; /* keep for now; may need to remove */
  515. break; /* later, if requested */
  516. #endif
  517. #ifdef MTS
  518. case ' ': /* change spaces to underscore under */
  519. *pp++ = '_'; /* MTS; leave as spaces under Unix */
  520. break;
  521. #endif
  522. default:
  523. /* allow European characters in filenames: */
  524. if (isprint(workch) || (128 <= workch && workch <= 254))
  525. *pp++ = (char)workch;
  526. } /* end switch */
  527. } /* end while loop */
  528. /* Show warning when stripping insecure "parent dir" path components */
  529. if (killed_ddot && QCOND2) {
  530. Info(slide, 0, ((char *)slide,
  531. "warning: skipped \"../\" path component(s) in %s\n",
  532. FnFilter1(G.filename)));
  533. if (!(error & ~MPN_MASK))
  534. error = (error & MPN_MASK) | PK_WARN;
  535. }
  536. /*---------------------------------------------------------------------------
  537. Report if directory was created (and no file to create: filename ended
  538. in '/'), check name to be sure it exists, and combine path and name be-
  539. fore exiting.
  540. ---------------------------------------------------------------------------*/
  541. if (G.filename[strlen(G.filename) - 1] == '/') {
  542. checkdir(__G__ G.filename, GETPATH);
  543. if (created_dir) {
  544. if (QCOND2) {
  545. Info(slide, 0, ((char *)slide, " creating: %s\n",
  546. FnFilter1(G.filename)));
  547. }
  548. /* set dir time (note trailing '/') */
  549. return (error & ~MPN_MASK) | MPN_CREATED_DIR;
  550. }
  551. /* dir existed already; don't look for data to extract */
  552. return (error & ~MPN_MASK) | MPN_INF_SKIP;
  553. }
  554. *pp = '\0'; /* done with pathcomp: terminate it */
  555. /* if not saving them, remove VMS version numbers (appended ";###") */
  556. if (!uO.V_flag && lastsemi) {
  557. pp = lastsemi + 1;
  558. while (isdigit((uch)(*pp)))
  559. ++pp;
  560. if (*pp == '\0') /* only digits between ';' and end: nuke */
  561. *lastsemi = '\0';
  562. }
  563. /* On UNIX (and compatible systems), "." and ".." are reserved for
  564. * directory navigation and cannot be used as regular file names.
  565. * These reserved one-dot and two-dot names are mapped to "_" and "__".
  566. */
  567. if (strcmp(pathcomp, ".") == 0)
  568. *pathcomp = '_';
  569. else if (strcmp(pathcomp, "..") == 0)
  570. strcpy(pathcomp, "__");
  571. #ifdef ACORN_FTYPE_NFS
  572. /* translate Acorn filetype information if asked to do so */
  573. if (uO.acorn_nfs_ext &&
  574. (ef_spark = (RO_extra_block *)
  575. getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))
  576. != (RO_extra_block *)NULL)
  577. {
  578. /* file *must* have a RISC OS extra field */
  579. long ft = (long)makelong(ef_spark->loadaddr);
  580. /*32-bit*/
  581. if (lastcomma) {
  582. pp = lastcomma + 1;
  583. while (isxdigit((uch)(*pp))) ++pp;
  584. if (pp == lastcomma+4 && *pp == '\0') *lastcomma='\0'; /* nuke */
  585. }
  586. if ((ft & 1<<31)==0) ft=0x000FFD00;
  587. sprintf(pathcomp+strlen(pathcomp), ",%03x", (int)(ft>>8) & 0xFFF);
  588. }
  589. #endif /* ACORN_FTYPE_NFS */
  590. if (*pathcomp == '\0') {
  591. Info(slide, 1, ((char *)slide, "mapname: conversion of %s failed\n",
  592. FnFilter1(G.filename)));
  593. return (error & ~MPN_MASK) | MPN_ERR_SKIP;
  594. }
  595. checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
  596. checkdir(__G__ G.filename, GETPATH);
  597. return error;
  598. } /* end function mapname() */
  599. #if 0 /*========== NOTES ==========*/
  600. extract-to dir: a:path/
  601. buildpath: path1/path2/ ... (NULL-terminated)
  602. pathcomp: filename
  603. mapname():
  604. loop over chars in zipfile member name
  605. checkdir(path component, COMPONENT | CREATEDIR) --> map as required?
  606. (d:/tmp/unzip/) (disk:[tmp.unzip.)
  607. (d:/tmp/unzip/jj/) (disk:[tmp.unzip.jj.)
  608. (d:/tmp/unzip/jj/temp/) (disk:[tmp.unzip.jj.temp.)
  609. finally add filename itself and check for existence? (could use with rename)
  610. (d:/tmp/unzip/jj/temp/msg.outdir) (disk:[tmp.unzip.jj.temp]msg.outdir)
  611. checkdir(name, GETPATH) --> copy path to name and free space
  612. #endif /* 0 */
  613. /***********************/
  614. /* Function checkdir() */
  615. /***********************/
  616. int checkdir(__G__ pathcomp, flag)
  617. __GDEF
  618. char *pathcomp;
  619. int flag;
  620. /*
  621. * returns:
  622. * MPN_OK - no problem detected
  623. * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
  624. * MPN_INF_SKIP - path doesn't exist, not allowed to create
  625. * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
  626. * exists and is not a directory, but is supposed to be
  627. * MPN_ERR_TOOLONG - path is too long
  628. * MPN_NOMEM - can't allocate memory for filename buffers
  629. */
  630. {
  631. static int rootlen = 0; /* length of rootpath */
  632. static char *rootpath; /* user's "extract-to" directory */
  633. static char *buildpath; /* full path (so far) to extracted file */
  634. static char *end; /* pointer to end of buildpath ('\0') */
  635. # define FN_MASK 7
  636. # define FUNCTION (flag & FN_MASK)
  637. /*---------------------------------------------------------------------------
  638. APPEND_DIR: append the path component to the path being built and check
  639. for its existence. If doesn't exist and we are creating directories, do
  640. so for this one; else signal success or error as appropriate.
  641. ---------------------------------------------------------------------------*/
  642. if (FUNCTION == APPEND_DIR) {
  643. int too_long = FALSE;
  644. #ifdef SHORT_NAMES
  645. char *old_end = end;
  646. #endif
  647. Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
  648. while ((*end = *pathcomp++) != '\0')
  649. ++end;
  650. #ifdef SHORT_NAMES /* path components restricted to 14 chars, typically */
  651. if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
  652. *(end = old_end + FILENAME_MAX) = '\0';
  653. #endif
  654. /* GRR: could do better check, see if overrunning buffer as we go:
  655. * check end-buildpath after each append, set warning variable if
  656. * within 20 of FILNAMSIZ; then if var set, do careful check when
  657. * appending. Clear variable when begin new path. */
  658. /* next check: need to append '/', at least one-char name, '\0' */
  659. if ((end-buildpath) > FILNAMSIZ-3)
  660. too_long = TRUE; /* check if extracting dir? */
  661. /* for AOS/VS, try to create so as to not use searchlist: */
  662. if ( /*SSTAT(buildpath, &G.statbuf)*/ 1) {
  663. if (!G.create_dirs) { /* told not to create (freshening) */
  664. free(buildpath);
  665. return MPN_INF_SKIP; /* path doesn't exist: nothing to do */
  666. }
  667. if (too_long) {
  668. Info(slide, 1, ((char *)slide,
  669. "checkdir error: path too long: %s\n",
  670. FnFilter1(buildpath)));
  671. free(buildpath);
  672. /* no room for filenames: fatal */
  673. return MPN_ERR_TOOLONG;
  674. }
  675. /* create the directory */
  676. if (zvs_credir(buildpath,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1) == -1)
  677. {
  678. Info(slide, 1, ((char *)slide,
  679. "checkdir error: cannot create %s\n\
  680. %s\n\
  681. unable to process %s.\n",
  682. FnFilter2(buildpath),
  683. strerror(errno),
  684. FnFilter1(G.filename)));
  685. free(buildpath);
  686. /* path didn't exist, tried to create, failed */
  687. return MPN_ERR_SKIP;
  688. }
  689. created_dir = TRUE;
  690. } else if (!S_ISDIR(G.statbuf.st_mode)) {
  691. Info(slide, 1, ((char *)slide,
  692. "checkdir error: %s exists but is not directory\n\
  693. unable to process %s.\n",
  694. FnFilter2(buildpath), FnFilter1(G.filename)));
  695. free(buildpath);
  696. /* path existed but wasn't dir */
  697. return MPN_ERR_SKIP;
  698. }
  699. if (too_long) {
  700. Info(slide, 1, ((char *)slide,
  701. "checkdir error: path too long: %s\n", FnFilter1(buildpath)));
  702. free(buildpath);
  703. /* no room for filenames: fatal */
  704. return MPN_ERR_TOOLONG;
  705. }
  706. *end++ = '/';
  707. *end = '\0';
  708. Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath)));
  709. return MPN_OK;
  710. } /* end if (FUNCTION == APPEND_DIR) */
  711. /*---------------------------------------------------------------------------
  712. GETPATH: copy full path to the string pointed at by pathcomp, and free
  713. buildpath.
  714. ---------------------------------------------------------------------------*/
  715. if (FUNCTION == GETPATH) {
  716. strcpy(pathcomp, buildpath);
  717. Trace((stderr, "getting and freeing path [%s]\n",
  718. FnFilter1(pathcomp)));
  719. free(buildpath);
  720. buildpath = end = (char *)NULL;
  721. return MPN_OK;
  722. }
  723. /*---------------------------------------------------------------------------
  724. APPEND_NAME: assume the path component is the filename; append it and
  725. return without checking for existence.
  726. ---------------------------------------------------------------------------*/
  727. if (FUNCTION == APPEND_NAME) {
  728. #ifdef SHORT_NAMES
  729. char *old_end = end;
  730. #endif
  731. Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));
  732. while ((*end = *pathcomp++) != '\0') {
  733. ++end;
  734. #ifdef SHORT_NAMES /* truncate name at 14 characters, typically */
  735. if ((end-old_end) > FILENAME_MAX) /* GRR: proper constant? */
  736. *(end = old_end + FILENAME_MAX) = '\0';
  737. #endif
  738. if ((end-buildpath) >= FILNAMSIZ) {
  739. *--end = '\0';
  740. Info(slide, 1, ((char *)slide,
  741. "checkdir warning: path too long; truncating\n\
  742. %s\n -> %s\n",
  743. FnFilter1(G.filename), FnFilter2(buildpath)));
  744. return MPN_INF_TRUNC; /* filename truncated */
  745. }
  746. }
  747. Trace((stderr, "buildpath now = [%s]\n", FnFilter1(buildpath)));
  748. /* could check for existence here, prompt for new name... */
  749. return MPN_OK;
  750. }
  751. /*---------------------------------------------------------------------------
  752. INIT: allocate and initialize buffer space for the file currently being
  753. extracted. If file was renamed with an absolute path, don't prepend the
  754. extract-to path.
  755. ---------------------------------------------------------------------------*/
  756. /* GRR: for VMS and TOPS-20, add up to 13 to strlen */
  757. if (FUNCTION == INIT) {
  758. Trace((stderr, "initializing buildpath to "));
  759. if ((buildpath = (char *)malloc(strlen(G.filename)+rootlen+1))
  760. == (char *)NULL)
  761. return MPN_NOMEM;
  762. if ((rootlen > 0) && !renamed_fullpath) {
  763. strcpy(buildpath, rootpath);
  764. end = buildpath + rootlen;
  765. } else {
  766. *buildpath = '\0';
  767. end = buildpath;
  768. }
  769. Trace((stderr, "[%s]\n", FnFilter1(buildpath)));
  770. return MPN_OK;
  771. }
  772. /*---------------------------------------------------------------------------
  773. ROOT: if appropriate, store the path in rootpath and create it if
  774. necessary; else assume it's a zipfile member and return. This path
  775. segment gets used in extracting all members from every zipfile specified
  776. on the command line.
  777. ---------------------------------------------------------------------------*/
  778. #if (!defined(SFX) || defined(SFX_EXDIR))
  779. if (FUNCTION == ROOT) {
  780. Trace((stderr, "initializing root path to [%s]\n",
  781. FnFilter1(pathcomp)));
  782. if (pathcomp == (char *)NULL) {
  783. rootlen = 0;
  784. return MPN_OK;
  785. }
  786. if (rootlen > 0) /* rootpath was already set, nothing to do */
  787. return MPN_OK;
  788. if ((rootlen = strlen(pathcomp)) > 0) {
  789. char *tmproot;
  790. if ((tmproot = (char *)malloc(rootlen+2)) == (char *)NULL) {
  791. rootlen = 0;
  792. return MPN_NOMEM;
  793. }
  794. strcpy(tmproot, pathcomp);
  795. if (tmproot[rootlen-1] == '/') {
  796. tmproot[--rootlen] = '\0';
  797. }
  798. if (rootlen > 0 && (SSTAT(tmproot, &G.statbuf) ||
  799. !S_ISDIR(G.statbuf.st_mode)))
  800. { /* path does not exist */
  801. if (!G.create_dirs /* || iswild(tmproot) */ ) {
  802. free(tmproot);
  803. rootlen = 0;
  804. /* skip (or treat as stored file) */
  805. return MPN_INF_SKIP;
  806. }
  807. /* create the directory (could add loop here scanning tmproot
  808. * to create more than one level, but why really necessary?) */
  809. if (zvs_credir(tmproot,-1L,-1L,-1L,(char *) -1,-1,0L,-1,-1)
  810. == -1)
  811. {
  812. Info(slide, 1, ((char *)slide,
  813. "checkdir: cannot create extraction directory: %s\n\
  814. %s\n",
  815. FnFilter1(tmproot), strerror(errno)));
  816. free(tmproot);
  817. rootlen = 0;
  818. /* path didn't exist, tried to create, and failed: */
  819. /* file exists, or 2+ subdir levels required */
  820. return MPN_ERR_SKIP;
  821. }
  822. }
  823. tmproot[rootlen++] = '/';
  824. tmproot[rootlen] = '\0';
  825. if ((rootpath = (char *)realloc(tmproot, rootlen+1)) == NULL) {
  826. free(tmproot);
  827. rootlen = 0;
  828. return MPN_NOMEM;
  829. }
  830. Trace((stderr, "rootpath now = [%s]\n", FnFilter1(rootpath)));
  831. }
  832. return MPN_OK;
  833. }
  834. #endif /* !SFX || SFX_EXDIR */
  835. /*---------------------------------------------------------------------------
  836. END: free rootpath, immediately prior to program exit.
  837. ---------------------------------------------------------------------------*/
  838. if (FUNCTION == END) {
  839. Trace((stderr, "freeing rootpath\n"));
  840. if (rootlen > 0) {
  841. free(rootpath);
  842. rootlen = 0;
  843. }
  844. return MPN_OK;
  845. }
  846. return MPN_INVALID; /* should never reach */
  847. } /* end function checkdir() */
  848. /****************************/
  849. /* Function close_outfile() */
  850. /****************************/
  851. void close_outfile(__G) /* GRR: change to return PK-style warning level */
  852. __GDEF
  853. {
  854. /*---------------------------------------------------------------------------
  855. If symbolic links are supported, allocate storage for a symlink control
  856. structure, put the uncompressed "data" and other required info in it, and
  857. add the structure to the "deferred symlinks" chain. Since we know it's a
  858. symbolic link to start with, we shouldn't have to worry about overflowing
  859. unsigned ints with unsigned longs.
  860. ---------------------------------------------------------------------------*/
  861. #ifdef SYMLINKS
  862. if (G.symlnk) {
  863. extent ucsize = (extent)G.lrec.ucsize;
  864. /* size of the symlink entry is the sum of
  865. * (struct size (includes 1st '\0') + 1 additional trailing '\0'),
  866. * system specific attribute data size (might be 0),
  867. * and the lengths of name and link target.
  868. */
  869. extent slnk_entrysize = (sizeof(slinkentry) + 1) +
  870. ucsize + strlen(G.filename);
  871. slinkentry *slnk_entry;
  872. if (slnk_entrysize < ucsize) {
  873. Info(slide, 0x201, ((char *)slide,
  874. "warning: symbolic link (%s) failed: mem alloc overflow\n",
  875. FnFilter1(G.filename)));
  876. fclose(G.outfile);
  877. return;
  878. }
  879. if ((slnk_entry = (slinkentry *)malloc(slnk_entrysize)) == NULL) {
  880. Info(slide, 0x201, ((char *)slide,
  881. "warning: symbolic link (%s) failed: no mem\n",
  882. FnFilter1(G.filename)));
  883. fclose(G.outfile);
  884. return;
  885. }
  886. slnk_entry->next = NULL;
  887. slnk_entry->targetlen = ucsize;
  888. slnk_entry->attriblen = 0; /* don't set attributes for symlinks */
  889. slnk_entry->target = slnk_entry->buf;
  890. slnk_entry->fname = slnk_entry->target + ucsize + 1;
  891. strcpy(slnk_entry->fname, G.filename);
  892. /* move back to the start of the file to re-read the "link data" */
  893. rewind(G.outfile);
  894. if (fread(slnk_entry->target, 1, ucsize, G.outfile) != ucsize)
  895. {
  896. Info(slide, 0x201, ((char *)slide,
  897. "warning: symbolic link (%s) failed\n",
  898. FnFilter1(G.filename)));
  899. free(slnk_entry);
  900. fclose(G.outfile);
  901. return;
  902. }
  903. fclose(G.outfile); /* close "link" file for good... */
  904. slnk_entry->target[ucsize] = '\0';
  905. if (QCOND2)
  906. Info(slide, 0, ((char *)slide, "-> %s ",
  907. FnFilter1(slnk_entry->target)));
  908. /* add this symlink record to the list of deferred symlinks */
  909. if (G.slink_last != NULL)
  910. G.slink_last->next = slnk_entry;
  911. else
  912. G.slink_head = slnk_entry;
  913. G.slink_last = slnk_entry;
  914. return;
  915. }
  916. #endif /* SYMLINKS */
  917. fclose(G.outfile);
  918. /*---------------------------------------------------------------------------
  919. Change the file permissions from default ones to those stored in the
  920. zipfile.
  921. ---------------------------------------------------------------------------*/
  922. #ifndef NO_CHMOD
  923. if (chmod(G.filename, 0xffff & G.pInfo->file_attr))
  924. perror("chmod (file attributes) error");
  925. #endif
  926. /*---------------------------------------------------------------------------
  927. AOS/VS only allows setting file times at creation but has its own permis-
  928. sions scheme which is better invoked here if the necessary information
  929. was in fact stored. In theory, we should look through an entire series
  930. of extra fields that might exist for the same file, but we're not going
  931. to bother. If we set up other types of extra fields, or if we run into
  932. other environments that add their own stuff to existing entries in ZIP
  933. files, we'll have to. NOTE: already copied extra-field stuff into
  934. zzextrafld structure when file was created.
  935. ---------------------------------------------------------------------------*/
  936. if (G.extra_field != NULL) {
  937. if (!memcmp(ZEXTRA_HEADID, zzextrafld.extra_header_id,
  938. sizeof(zzextrafld.extra_header_id)) &&
  939. !memcmp(ZEXTRA_SENTINEL, zzextrafld.extra_sentinel,
  940. sizeof(zzextrafld.extra_sentinel)) &&
  941. zzextrafld.fstat_packet.norm_fstat_packet.styp_type != $FLNK)
  942. /* (AOS/VS links don't have ACLs) */
  943. {
  944. /* vs_path was set (in this case) when we created the file */
  945. if (sys_sacl(vs_path, zzextrafld.aclbuf)) {
  946. Info(slide, 0x201, ((char *)slide,
  947. "error: cannot set ACL for %s\n", FnFilter1(G.filename)));
  948. perror("sys_sacl()");
  949. }
  950. }
  951. }
  952. } /* end function close_outfile() */
  953. #ifndef SFX
  954. /************************/
  955. /* Function version() */
  956. /************************/
  957. void version(__G)
  958. __GDEF
  959. {
  960. #if (defined(__GNUC__) && defined(NX_CURRENT_COMPILER_RELEASE))
  961. char cc_namebuf[40];
  962. char cc_versbuf[40];
  963. #else
  964. #if (defined(CRAY) && defined(_RELEASE))
  965. char cc_versbuf[40];
  966. #endif
  967. #endif
  968. #if ((defined(CRAY) || defined(cray)) && defined(_UNICOS))
  969. char os_namebuf[40];
  970. #else
  971. #if defined(__NetBSD__)
  972. char os_namebuf[40];
  973. #endif
  974. #endif
  975. /* Pyramid, NeXT have problems with huge macro expansion, too: no Info() */
  976. sprintf((char *)slide, LoadFarString(CompiledWith),
  977. #ifdef __GNUC__
  978. # ifdef NX_CURRENT_COMPILER_RELEASE
  979. (sprintf(cc_namebuf, "NeXT DevKit %d.%02d ",
  980. NX_CURRENT_COMPILER_RELEASE/100, NX_CURRENT_COMPILER_RELEASE%100),
  981. cc_namebuf),
  982. (strlen(__VERSION__) > 8)? "(gcc)" :
  983. (sprintf(cc_versbuf, "(gcc %s)", __VERSION__), cc_versbuf),
  984. # else
  985. "gcc ", __VERSION__,
  986. # endif
  987. #else
  988. # if defined(CRAY) && defined(_RELEASE)
  989. "cc ", (sprintf(cc_versbuf, "version %d", _RELEASE), cc_versbuf),
  990. # else
  991. # ifdef __VERSION__
  992. # ifndef IZ_CC_NAME
  993. # define IZ_CC_NAME "cc "
  994. # endif
  995. IZ_CC_NAME, __VERSION__
  996. # else
  997. # ifndef IZ_CC_NAME
  998. # define IZ_CC_NAME "cc"
  999. # endif
  1000. IZ_CC_NAME, "",
  1001. # endif
  1002. # endif
  1003. #endif /* ?__GNUC__ */
  1004. #ifndef IZ_OS_NAME
  1005. # define IZ_OS_NAME "Unix"
  1006. #endif
  1007. IZ_OS_NAME,
  1008. #if defined(sgi) || defined(__sgi)
  1009. " (Silicon Graphics IRIX)",
  1010. #else
  1011. #ifdef sun
  1012. # ifdef sparc
  1013. # ifdef __SVR4
  1014. " (Sun SPARC/Solaris)",
  1015. # else /* may or may not be SunOS */
  1016. " (Sun SPARC)",
  1017. # endif
  1018. # else
  1019. # if defined(sun386) || defined(i386)
  1020. " (Sun 386i)",
  1021. # else
  1022. # if defined(mc68020) || defined(__mc68020__)
  1023. " (Sun 3)",
  1024. # else /* mc68010 or mc68000: Sun 2 or earlier */
  1025. " (Sun 2)",
  1026. # endif
  1027. # endif
  1028. # endif
  1029. #else
  1030. #ifdef __hpux
  1031. " (HP/UX)",
  1032. #else
  1033. #ifdef __osf__
  1034. " (DEC OSF/1)",
  1035. #else
  1036. #ifdef _AIX
  1037. " (IBM AIX)",
  1038. #else
  1039. #ifdef aiws
  1040. " (IBM RT/AIX)",
  1041. #else
  1042. #if defined(CRAY) || defined(cray)
  1043. # ifdef _UNICOS
  1044. (sprintf(os_namebuf, " (Cray UNICOS release %d)", _UNICOS), os_namebuf),
  1045. # else
  1046. " (Cray UNICOS)",
  1047. # endif
  1048. #else
  1049. #if defined(uts) || defined(UTS)
  1050. " (Amdahl UTS)",
  1051. #else
  1052. #ifdef NeXT
  1053. # ifdef mc68000
  1054. " (NeXTStep/black)",
  1055. # else
  1056. " (NeXTStep for Intel)",
  1057. # endif
  1058. #else /* the next dozen or so are somewhat order-dependent */
  1059. #ifdef LINUX
  1060. # ifdef __ELF__
  1061. " (Linux ELF)",
  1062. # else
  1063. " (Linux a.out)",
  1064. # endif
  1065. #else
  1066. #ifdef MINIX
  1067. " (Minix)",
  1068. #else
  1069. #ifdef M_UNIX
  1070. " (SCO Unix)",
  1071. #else
  1072. #ifdef M_XENIX
  1073. " (SCO Xenix)",
  1074. #else
  1075. #ifdef __NetBSD__
  1076. # ifdef NetBSD0_8
  1077. (sprintf(os_namebuf, " (NetBSD 0.8%c)", (char)(NetBSD0_8 - 1 + 'A')),
  1078. os_namebuf),
  1079. # else
  1080. # ifdef NetBSD0_9
  1081. (sprintf(os_namebuf, " (NetBSD 0.9%c)", (char)(NetBSD0_9 - 1 + 'A')),
  1082. os_namebuf),
  1083. # else
  1084. # ifdef NetBSD1_0
  1085. (sprintf(os_namebuf, " (NetBSD 1.0%c)", (char)(NetBSD1_0 - 1 + 'A')),
  1086. os_namebuf),
  1087. # else
  1088. (BSD4_4 == 0.5)? " (NetBSD before 0.9)" : " (NetBSD 1.1 or later)",
  1089. # endif
  1090. # endif
  1091. # endif
  1092. #else
  1093. #ifdef __FreeBSD__
  1094. (BSD4_4 == 0.5)? " (FreeBSD 1.x)" : " (FreeBSD 2.0 or later)",
  1095. #else
  1096. #ifdef __bsdi__
  1097. (BSD4_4 == 0.5)? " (BSD/386 1.0)" : " (BSD/386 1.1 or later)",
  1098. #else
  1099. #ifdef __386BSD__
  1100. (BSD4_4 == 1)? " (386BSD, post-4.4 release)" : " (386BSD)",
  1101. #else
  1102. #if defined(i486) || defined(__i486) || defined(__i486__)
  1103. " (Intel 486)",
  1104. #else
  1105. #if defined(i386) || defined(__i386) || defined(__i386__)
  1106. " (Intel 386)",
  1107. #else
  1108. #ifdef pyr
  1109. " (Pyramid)",
  1110. #else
  1111. #ifdef ultrix
  1112. # ifdef mips
  1113. " (DEC/MIPS)",
  1114. # else
  1115. # ifdef vax
  1116. " (DEC/VAX)",
  1117. # else /* __alpha? */
  1118. " (DEC/Alpha)",
  1119. # endif
  1120. # endif
  1121. #else
  1122. #ifdef gould
  1123. " (Gould)",
  1124. #else
  1125. #ifdef MTS
  1126. " (MTS)",
  1127. #else
  1128. #ifdef __convexc__
  1129. " (Convex)",
  1130. #else
  1131. "",
  1132. #endif /* Convex */
  1133. #endif /* MTS */
  1134. #endif /* Gould */
  1135. #endif /* DEC */
  1136. #endif /* Pyramid */
  1137. #endif /* 386 */
  1138. #endif /* 486 */
  1139. #endif /* 386BSD */
  1140. #endif /* BSDI BSD/386 */
  1141. #endif /* NetBSD */
  1142. #endif /* FreeBSD */
  1143. #endif /* SCO Xenix */
  1144. #endif /* SCO Unix */
  1145. #endif /* Minix */
  1146. #endif /* Linux */
  1147. #endif /* NeXT */
  1148. #endif /* Amdahl */
  1149. #endif /* Cray */
  1150. #endif /* RT/AIX */
  1151. #endif /* AIX */
  1152. #endif /* OSF/1 */
  1153. #endif /* HP/UX */
  1154. #endif /* Sun */
  1155. #endif /* SGI */
  1156. #ifdef __DATE__
  1157. " on ", __DATE__
  1158. #else
  1159. "", ""
  1160. #endif
  1161. );
  1162. (*G.message)((zvoid *)&G, slide, (ulg)strlen((char *)slide), 0);
  1163. } /* end function version() */
  1164. #endif /* !SFX */
  1165. /* ===================================================================
  1166. * ZVS_CREATE()
  1167. * Function to create a file with specified times. The times should be sent
  1168. * as long ints in DG time format; use -1 to set to the current times. You
  1169. * may also specify a pointer to the ACL, the file type (see PARU.H, and do
  1170. * not specify dirs or links), the element size, and the max index level.
  1171. * For all of these parameters you may use -1 to specify the default.
  1172. *
  1173. * Returns 0 if no error, or the error code returned by ?CREATE.
  1174. *
  1175. * HISTORY:
  1176. * 15-dec-93 dbl
  1177. * 31-may-94 dbl: added call to convert pathname to AOS/VS
  1178. *
  1179. *
  1180. */
  1181. int zvs_create(ZCONST char *fname, long cretim, long modtim, long acctim,
  1182. char *pacl, int ftyp, int eltsize, int maxindlev)
  1183. {
  1184. P_CREATE pcr_stru;
  1185. P_CTIM pct_stru;
  1186. pcr_stru.cftyp_format = 0; /* unspecified record format */
  1187. if (ftyp == -1) /* default file type to UNX */
  1188. pcr_stru.cftyp_entry = $FUNX;
  1189. else
  1190. pcr_stru.cftyp_entry = ftyp;
  1191. pcr_stru.ctim = &pct_stru;
  1192. pcr_stru.cacp = pacl;
  1193. pcr_stru.cdel = eltsize;
  1194. pcr_stru.cmil = maxindlev;
  1195. pct_stru.tcth.long_time = cretim;
  1196. pct_stru.tath.long_time = acctim;
  1197. pct_stru.tmth.long_time = modtim;
  1198. return (sys_create(ux_to_vs_name(Vs_path, fname), &pcr_stru));
  1199. } /* end zvs_create() */
  1200. /* ===================================================================
  1201. * ZVS_CREDIR()
  1202. * Function to create a dir as specified. The times should be sent
  1203. * as long ints in DG time format; use -1 to set to the current times. You
  1204. * may also specify a pointer to the ACL, the file type (either $FDIR or $FCPD; see PARU.H),
  1205. * the max # blocks (if a CPD), the hash frame size, and the max index level.
  1206. * For all of these parameters (except for the CPD's maximum blocks),
  1207. * you may use -1 to specify the default.
  1208. *
  1209. * (The System Call Dictionary says both that you may specify a
  1210. * maximum-index-level value up to the maximum, with 0 for a contiguous
  1211. * directory, and that 3 is always used for this whatever you specify.)
  1212. *
  1213. * If you specify anything other than CPD for the file type, DIR will
  1214. * be used.
  1215. *
  1216. * Returns 0 if no error, or the error code returned by ?CREATE.
  1217. *
  1218. * HISTORY:
  1219. * 1-jun-94 dbl
  1220. *
  1221. *
  1222. */
  1223. int zvs_credir(ZCONST char *dname, long cretim, long modtim, long acctim,
  1224. char *pacl, int ftyp, long maxblocks, int hashfsize,
  1225. int maxindlev)
  1226. {
  1227. P_CREATE_DIR pcr_stru;
  1228. P_CTIM pct_stru;
  1229. if (ftyp != $FCPD) /* default file type to UNX */
  1230. pcr_stru.cftyp_entry = $FDIR;
  1231. else
  1232. {
  1233. pcr_stru.cftyp_entry = ftyp;
  1234. pcr_stru.cmsh = maxblocks;
  1235. }
  1236. pcr_stru.ctim = &pct_stru;
  1237. pcr_stru.cacp = pacl;
  1238. pcr_stru.chfs = hashfsize;
  1239. pcr_stru.cmil = maxindlev;
  1240. pct_stru.tcth.long_time = cretim;
  1241. pct_stru.tath.long_time = acctim;
  1242. pct_stru.tmth.long_time = modtim;
  1243. return (sys_create(ux_to_vs_name(Vs_path, dname), &pcr_stru));
  1244. } /* end zvs_credir() */
  1245. /* ===================================================================
  1246. * UX_TO_VS_NAME() - makes a somewhat dumb pass at converting a Unix
  1247. * filename to an AOS/VS filename. This should
  1248. * be just about adequate to handle the results
  1249. * of similarly-simple AOS/VS-to-Unix conversions
  1250. * in the ZIP program. It does not guarantee a
  1251. * legal AOS/VS filename for every Unix filename;
  1252. * conspicuous examples would be names with
  1253. * embedded ./ and ../ (which will receive no
  1254. * special treatment).
  1255. *
  1256. * RETURNS: pointer to the result (which is an input parameter)
  1257. *
  1258. * NOTE: calling code is responsible for making sure
  1259. * the output buffer is big enough!
  1260. *
  1261. * HISTORY:
  1262. * 31-may-94 dbl
  1263. *
  1264. */
  1265. char *ux_to_vs_name(char *outname, ZCONST char *inname)
  1266. {
  1267. ZCONST char *ip=inname, *op=outname;
  1268. if (ip[0] == '.') {
  1269. if (ip[1] == '/') {
  1270. *(op++) = '=';
  1271. ip += 2;
  1272. } else if (ip[1] == '.' && ip[2] == '/') {
  1273. *(op++) = '^';
  1274. ip += 3;
  1275. }
  1276. }
  1277. do {
  1278. if (*ip == '/')
  1279. *(op++) = ':';
  1280. else if (strchr(
  1281. "0123456789_$?.abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
  1282. *ip) != NULL)
  1283. {
  1284. *(op++) = *ip;
  1285. } else
  1286. *(op++) = '?';
  1287. } while (*(ip++) != '\0');
  1288. return outname;
  1289. } /* end ux_to_vs_name() */
  1290. /* =================================================================== */
  1291. /* DGDATE
  1292. Two functions do encode/decode dates in DG system format.
  1293. Usage:
  1294. long value,year,month,day;
  1295. value=dgdate(month,day,year);
  1296. undgdate(value,&month,&day,&year); [GRR: not used in UnZip: removed]
  1297. Notes:
  1298. 1. DG date functions only work on dates within the range
  1299. Jan 1, 1968 through Dec 31, 2099. I have tested these
  1300. functions through the same range with exact agreement.
  1301. For dates outside of that range, the DG system calls
  1302. may return different values than these functions.
  1303. 2. dgundate() accepts values between 0 and 48213 inclusive.
  1304. These correspond to 12/31/1967 and 12/31/2099.
  1305. 3. Both functions assume the data is in the native OS byte
  1306. order. So if you're reading or writing these fields from
  1307. a file that has been passed between AOS/VS and PC-DOS you
  1308. will need to swap byte order.
  1309. 4. With reference to byte order, the entire range of values
  1310. supported by these functions will fit into an unsigned
  1311. short int. In most cases the input or output will be
  1312. in that variable type. You are better off casting the
  1313. value to/from unsigned short so you only need to concern
  1314. yourself with swapping two bytes instead of four.
  1315. Written by: Stanley J. Gula
  1316. US&T, Inc.
  1317. 529 Main Street, Suite 1
  1318. Indian Orchard, MA 01151
  1319. (413)-543-3672
  1320. Copyright (c) 1990 US&T, Inc.
  1321. All rights reserved.
  1322. I hereby release these functions into the public
  1323. domain. You may use these routines freely as long
  1324. as the US&T copyright remains intact in the source
  1325. code.
  1326. Stanley J. Gula July 24, 1990
  1327. */
  1328. long motable[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
  1329. long yrtable[132]={
  1330. 366, 731, 1096, 1461, 1827, 2192, 2557, 2922, 3288, 3653,
  1331. 4018, 4383, 4749, 5114, 5479, 5844, 6210, 6575, 6940, 7305,
  1332. 7671, 8036, 8401, 8766, 9132, 9497, 9862,10227,10593,10958,
  1333. 11323,11688,12054,12419,12784,13149,13515,13880,14245,14610,
  1334. 14976,15341,15706,16071,16437,16802,17167,17532,17898,18263,
  1335. 18628,18993,19359,19724,20089,20454,20820,21185,21550,21915,
  1336. 22281,22646,23011,23376,23742,24107,24472,24837,25203,25568,
  1337. 25933,26298,26664,27029,27394,27759,28125,28490,28855,29220,
  1338. 29586,29951,30316,30681,31047,31412,31777,32142,32508,32873,
  1339. 33238,33603,33969,34334,34699,35064,35430,35795,36160,36525,
  1340. 36891,37256,37621,37986,38352,38717,39082,39447,39813,40178,
  1341. 40543,40908,41274,41639,42004,42369,42735,43100,43465,43830,
  1342. 44196,44561,44926,45291,45657,46022,46387,46752,47118,47483,
  1343. 47848,48213};
  1344. /* Given y,m,d return # of days since 12/31/67 */
  1345. long int dgdate(short mm, short dd, short yy)
  1346. {
  1347. long int temp;
  1348. short ytmp;
  1349. if (mm<1 || mm>12 || dd<1 || dd>31 || yy<1968 || yy>2099)
  1350. return 0L;
  1351. /* Figure in whole years since 1968 + whole months plus days */
  1352. temp=365L*(long)(yy-1968) + motable[mm-1] + (long)dd;
  1353. /* Adjust for leap years - note we don't account for skipped leap
  1354. year in years divisible by 1000 but not by 4000. We're correct
  1355. through the year 2099 */
  1356. temp+=(yy-1965)/4;
  1357. /* Correct for this year */
  1358. /* In leap years, if date is 3/1 or later, bump */
  1359. if ((yy%4==0) && (mm>2))
  1360. temp++;
  1361. return temp;
  1362. }