os2.c 76 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413
  1. /*
  2. Copyright (c) 1990-2007 Info-ZIP. All rights reserved.
  3. See the accompanying file LICENSE, version 2000-Apr-09 or later
  4. (the contents of which are also included in zip.h) for terms of use.
  5. If, for some reason, both of 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. os2.c
  10. OS/2-specific routines for use with Info-ZIP's UnZip 5.1 and later.
  11. This file contains the OS/2 versions of the file name/attribute/time/etc
  12. code. Most or all of the routines which make direct use of OS/2 system
  13. calls (i.e., the non-lowercase routines) are Kai Uwe Rommel's. The read-
  14. dir() suite was written by Michael Rendell and ported to OS/2 by Kai Uwe;
  15. it is in the public domain.
  16. Contains: GetCountryInfo()
  17. SetFileSize()
  18. GetFileTime()
  19. SetFileTime() (TIMESTAMP only)
  20. stamp_file() (TIMESTAMP only)
  21. Utime2DosDateTime()
  22. SetPathAttrTimes()
  23. SetEAs()
  24. GetLoadPath()
  25. opendir()
  26. closedir()
  27. readdir()
  28. [ seekdir() ] not used
  29. [ telldir() ] not used
  30. free_dircontents()
  31. getdirent()
  32. IsFileSystemFAT()
  33. do_wild()
  34. mapattr()
  35. mapname()
  36. checkdir()
  37. isfloppy()
  38. IsFileNameValid()
  39. map2fat()
  40. SetLongNameEA()
  41. close_outfile()
  42. check_for_newer()
  43. dateformat()
  44. version()
  45. zcalloc() (16-bit, only)
  46. zcfree() (16-bit, only)
  47. InitNLS()
  48. IsUpperNLS()
  49. ToLowerNLS()
  50. StringLower()
  51. screensize()
  52. DebugMalloc()
  53. ---------------------------------------------------------------------------*/
  54. #define UNZIP_INTERNAL
  55. #include "unzip.h"
  56. /* fUnZip does not need anything from here except the zcalloc() & zcfree()
  57. * function pair (when Deflate64 support is enabled in 16-bit environment).
  58. */
  59. #ifndef FUNZIP
  60. #include "os2acl.h"
  61. extern ZCONST char Far TruncEAs[];
  62. /* local prototypes */
  63. #ifdef TIMESTAMP
  64. static int SetFileTime(ZCONST char *name, ulg stamp);
  65. #endif
  66. #if defined(USE_EF_UT_TIME) || defined(TIMESTAMP)
  67. static ulg Utime2DosDateTime OF((time_t uxtime));
  68. #endif
  69. static int getOS2filetimes OF((__GPRO__
  70. ulg *pM_dt, ulg *pA_dt, ulg *pC_dt));
  71. static void SetPathAttrTimes OF((__GPRO__ int flags, int dir));
  72. static int SetEAs OF((__GPRO__ const char *path,
  73. void *ef_block));
  74. static int SetACL OF((__GPRO__ const char *path,
  75. void *ef_block));
  76. static int EvalExtraFields OF((__GPRO__ const char *path,
  77. void *extra_field, unsigned ef_len));
  78. static int isfloppy OF((int nDrive));
  79. static int IsFileNameValid OF((const char *name));
  80. static void map2fat OF((char *pathcomp, char **pEndFAT));
  81. static int SetLongNameEA OF((char *name, char *longname));
  82. static void InitNLS OF((void));
  83. #ifdef ACORN_FTYPE_NFS
  84. /* Acorn bits for NFS filetyping */
  85. typedef struct {
  86. uch ID[2];
  87. uch size[2];
  88. uch ID_2[4];
  89. uch loadaddr[4];
  90. uch execaddr[4];
  91. uch attr[4];
  92. } RO_extra_block;
  93. #endif /* ACORN_FTYPE_NFS */
  94. /*****************************/
  95. /* Strings used in os2.c */
  96. /*****************************/
  97. #ifndef SFX
  98. static ZCONST char Far CantAllocateWildcard[] =
  99. "warning: cannot allocate wildcard buffers\n";
  100. #endif
  101. static ZCONST char Far WarnDirTraversSkip[] =
  102. "warning: skipped \"../\" path component(s) in %s\n";
  103. static ZCONST char Far Creating[] = " creating: %-22s ";
  104. static ZCONST char Far ConversionFailed[] =
  105. "mapname: conversion of %s failed\n";
  106. static ZCONST char Far Labelling[] = "labelling %c: %-22s\n";
  107. static ZCONST char Far ErrSetVolLabel[] =
  108. "mapname: error setting volume label\n";
  109. static ZCONST char Far PathTooLong[] = "checkdir error: path too long: %s\n";
  110. static ZCONST char Far CantCreateDir[] = "checkdir error: cannot create %s\n\
  111. unable to process %s.\n";
  112. static ZCONST char Far DirIsntDirectory[] =
  113. "checkdir error: %s exists but is not directory\n\
  114. unable to process %s.\n";
  115. static ZCONST char Far PathTooLongTrunc[] =
  116. "checkdir warning: path too long; truncating\n %s\n\
  117. -> %s\n";
  118. #if (!defined(SFX) || defined(SFX_EXDIR))
  119. static ZCONST char Far CantCreateExtractDir[] =
  120. "checkdir: cannot create extraction directory: %s\n";
  121. #endif
  122. #ifndef __GNUC__
  123. /* all supported non-gcc compilers provide MSC/DOS style mkdir() */
  124. # if (_MSC_VER >= 600) || defined(__IBMC__)
  125. # include <direct.h> /* have special MSC/IBM C mkdir prototype */
  126. # else /* own prototype because dir.h conflicts? */
  127. int mkdir(const char *path);
  128. # endif
  129. # define MKDIR(path,mode) mkdir(path)
  130. #else
  131. /* EMX and hopefully all other gcc ports support POSIX style mkdir() */
  132. # define MKDIR(path,mode) mkdir(path,mode)
  133. #endif
  134. #ifdef __32BIT__
  135. USHORT DosDevIOCtl32(PVOID pData, USHORT cbData, PVOID pParms, USHORT cbParms,
  136. USHORT usFunction, USHORT usCategory, HFILE hDevice)
  137. {
  138. ULONG ulParmLengthInOut = cbParms, ulDataLengthInOut = cbData;
  139. return (USHORT) DosDevIOCtl(hDevice, usCategory, usFunction,
  140. pParms, cbParms, &ulParmLengthInOut,
  141. pData, cbData, &ulDataLengthInOut);
  142. }
  143. # define DosDevIOCtl DosDevIOCtl32
  144. #else
  145. # define DosDevIOCtl DosDevIOCtl2
  146. #endif
  147. typedef struct
  148. {
  149. ush nID;
  150. ush nSize;
  151. ulg lSize;
  152. }
  153. EFHEADER, *PEFHEADER;
  154. #ifdef __32BIT__
  155. #define DosFindFirst(p1, p2, p3, p4, p5, p6) \
  156. DosFindFirst(p1, p2, p3, p4, p5, p6, 1)
  157. #else
  158. typedef struct
  159. {
  160. ULONG oNextEntryOffset;
  161. BYTE fEA;
  162. BYTE cbName;
  163. USHORT cbValue;
  164. CHAR szName[1];
  165. }
  166. FEA2, *PFEA2;
  167. typedef struct
  168. {
  169. ULONG cbList;
  170. FEA2 list[1];
  171. }
  172. FEA2LIST, *PFEA2LIST;
  173. #define DosQueryCurrentDisk DosQCurDisk
  174. #define DosQueryFSAttach(p1, p2, p3, p4, p5) \
  175. DosQFSAttach(p1, p2, p3, p4, p5, 0)
  176. #define DosEnumAttribute(p1, p2, p3, p4, p5, p6, p7) \
  177. DosEnumAttribute(p1, p2, p3, p4, p5, p6, p7, 0)
  178. #define DosFindFirst(p1, p2, p3, p4, p5, p6) \
  179. DosFindFirst(p1, p2, p3, p4, p5, p6, 0)
  180. #define DosMapCase DosCaseMap
  181. #define DosSetPathInfo(p1, p2, p3, p4, p5) \
  182. DosSetPathInfo(p1, p2, p3, p4, p5, 0)
  183. #define DosQueryPathInfo(p1, p2, p3, p4) \
  184. DosQPathInfo(p1, p2, p3, p4, 0)
  185. #define DosQueryFileInfo DosQFileInfo
  186. #define DosMapCase DosCaseMap
  187. #define DosQueryCtryInfo DosGetCtryInfo
  188. #endif /* !__32BIT__ */
  189. /*
  190. * @(#) dir.h 1.4 87/11/06 Public Domain.
  191. */
  192. #define A_RONLY 0x01
  193. #define A_HIDDEN 0x02
  194. #define A_SYSTEM 0x04
  195. #define A_LABEL 0x08
  196. #define A_DIR 0x10
  197. #define A_ARCHIVE 0x20
  198. const int attributes = A_DIR | A_HIDDEN | A_SYSTEM;
  199. extern DIR *opendir(__GPRO__ ZCONST char *);
  200. extern struct direct *readdir(__GPRO__ DIR *);
  201. extern void seekdir(DIR *, long);
  202. extern long telldir(DIR *);
  203. extern void closedir(DIR *);
  204. #define rewinddir(dirp) seekdir(dirp, 0L)
  205. int IsFileSystemFAT(__GPRO__ ZCONST char *dir);
  206. char *StringLower(char *szArg);
  207. /*
  208. * @(#)dir.c 1.4 87/11/06 Public Domain.
  209. */
  210. #ifndef S_IFMT
  211. # define S_IFMT 0xF000
  212. #endif
  213. #ifndef SFX
  214. static char *getdirent(__GPRO__ ZCONST char *);
  215. static void free_dircontents(struct _dircontents *);
  216. #endif /* !SFX */
  217. int GetCountryInfo(void)
  218. {
  219. COUNTRYINFO ctryi;
  220. COUNTRYCODE ctryc;
  221. #ifdef __32BIT__
  222. ULONG cbInfo;
  223. #else
  224. USHORT cbInfo;
  225. #endif
  226. ctryc.country = ctryc.codepage = 0;
  227. if ( DosQueryCtryInfo(sizeof(ctryi), &ctryc, &ctryi, &cbInfo) != NO_ERROR )
  228. return 0;
  229. return ctryi.fsDateFmt;
  230. }
  231. int SetFileSize(FILE *file, ulg filesize)
  232. {
  233. #ifdef __32BIT__
  234. return DosSetFileSize(fileno(file), (size_t)filesize) ? -1 : 0;
  235. #else
  236. return 0;
  237. #endif
  238. }
  239. long GetFileTime(ZCONST char *name)
  240. {
  241. #ifdef __32BIT__
  242. FILESTATUS3 fs;
  243. #else
  244. FILESTATUS fs;
  245. #endif
  246. USHORT nDate, nTime;
  247. if ( DosQueryPathInfo((PSZ) name, 1, (PBYTE) &fs, sizeof(fs)) )
  248. return -1;
  249. nDate = * (USHORT *) &fs.fdateLastWrite;
  250. nTime = * (USHORT *) &fs.ftimeLastWrite;
  251. return ((ULONG) nDate) << 16 | nTime;
  252. }
  253. #ifdef TIMESTAMP
  254. static int SetFileTime(ZCONST char *name, ulg stamp) /* swiped from Zip */
  255. {
  256. FILESTATUS fs;
  257. USHORT fd, ft;
  258. if (DosQueryPathInfo((PSZ) name, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)))
  259. return -1;
  260. fd = (USHORT) (stamp >> 16);
  261. ft = (USHORT) stamp;
  262. fs.fdateLastWrite = fs.fdateCreation = * (FDATE *) &fd;
  263. fs.ftimeLastWrite = fs.ftimeCreation = * (FTIME *) &ft;
  264. if (DosSetPathInfo((PSZ) name, FIL_STANDARD, (PBYTE) &fs, sizeof(fs), 0))
  265. return -1;
  266. return 0;
  267. }
  268. int stamp_file(ZCONST char *fname, time_t modtime)
  269. {
  270. return SetFileTime(fname, Utime2DosDateTime(modtime));
  271. }
  272. #endif /* TIMESTAMP */
  273. /* The following DOS date/time structures are machine-dependent as they
  274. * assume "little-endian" byte order. For OS/2-specific code, which
  275. * is run on x86 CPUs (or emulators?), this assumption is valid; but
  276. * care should be taken when using this code as template for other ports.
  277. */
  278. typedef union {
  279. ULONG timevalue; /* combined value, useful for comparisons */
  280. struct {
  281. FTIME ft; /* system file time record:
  282. * USHORT twosecs : 5
  283. * USHORT minutes : 6;
  284. * USHORT hours : 5; */
  285. FDATE fd; /* system file date record:
  286. * USHORT day : 5
  287. * USHORT month : 4;
  288. * USHORT year : 7; */
  289. } _fdt;
  290. } F_DATE_TIME, *PF_DATE_TIME;
  291. #if defined(USE_EF_UT_TIME) || defined(TIMESTAMP)
  292. static ulg Utime2DosDateTime(uxtime)
  293. time_t uxtime;
  294. {
  295. F_DATE_TIME dosfiletime;
  296. struct tm *t;
  297. /* round up to even seconds */
  298. /* round up (down if "up" overflows) to even seconds */
  299. if (((ulg)uxtime) & 1)
  300. uxtime = (uxtime + 1 > uxtime) ? uxtime + 1 : uxtime - 1;
  301. t = localtime(&(uxtime));
  302. if (t == (struct tm *)NULL) {
  303. /* time conversion error; use current time instead, hoping
  304. that localtime() does not reject it as well! */
  305. time_t now = time(NULL);
  306. t = localtime(&now);
  307. }
  308. if (t->tm_year < 80) {
  309. dosfiletime._fdt.ft.twosecs = 0;
  310. dosfiletime._fdt.ft.minutes = 0;
  311. dosfiletime._fdt.ft.hours = 0;
  312. dosfiletime._fdt.fd.day = 1;
  313. dosfiletime._fdt.fd.month = 1;
  314. dosfiletime._fdt.fd.year = 0;
  315. } else {
  316. dosfiletime._fdt.ft.twosecs = t->tm_sec >> 1;
  317. dosfiletime._fdt.ft.minutes = t->tm_min;
  318. dosfiletime._fdt.ft.hours = t->tm_hour;
  319. dosfiletime._fdt.fd.day = t->tm_mday;
  320. dosfiletime._fdt.fd.month = t->tm_mon + 1;
  321. dosfiletime._fdt.fd.year = t->tm_year - 80;
  322. }
  323. return dosfiletime.timevalue;
  324. } /* end function Utime2DosDateTime() */
  325. #endif /* USE_EF_UT_TIME || TIMESTAMP */
  326. static int getOS2filetimes(__GPRO__ ulg *pM_dt, ulg *pA_dt, ulg *pC_dt)
  327. {
  328. #ifdef USE_EF_UT_TIME
  329. unsigned eb_izux_flg;
  330. iztimes z_utime;
  331. #endif
  332. /* Copy and/or convert time and date variables, if necessary; */
  333. /* return a flag indicating which time stamps are available. */
  334. #ifdef USE_EF_UT_TIME
  335. if (G.extra_field &&
  336. #ifdef IZ_CHECK_TZ
  337. G.tz_is_valid &&
  338. #endif
  339. ((eb_izux_flg = ef_scan_for_izux(G.extra_field,
  340. G.lrec.extra_field_length, 0, G.lrec.last_mod_dos_datetime,
  341. &z_utime, NULL)) & EB_UT_FL_MTIME))
  342. {
  343. TTrace((stderr, "getOS2filetimes: UT e.f. modif. time = %lu\n",
  344. z_utime.mtime));
  345. *pM_dt = Utime2DosDateTime(z_utime.mtime);
  346. if (eb_izux_flg & EB_UT_FL_ATIME) {
  347. TTrace((stderr, "getOS2filetimes: UT e.f. access time = %lu\n",
  348. z_utime.atime));
  349. *pA_dt = Utime2DosDateTime(z_utime.atime);
  350. }
  351. if (eb_izux_flg & EB_UT_FL_CTIME) {
  352. TTrace((stderr, "getOS2filetimes: UT e.f. creation time = %lu\n",
  353. z_utime.ctime));
  354. *pC_dt = Utime2DosDateTime(z_utime.ctime);
  355. } else {
  356. /* no creation time value supplied, set it to modification time */
  357. *pC_dt = *pM_dt;
  358. eb_izux_flg |= EB_UT_FL_CTIME;
  359. }
  360. return (int)eb_izux_flg;
  361. }
  362. #endif /* USE_EF_UT_TIME */
  363. *pC_dt = *pM_dt = G.lrec.last_mod_dos_datetime;
  364. TTrace((stderr, "\ngetOS2filetimes: DOS dir modific./creation time = %lu\n",
  365. *pM_dt));
  366. return (EB_UT_FL_MTIME | EB_UT_FL_CTIME);
  367. }
  368. static void SetPathAttrTimes(__GPRO__ int flags, int dir)
  369. {
  370. HFILE hFile;
  371. #ifdef __32BIT__
  372. ULONG nAction;
  373. #else
  374. USHORT nAction;
  375. #endif
  376. FILESTATUS fs;
  377. USHORT nLength;
  378. char szName[CCHMAXPATH];
  379. ulg Mod_dt, Acc_dt, Cre_dt;
  380. int gotTimes;
  381. strcpy(szName, G.filename);
  382. nLength = strlen(szName);
  383. if (szName[nLength - 1] == '/')
  384. szName[nLength - 1] = 0;
  385. if (dir)
  386. {
  387. if ( DosQueryPathInfo(szName, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)) )
  388. return;
  389. }
  390. else
  391. {
  392. /* for regular files, open them and operate on the file handle, to
  393. work around certain network operating system bugs ... */
  394. if ( DosOpen(szName, &hFile, &nAction, 0, 0,
  395. OPEN_ACTION_OPEN_IF_EXISTS | OPEN_ACTION_CREATE_IF_NEW,
  396. OPEN_SHARE_DENYREADWRITE | OPEN_ACCESS_READWRITE, 0) )
  397. return;
  398. if ( DosQueryFileInfo(hFile, FIL_STANDARD, (PBYTE) &fs, sizeof(fs)) )
  399. return;
  400. }
  401. if (uO.D_flag <= (dir ? 1 : 0)) {
  402. /* set date/time stamps */
  403. gotTimes = getOS2filetimes(__G__ &Mod_dt, &Acc_dt, &Cre_dt);
  404. if (gotTimes & EB_UT_FL_MTIME) {
  405. fs.fdateLastWrite = ((F_DATE_TIME *)&Mod_dt)->_fdt.fd;
  406. fs.ftimeLastWrite = ((F_DATE_TIME *)&Mod_dt)->_fdt.ft;
  407. }
  408. if (gotTimes & EB_UT_FL_ATIME) {
  409. fs.fdateLastAccess = ((F_DATE_TIME *)&Acc_dt)->_fdt.fd;
  410. fs.ftimeLastAccess = ((F_DATE_TIME *)&Acc_dt)->_fdt.ft;
  411. }
  412. if (gotTimes & EB_UT_FL_CTIME) {
  413. fs.fdateCreation = ((F_DATE_TIME *)&Cre_dt)->_fdt.fd;
  414. fs.ftimeCreation = ((F_DATE_TIME *)&Cre_dt)->_fdt.ft;
  415. }
  416. }
  417. if ( flags != -1 )
  418. fs.attrFile = flags; /* hidden, system, archive, read-only */
  419. if (dir)
  420. {
  421. DosSetPathInfo(szName, FIL_STANDARD, (PBYTE) &fs, sizeof(fs), 0);
  422. }
  423. else
  424. {
  425. DosSetFileInfo(hFile, FIL_STANDARD, (PBYTE) &fs, sizeof(fs));
  426. DosClose(hFile);
  427. }
  428. }
  429. typedef struct
  430. {
  431. ULONG cbList; /* length of value + 22 */
  432. #ifdef __32BIT__
  433. ULONG oNext;
  434. #endif
  435. BYTE fEA; /* 0 */
  436. BYTE cbName; /* length of ".LONGNAME" = 9 */
  437. USHORT cbValue; /* length of value + 4 */
  438. BYTE szName[10]; /* ".LONGNAME" */
  439. USHORT eaType; /* 0xFFFD for length-preceded ASCII */
  440. USHORT eaSize; /* length of value */
  441. BYTE szValue[CCHMAXPATH];
  442. }
  443. FEALST;
  444. static int SetEAs(__GPRO__ const char *path, void *ef_block)
  445. { /* returns almost-PK errors */
  446. EFHEADER *pEAblock = (PEFHEADER) ef_block;
  447. #ifdef __32BIT__
  448. EAOP2 eaop;
  449. PFEA2LIST pFEA2list;
  450. #else
  451. EAOP eaop;
  452. PFEALIST pFEAlist;
  453. PFEA pFEA;
  454. PFEA2LIST pFEA2list;
  455. PFEA2 pFEA2;
  456. ULONG nLength2;
  457. #endif
  458. USHORT nLength;
  459. char szName[CCHMAXPATH];
  460. int error;
  461. if ( ef_block == NULL || pEAblock -> nID != EF_OS2 )
  462. return PK_OK; /* not an OS/2 extra field: assume OK */
  463. if ( pEAblock->nSize < 4 || (pEAblock->lSize > 0L && pEAblock->nSize <= 10) )
  464. return IZ_EF_TRUNC; /* no compressed data! */
  465. strcpy(szName, path);
  466. nLength = strlen(szName);
  467. if (szName[nLength - 1] == '/')
  468. szName[nLength - 1] = 0;
  469. if ( (pFEA2list = (PFEA2LIST) malloc((size_t) pEAblock -> lSize)) == NULL )
  470. return PK_MEM4;
  471. if ( (error = memextract(__G__ (uch *)pFEA2list, pEAblock->lSize,
  472. (uch *)(pEAblock+1), (ulg)(pEAblock->nSize - 4))) != PK_OK )
  473. {
  474. free(pFEA2list);
  475. return error;
  476. }
  477. #ifdef __32BIT__
  478. eaop.fpGEA2List = NULL;
  479. eaop.fpFEA2List = pFEA2list;
  480. #else
  481. pFEAlist = (PVOID) pFEA2list;
  482. pFEA2 = pFEA2list -> list;
  483. pFEA = pFEAlist -> list;
  484. do
  485. {
  486. nLength2 = pFEA2 -> oNextEntryOffset;
  487. nLength = sizeof(FEA) + pFEA2 -> cbName + 1 + pFEA2 -> cbValue;
  488. memcpy(pFEA, (PCH) pFEA2 + sizeof(pFEA2 -> oNextEntryOffset), nLength);
  489. pFEA2 = (PFEA2) ((PCH) pFEA2 + nLength2);
  490. pFEA = (PFEA) ((PCH) pFEA + nLength);
  491. }
  492. while ( nLength2 != 0 );
  493. pFEAlist -> cbList = (PCH) pFEA - (PCH) pFEAlist;
  494. eaop.fpGEAList = NULL;
  495. eaop.fpFEAList = pFEAlist;
  496. #endif
  497. eaop.oError = 0;
  498. DosSetPathInfo(szName, FIL_QUERYEASIZE, (PBYTE) &eaop, sizeof(eaop), 0);
  499. if (!uO.tflag && QCOND2)
  500. Info(slide, 0, ((char *)slide, " (%ld bytes EAs)", pFEA2list -> cbList));
  501. free(pFEA2list);
  502. return PK_COOL;
  503. }
  504. static int SetACL(__GPRO__ const char *path, void *ef_block)
  505. { /* returns almost-PK errors */
  506. EFHEADER *pACLblock = (PEFHEADER) ef_block;
  507. char *szACL;
  508. int error;
  509. if ( ef_block == NULL || pACLblock -> nID != EF_ACL )
  510. return PK_OK; /* not an OS/2 extra field: assume OK */
  511. if (pACLblock->nSize < 4 || (pACLblock->lSize > 0L && pACLblock->nSize <= 10))
  512. return IZ_EF_TRUNC; /* no compressed data! */
  513. if ( (szACL = malloc((size_t) pACLblock -> lSize)) == NULL )
  514. return PK_MEM4;
  515. if ( (error = memextract(__G__ (uch *)szACL, pACLblock->lSize,
  516. (uch *)(pACLblock+1), (ulg)(pACLblock->nSize - 4))) != PK_OK )
  517. {
  518. free(szACL);
  519. return error;
  520. }
  521. if (acl_set(NULL, path, szACL) == 0)
  522. if (!uO.tflag && QCOND2)
  523. Info(slide, 0, ((char *)slide, " (%ld bytes ACL)", strlen(szACL)));
  524. free(szACL);
  525. return PK_COOL;
  526. }
  527. #ifdef SFX
  528. char *GetLoadPath(__GPRO)
  529. {
  530. #ifdef __32BIT__ /* generic for 32-bit API */
  531. PTIB pptib;
  532. PPIB pppib;
  533. char *szPath;
  534. DosGetInfoBlocks(&pptib, &pppib);
  535. szPath = pppib -> pib_pchenv;
  536. #else /* 16-bit, note: requires large data model */
  537. SEL selEnv;
  538. USHORT offCmd;
  539. char *szPath;
  540. DosGetEnv(&selEnv, &offCmd);
  541. szPath = MAKEP(selEnv, 0);
  542. #endif
  543. while (*szPath) /* find end of process environment */
  544. szPath = strchr(szPath, 0) + 1;
  545. return szPath + 1; /* .exe file name follows environment */
  546. } /* end function GetLoadPath() */
  547. #else /* !SFX */
  548. DIR *opendir(__GPRO__ const char *name)
  549. {
  550. struct stat statb;
  551. DIR *dirp;
  552. char c;
  553. char *s;
  554. struct _dircontents *dp;
  555. char nbuf[MAXPATHLEN + 1];
  556. int len;
  557. strcpy(nbuf, name);
  558. if ((len = strlen(nbuf)) == 0)
  559. return NULL;
  560. if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len > 1) )
  561. {
  562. nbuf[len - 1] = 0;
  563. --len;
  564. if ( nbuf[len - 1] == ':' )
  565. {
  566. strcpy(nbuf+len, "\\.");
  567. len += 2;
  568. }
  569. }
  570. else
  571. if ( nbuf[len - 1] == ':' )
  572. {
  573. strcpy(nbuf+len, ".");
  574. ++len;
  575. }
  576. /* GRR: Borland and Watcom C return non-zero on wildcards... < 0 ? */
  577. if (stat(nbuf, &statb) < 0 || (statb.st_mode & S_IFMT) != S_IFDIR)
  578. {
  579. Trace((stderr, "opendir: stat(%s) returns negative or not directory\n",
  580. FnFilter1(nbuf)));
  581. return NULL;
  582. }
  583. if ( (dirp = malloc(sizeof(DIR))) == NULL )
  584. return NULL;
  585. if ( nbuf[len - 1] == '.' && (len == 1 || nbuf[len - 2] != '.') )
  586. strcpy(nbuf+len-1, "*");
  587. else
  588. if ( ((c = nbuf[len - 1]) == '\\' || c == '/') && (len == 1) )
  589. strcpy(nbuf+len, "*");
  590. else
  591. strcpy(nbuf+len, "\\*");
  592. /* len is no longer correct (but no longer needed) */
  593. Trace((stderr, "opendir: nbuf = [%s]\n", FnFilter1(nbuf)));
  594. dirp -> dd_loc = 0;
  595. dirp -> dd_contents = dirp -> dd_cp = NULL;
  596. if ((s = getdirent(__G__ nbuf)) == NULL)
  597. return dirp;
  598. do
  599. {
  600. if (((dp = malloc(sizeof(struct _dircontents))) == NULL) ||
  601. ((dp -> _d_entry = malloc(strlen(s) + 1)) == NULL) )
  602. {
  603. if (dp)
  604. free(dp);
  605. free_dircontents(dirp -> dd_contents);
  606. return NULL;
  607. }
  608. if (dirp -> dd_contents)
  609. {
  610. dirp -> dd_cp -> _d_next = dp;
  611. dirp -> dd_cp = dirp -> dd_cp -> _d_next;
  612. }
  613. else
  614. dirp -> dd_contents = dirp -> dd_cp = dp;
  615. strcpy(dp -> _d_entry, s);
  616. dp -> _d_next = NULL;
  617. dp -> _d_size = G.os2.find.cbFile;
  618. dp -> _d_mode = G.os2.find.attrFile;
  619. dp -> _d_time = *(unsigned *) &(G.os2.find.ftimeLastWrite);
  620. dp -> _d_date = *(unsigned *) &(G.os2.find.fdateLastWrite);
  621. }
  622. while ((s = getdirent(__G__ NULL)) != NULL);
  623. dirp -> dd_cp = dirp -> dd_contents;
  624. return dirp;
  625. }
  626. void closedir(DIR * dirp)
  627. {
  628. free_dircontents(dirp -> dd_contents);
  629. free(dirp);
  630. }
  631. struct direct *readdir(__GPRO__ DIR * dirp)
  632. {
  633. /* moved to os2data.h so it can be global */
  634. /* static struct direct dp; */
  635. if (dirp -> dd_cp == NULL)
  636. return NULL;
  637. G.os2.dp.d_namlen = G.os2.dp.d_reclen =
  638. strlen(strcpy(G.os2.dp.d_name, dirp -> dd_cp -> _d_entry));
  639. G.os2.dp.d_ino = 0;
  640. G.os2.dp.d_size = dirp -> dd_cp -> _d_size;
  641. G.os2.dp.d_mode = dirp -> dd_cp -> _d_mode;
  642. G.os2.dp.d_time = dirp -> dd_cp -> _d_time;
  643. G.os2.dp.d_date = dirp -> dd_cp -> _d_date;
  644. dirp -> dd_cp = dirp -> dd_cp -> _d_next;
  645. dirp -> dd_loc++;
  646. return &G.os2.dp;
  647. }
  648. #if 0 /* not used in unzip; retained for possibly future use */
  649. void seekdir(DIR * dirp, long off)
  650. {
  651. long i = off;
  652. struct _dircontents *dp;
  653. if (off >= 0)
  654. {
  655. for (dp = dirp -> dd_contents; --i >= 0 && dp; dp = dp -> _d_next);
  656. dirp -> dd_loc = off - (i + 1);
  657. dirp -> dd_cp = dp;
  658. }
  659. }
  660. long telldir(DIR * dirp)
  661. {
  662. return dirp -> dd_loc;
  663. }
  664. #endif /* 0 */
  665. static void free_dircontents(struct _dircontents * dp)
  666. {
  667. struct _dircontents *odp;
  668. while (dp)
  669. {
  670. if (dp -> _d_entry)
  671. free(dp -> _d_entry);
  672. dp = (odp = dp) -> _d_next;
  673. free(odp);
  674. }
  675. }
  676. static char *getdirent(__GPRO__ ZCONST char *dir)
  677. {
  678. int done;
  679. /* moved to os2data.h so it can be global */
  680. /* static int lower; */
  681. if (dir != NULL)
  682. { /* get first entry */
  683. G.os2.hdir = HDIR_SYSTEM;
  684. G.os2.count = 1;
  685. done = DosFindFirst((PSZ) dir, &G.os2.hdir, attributes,
  686. &G.os2.find, sizeof(G.os2.find), &G.os2.count);
  687. G.os2.lower = IsFileSystemFAT(__G__ dir);
  688. }
  689. else /* get next entry */
  690. done = DosFindNext(G.os2.hdir,
  691. &G.os2.find, sizeof(G.os2.find), &G.os2.count);
  692. if (done == 0)
  693. {
  694. if ( G.os2.lower )
  695. StringLower(G.os2.find.achName);
  696. return G.os2.find.achName;
  697. }
  698. else
  699. {
  700. DosFindClose(G.os2.hdir);
  701. return NULL;
  702. }
  703. }
  704. int IsFileSystemFAT(__GPRO__ ZCONST char *dir) /* FAT / HPFS detection */
  705. {
  706. /* moved to os2data.h so they can be global */
  707. /* static USHORT nLastDrive=(USHORT)(-1), nResult; */
  708. ULONG lMap;
  709. BYTE bData[64];
  710. char bName[3];
  711. #ifdef __32BIT__
  712. ULONG nDrive, cbData;
  713. PFSQBUFFER2 pData = (PFSQBUFFER2) bData;
  714. #else
  715. USHORT nDrive, cbData;
  716. PFSQBUFFER pData = (PFSQBUFFER) bData;
  717. #endif
  718. /* We separate FAT and HPFS+other file systems here.
  719. at the moment I consider other systems to be similar to HPFS,
  720. i.e. support long file names and case sensitive */
  721. if ( isalpha((uch)dir[0]) && (dir[1] == ':') )
  722. nDrive = toupper(dir[0]) - '@';
  723. else
  724. DosQueryCurrentDisk(&nDrive, &lMap);
  725. if ( nDrive == G.os2.nLastDrive )
  726. return G.os2.nResult;
  727. bName[0] = (char) (nDrive + '@');
  728. bName[1] = ':';
  729. bName[2] = 0;
  730. G.os2.nLastDrive = nDrive;
  731. cbData = sizeof(bData);
  732. if ( !DosQueryFSAttach(bName, 0, FSAIL_QUERYNAME, (PVOID) pData, &cbData) )
  733. G.os2.nResult = !strcmp((char *) (pData -> szFSDName) + pData -> cbName,
  734. "FAT");
  735. else
  736. G.os2.nResult = FALSE;
  737. /* End of this ugly code */
  738. return G.os2.nResult;
  739. } /* end function IsFileSystemFAT() */
  740. /************************/
  741. /* Function do_wild() */
  742. /************************/
  743. char *do_wild(__G__ wildspec)
  744. __GDEF
  745. ZCONST char *wildspec; /* only used first time on a given dir */
  746. {
  747. /* moved to os2data.h so they can be global */
  748. #if 0
  749. static DIR *wild_dir = NULL;
  750. static ZCONST char *wildname;
  751. static char *dirname, matchname[FILNAMSIZ];
  752. static int notfirstcall=FALSE, have_dirname, dirnamelen;
  753. #endif
  754. char *fnamestart;
  755. struct direct *file;
  756. /* Even when we're just returning wildspec, we *always* do so in
  757. * matchname[]--calling routine is allowed to append four characters
  758. * to the returned string, and wildspec may be a pointer to argv[].
  759. */
  760. if (!G.os2.notfirstcall) { /* first call: must initialize everything */
  761. G.os2.notfirstcall = TRUE;
  762. if (!iswild(wildspec)) {
  763. strncpy(G.os2.matchname, wildspec, FILNAMSIZ);
  764. G.os2.matchname[FILNAMSIZ-1] = '\0';
  765. G.os2.have_dirname = FALSE;
  766. G.os2.wild_dir = NULL;
  767. return G.os2.matchname;
  768. }
  769. /* break the wildspec into a directory part and a wildcard filename */
  770. if ((G.os2.wildname = (ZCONST char *)strrchr(wildspec, '/')) == NULL &&
  771. (G.os2.wildname = (ZCONST char *)strrchr(wildspec, ':')) == NULL) {
  772. G.os2.dirname = ".";
  773. G.os2.dirnamelen = 1;
  774. G.os2.have_dirname = FALSE;
  775. G.os2.wildname = wildspec;
  776. } else {
  777. ++G.os2.wildname; /* point at character after '/' or ':' */
  778. G.os2.dirnamelen = G.os2.wildname - wildspec;
  779. if ((G.os2.dirname = (char *)malloc(G.os2.dirnamelen+1)) == NULL) {
  780. Info(slide, 1, ((char *)slide,
  781. LoadFarString(CantAllocateWildcard)));
  782. strncpy(G.os2.matchname, wildspec, FILNAMSIZ);
  783. G.os2.matchname[FILNAMSIZ-1] = '\0';
  784. return G.os2.matchname; /* but maybe filespec was not a wildcard */
  785. }
  786. strncpy(G.os2.dirname, wildspec, G.os2.dirnamelen);
  787. G.os2.dirname[G.os2.dirnamelen] = '\0'; /* terminate for strcpy below */
  788. G.os2.have_dirname = TRUE;
  789. }
  790. Trace((stderr, "do_wild: dirname = [%s]\n",
  791. FnFilter1(G.os2.dirname)));
  792. if ((G.os2.wild_dir = opendir(__G__ G.os2.dirname)) != NULL) {
  793. if (G.os2.have_dirname) {
  794. strcpy(G.os2.matchname, G.os2.dirname);
  795. fnamestart = G.os2.matchname + G.os2.dirnamelen;
  796. } else
  797. fnamestart = G.os2.matchname;
  798. while ((file = readdir(__G__ G.os2.wild_dir)) != NULL) {
  799. Trace((stderr, "do_wild: readdir returns %s\n",
  800. FnFilter1(file->d_name)));
  801. strcpy(fnamestart, file->d_name);
  802. if (strrchr(fnamestart, '.') == (char *)NULL)
  803. strcat(fnamestart, ".");
  804. if (match(fnamestart, G.os2.wildname, 1 WISEP) &&
  805. /* 1 == ignore case */
  806. /* skip "." and ".." directory entries */
  807. strcmp(fnamestart, ".") && strcmp(fnamestart, "..")) {
  808. Trace((stderr, "do_wild: match() succeeds\n"));
  809. /* remove trailing dot */
  810. fnamestart += strlen(fnamestart) - 1;
  811. if (*fnamestart == '.')
  812. *fnamestart = '\0';
  813. return G.os2.matchname;
  814. }
  815. }
  816. /* if we get to here directory is exhausted, so close it */
  817. closedir(G.os2.wild_dir);
  818. G.os2.wild_dir = NULL;
  819. }
  820. #ifdef DEBUG
  821. else {
  822. Trace((stderr, "do_wild: opendir(%s) returns NULL\n",
  823. FnFilter1(G.os2.dirname)));
  824. }
  825. #endif /* DEBUG */
  826. /* return the raw wildspec in case that works (e.g., directory not
  827. * searchable, but filespec was not wild and file is readable) */
  828. strncpy(G.os2.matchname, wildspec, FILNAMSIZ);
  829. G.os2.matchname[FILNAMSIZ-1] = '\0';
  830. return G.os2.matchname;
  831. }
  832. /* last time through, might have failed opendir but returned raw wildspec */
  833. if (G.os2.wild_dir == NULL) {
  834. G.os2.notfirstcall = FALSE; /* nothing left to try--reset */
  835. if (G.os2.have_dirname)
  836. free(G.os2.dirname);
  837. return (char *)NULL;
  838. }
  839. /* If we've gotten this far, we've read and matched at least one entry
  840. * successfully (in a previous call), so dirname has been copied into
  841. * matchname already.
  842. */
  843. if (G.os2.have_dirname) {
  844. /* strcpy(G.os2.matchname, G.os2.dirname); */
  845. fnamestart = G.os2.matchname + G.os2.dirnamelen;
  846. } else
  847. fnamestart = G.os2.matchname;
  848. while ((file = readdir(__G__ G.os2.wild_dir)) != NULL) {
  849. Trace((stderr, "do_wild: readdir returns %s\n",
  850. FnFilter1(file->d_name)));
  851. strcpy(fnamestart, file->d_name);
  852. if (strrchr(fnamestart, '.') == (char *)NULL)
  853. strcat(fnamestart, ".");
  854. if (match(fnamestart, G.os2.wildname, 1 WISEP)) { /* 1==ignore case */
  855. Trace((stderr, "do_wild: match() succeeds\n"));
  856. /* remove trailing dot */
  857. fnamestart += strlen(fnamestart) - 1;
  858. if (*fnamestart == '.')
  859. *fnamestart = '\0';
  860. return G.os2.matchname;
  861. }
  862. }
  863. closedir(G.os2.wild_dir); /* have read at least one entry; nothing left */
  864. G.os2.wild_dir = NULL;
  865. G.os2.notfirstcall = FALSE; /* reset for new wildspec */
  866. if (G.os2.have_dirname)
  867. free(G.os2.dirname);
  868. return (char *)NULL;
  869. } /* end function do_wild() */
  870. #endif /* !SFX */
  871. /* scan extra fields for something we happen to know */
  872. static int EvalExtraFields(__GPRO__ const char *path,
  873. void *extra_field, unsigned ef_len)
  874. {
  875. char *ef_ptr = extra_field;
  876. PEFHEADER pEFblock;
  877. int rc = PK_OK;
  878. while (ef_len >= sizeof(EFHEADER))
  879. {
  880. pEFblock = (PEFHEADER) ef_ptr;
  881. if (pEFblock -> nSize > (ef_len - EB_HEADSIZE))
  882. return PK_ERR; /* claimed EFblock length exceeds EF size! */
  883. switch (pEFblock -> nID)
  884. {
  885. case EF_OS2:
  886. rc = SetEAs(__G__ path, ef_ptr);
  887. break;
  888. case EF_ACL:
  889. rc = (uO.X_flag) ? SetACL(__G__ path, ef_ptr) : PK_OK;
  890. break;
  891. #if 0
  892. case EF_IZUNIX:
  893. case EF_PKUNIX:
  894. /* handled elsewhere */
  895. break;
  896. #endif
  897. default:
  898. TTrace((stderr,"EvalExtraFields: unknown extra field block, ID=%d\n",
  899. pEFblock -> nID));
  900. break;
  901. }
  902. ef_ptr += (pEFblock -> nSize + EB_HEADSIZE);
  903. ef_len -= (pEFblock -> nSize + EB_HEADSIZE);
  904. if (rc != PK_OK)
  905. break;
  906. }
  907. return rc;
  908. }
  909. /************************/
  910. /* Function mapattr() */
  911. /************************/
  912. int mapattr(__G)
  913. __GDEF
  914. {
  915. /* set archive bit (file is not backed up): */
  916. G.pInfo->file_attr = (unsigned)(G.crec.external_file_attributes | 32) & 0xff;
  917. return 0;
  918. }
  919. /************************/
  920. /* Function mapname() */
  921. /************************/
  922. /*
  923. * There are presently two possibilities in OS/2: the output filesystem is
  924. * FAT, or it is HPFS. If the former, we need to map to FAT, obviously, but
  925. * we *also* must map to HPFS and store that version of the name in extended
  926. * attributes. Either way, we need to map to HPFS, so the main mapname
  927. * routine does that. In the case that the output file system is FAT, an
  928. * extra filename-mapping routine is called in checkdir(). While it should
  929. * be possible to determine the filesystem immediately upon entry to mapname(),
  930. * it is conceivable that the DOS APPEND utility could be added to OS/2 some-
  931. * day, allowing a FAT directory to be APPENDed to an HPFS drive/path. There-
  932. * fore we simply check the filesystem at each path component.
  933. *
  934. * Note that when alternative IFSes become available/popular, everything will
  935. * become immensely more complicated. For example, a Minix filesystem would
  936. * have limited filename lengths like FAT but no extended attributes in which
  937. * to store the longer versions of the names. A BSD Unix filesystem would
  938. * support paths of length 1024 bytes or more, but it is not clear that FAT
  939. * EAs would allow such long .LONGNAME fields or that OS/2 would properly
  940. * restore such fields when moving files from FAT to the new filesystem.
  941. *
  942. * GRR: some or all of the following chars should be checked in either
  943. * mapname (HPFS) or map2fat (FAT), depending: ,=^+'"[]<>|\t&
  944. */
  945. int mapname(__G__ renamed)
  946. __GDEF
  947. int renamed;
  948. /*
  949. * returns:
  950. * MPN_OK - no problem detected
  951. * MPN_INF_TRUNC - caution (truncated filename)
  952. * MPN_INF_SKIP - info "skip entry" (dir doesn't exist)
  953. * MPN_ERR_SKIP - error -> skip entry
  954. * MPN_ERR_TOOLONG - error -> path is too long
  955. * MPN_NOMEM - error (memory allocation failed) -> skip entry
  956. * [also MPN_VOL_LABEL, MPN_CREATED_DIR]
  957. */
  958. {
  959. char pathcomp[FILNAMSIZ]; /* path-component buffer */
  960. char *pp, *cp=(char *)NULL; /* character pointers */
  961. char *lastsemi=(char *)NULL; /* pointer to last semi-colon in pathcomp */
  962. #ifdef ACORN_FTYPE_NFS
  963. char *lastcomma=(char *)NULL; /* pointer to last comma in pathcomp */
  964. RO_extra_block *ef_spark; /* pointer Acorn FTYPE ef block */
  965. #endif
  966. int killed_ddot = FALSE; /* is set when skipping "../" pathcomp */
  967. int error = MPN_OK;
  968. register unsigned workch; /* hold the character being tested */
  969. /*---------------------------------------------------------------------------
  970. Initialize various pointers and counters and stuff.
  971. ---------------------------------------------------------------------------*/
  972. /* can create path as long as not just freshening, or if user told us */
  973. G.create_dirs = (!uO.fflag || renamed);
  974. G.os2.created_dir = FALSE; /* not yet */
  975. G.os2.renamed_fullpath = FALSE;
  976. G.os2.fnlen = strlen(G.filename);
  977. /* GRR: for VMS, convert to internal format now or later? or never? */
  978. if (renamed) {
  979. cp = G.filename - 1; /* point to beginning of renamed name... */
  980. while (*++cp)
  981. if (*cp == '\\') /* convert backslashes to forward */
  982. *cp = '/';
  983. cp = G.filename;
  984. /* use temporary rootpath if user gave full pathname */
  985. if (G.filename[0] == '/') {
  986. G.os2.renamed_fullpath = TRUE;
  987. pathcomp[0] = '/'; /* copy the '/' and terminate */
  988. pathcomp[1] = '\0';
  989. ++cp;
  990. } else if (isalpha((uch)G.filename[0]) && G.filename[1] == ':') {
  991. G.os2.renamed_fullpath = TRUE;
  992. pp = pathcomp;
  993. *pp++ = *cp++; /* copy the "d:" (+ '/', possibly) */
  994. *pp++ = *cp++;
  995. if (*cp == '/')
  996. *pp++ = *cp++; /* otherwise add "./"? */
  997. *pp = '\0';
  998. }
  999. }
  1000. /* pathcomp is ignored unless renamed_fullpath is TRUE: */
  1001. if ((error = checkdir(__G__ pathcomp, INIT)) != 0) /* init path buffer */
  1002. return error; /* ...unless no mem or vol label on hard disk */
  1003. *pathcomp = '\0'; /* initialize translation buffer */
  1004. pp = pathcomp; /* point to translation buffer */
  1005. if (!renamed) { /* cp already set if renamed */
  1006. if (uO.jflag) /* junking directories */
  1007. /* GRR: watch out for VMS version... */
  1008. cp = (char *)strrchr(G.filename, '/');
  1009. if (cp == (char *)NULL) /* no '/' or not junking dirs */
  1010. cp = G.filename; /* point to internal zipfile-member pathname */
  1011. else
  1012. ++cp; /* point to start of last component of path */
  1013. }
  1014. /*---------------------------------------------------------------------------
  1015. Begin main loop through characters in filename.
  1016. ---------------------------------------------------------------------------*/
  1017. while ((workch = (uch)*cp++) != 0) {
  1018. switch (workch) {
  1019. case '/': /* can assume -j flag not given */
  1020. *pp = '\0';
  1021. if (strcmp(pathcomp, ".") == 0) {
  1022. /* don't bother appending "./" to the path */
  1023. *pathcomp = '\0';
  1024. } else if (!uO.ddotflag && strcmp(pathcomp, "..") == 0) {
  1025. /* "../" dir traversal detected, skip over it */
  1026. *pathcomp = '\0';
  1027. killed_ddot = TRUE; /* set "show message" flag */
  1028. }
  1029. /* when path component is not empty, append it now */
  1030. if (*pathcomp != '\0' &&
  1031. ((error = checkdir(__G__ pathcomp, APPEND_DIR))
  1032. & MPN_MASK) > MPN_INF_TRUNC)
  1033. return error;
  1034. pp = pathcomp; /* reset conversion buffer for next piece */
  1035. lastsemi = (char *)NULL; /* leave direct. semi-colons alone */
  1036. break;
  1037. case ':': /* drive never stored, so no colon allowed */
  1038. case '\\': /* "non-dos" FSs may allow '\\' as normal */
  1039. *pp++ = '_'; /* character in filenames */
  1040. break; /* -> map invalid chars to underscore */
  1041. case ';': /* start of VMS version? */
  1042. lastsemi = pp; /* remove VMS version later... */
  1043. *pp++ = ';'; /* but keep semicolon for now */
  1044. break;
  1045. #ifdef ACORN_FTYPE_NFS
  1046. case ',': /* NFS filetype extension */
  1047. lastcomma = pp;
  1048. *pp++ = ','; /* keep for now; may need to remove */
  1049. break; /* later, if requested */
  1050. #endif
  1051. case ' ': /* keep spaces unless specifically */
  1052. if (uO.sflag) /* requested to change to underscore */
  1053. *pp++ = '_';
  1054. else
  1055. *pp++ = ' ';
  1056. break;
  1057. default:
  1058. /* allow ASCII 255 and European characters in filenames: */
  1059. if (isprint(workch) || workch >= 127)
  1060. *pp++ = (char)workch;
  1061. } /* end switch */
  1062. } /* end while loop */
  1063. /* Show warning when stripping insecure "parent dir" path components */
  1064. if (killed_ddot && QCOND2) {
  1065. Info(slide, 0, ((char *)slide, LoadFarString(WarnDirTraversSkip),
  1066. FnFilter1(G.filename)));
  1067. if (!(error & ~MPN_MASK))
  1068. error = (error & MPN_MASK) | PK_WARN;
  1069. }
  1070. /*---------------------------------------------------------------------------
  1071. Report if directory was created (and no file to create: filename ended
  1072. in '/'), check name to be sure it exists, and combine path and name be-
  1073. fore exiting.
  1074. ---------------------------------------------------------------------------*/
  1075. if (G.filename[G.os2.fnlen-1] == '/') {
  1076. checkdir(__G__ G.filename, GETPATH);
  1077. if (G.os2.created_dir) {
  1078. if (QCOND2)
  1079. Info(slide, 0, ((char *)slide, LoadFarString(Creating),
  1080. FnFilter1(G.filename)));
  1081. if (G.extra_field) { /* zipfile extra field has extended attribs */
  1082. int err = EvalExtraFields(__G__ G.filename, G.extra_field,
  1083. G.lrec.extra_field_length);
  1084. if (err == IZ_EF_TRUNC) {
  1085. if (uO.qflag)
  1086. Info(slide, 1, ((char *)slide, "%-22s ",
  1087. FnFilter1(G.filename)));
  1088. Info(slide, 1, ((char *)slide, LoadFarString(TruncEAs),
  1089. makeword(G.extra_field+2)-10, "\n"));
  1090. } else if (!uO.qflag)
  1091. (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
  1092. } else if (!uO.qflag)
  1093. (*G.message)((zvoid *)&G, (uch *)"\n", 1L, 0);
  1094. /* set date/time stamps */
  1095. SetPathAttrTimes(__G__ G.pInfo->file_attr & ~A_ARCHIVE, 1);
  1096. /* dir time already set */
  1097. return (error & ~MPN_MASK) | MPN_CREATED_DIR;
  1098. } else if (G.extra_field && IS_OVERWRT_ALL) {
  1099. /* overwrite EAs of existing directory since user requested it */
  1100. int err = EvalExtraFields(__G__ G.filename, G.extra_field,
  1101. G.lrec.extra_field_length);
  1102. if (err == IZ_EF_TRUNC) {
  1103. Info(slide, 0x421, ((char *)slide, "%-22s ",
  1104. FnFilter1(G.filename)));
  1105. Info(slide, 0x401, ((char *)slide, LoadFarString(TruncEAs),
  1106. makeword(G.extra_field+2)-10, "\n"));
  1107. }
  1108. /* set date/time stamps (dirs only have creation times) */
  1109. SetPathAttrTimes(__G__ G.pInfo->file_attr & ~A_ARCHIVE, 1);
  1110. }
  1111. /* dir existed already; don't look for data to extract */
  1112. return (error & ~MPN_MASK) | MPN_INF_SKIP;
  1113. }
  1114. *pp = '\0'; /* done with pathcomp: terminate it */
  1115. /* if not saving them, remove VMS version numbers (appended "###") */
  1116. if (!uO.V_flag && lastsemi) {
  1117. pp = lastsemi + 1; /* semi-colon was kept: expect #s after */
  1118. while (isdigit((uch)(*pp)))
  1119. ++pp;
  1120. if (*pp == '\0') /* only digits between ';' and end: nuke */
  1121. *lastsemi = '\0';
  1122. }
  1123. #ifdef ACORN_FTYPE_NFS
  1124. /* translate Acorn filetype information if asked to do so */
  1125. if (uO.acorn_nfs_ext &&
  1126. (ef_spark = (RO_extra_block *)
  1127. getRISCOSexfield(G.extra_field, G.lrec.extra_field_length))
  1128. != (RO_extra_block *)NULL)
  1129. {
  1130. /* file *must* have a RISC OS extra field */
  1131. long ft = (long)makelong(ef_spark->loadaddr);
  1132. /*32-bit*/
  1133. if (lastcomma) {
  1134. pp = lastcomma + 1;
  1135. while (isxdigit((uch)(*pp))) ++pp;
  1136. if (pp == lastcomma+4 && *pp == '\0') *lastcomma='\0'; /* nuke */
  1137. }
  1138. if ((ft & 1<<31)==0) ft=0x000FFD00;
  1139. sprintf(pathcomp+strlen(pathcomp), ",%03x", (int)(ft>>8) & 0xFFF);
  1140. }
  1141. #endif /* ACORN_FTYPE_NFS */
  1142. if (*pathcomp == '\0') {
  1143. Info(slide, 1, ((char *)slide, LoadFarString(ConversionFailed),
  1144. FnFilter1(G.filename)));
  1145. return (error & ~MPN_MASK) | MPN_ERR_SKIP;
  1146. }
  1147. checkdir(__G__ pathcomp, APPEND_NAME); /* returns 1 if truncated: care? */
  1148. checkdir(__G__ G.filename, GETPATH);
  1149. Trace((stderr, "mapname returns with filename = [%s] (error = %d)\n\n",
  1150. FnFilter1(G.filename), error));
  1151. if (G.pInfo->vollabel) { /* set the volume label now */
  1152. VOLUMELABEL FSInfoBuf;
  1153. /* GRR: "VOLUMELABEL" defined for IBM C and emx, but haven't checked MSC... */
  1154. strcpy(FSInfoBuf.szVolLabel, G.filename);
  1155. FSInfoBuf.cch = (BYTE)strlen(FSInfoBuf.szVolLabel);
  1156. if (!uO.qflag)
  1157. Info(slide, 0, ((char *)slide, LoadFarString(Labelling),
  1158. (char)(G.os2.nLabelDrive + 'a' - 1), FnFilter1(G.filename)));
  1159. if (DosSetFSInfo(G.os2.nLabelDrive, FSIL_VOLSER, (PBYTE)&FSInfoBuf,
  1160. sizeof(VOLUMELABEL)))
  1161. {
  1162. Info(slide, 1, ((char *)slide, LoadFarString(ErrSetVolLabel)));
  1163. return (error & ~MPN_MASK) | MPN_ERR_SKIP;
  1164. }
  1165. /* success: skip the "extraction" quietly */
  1166. return (error & ~MPN_MASK) | MPN_INF_SKIP;
  1167. }
  1168. return error;
  1169. } /* end function mapname() */
  1170. /***********************/
  1171. /* Function checkdir() */
  1172. /***********************/
  1173. int checkdir(__G__ pathcomp, flag)
  1174. __GDEF
  1175. char *pathcomp;
  1176. int flag;
  1177. /*
  1178. * returns:
  1179. * MPN_OK - no problem detected
  1180. * MPN_INF_TRUNC - (on APPEND_NAME) truncated filename
  1181. * MPN_INF_SKIP - path doesn't exist, not allowed to create
  1182. * MPN_ERR_SKIP - path doesn't exist, tried to create and failed; or path
  1183. * exists and is not a directory, but is supposed to be
  1184. * MPN_ERR_TOOLONG - path is too long
  1185. * MPN_NOMEM - can't allocate memory for filename buffers
  1186. */
  1187. {
  1188. /* moved to os2data.h so they can be global */
  1189. #if 0
  1190. static int rootlen = 0; /* length of rootpath */
  1191. static char *rootpath; /* user's "extract-to" directory */
  1192. static char *buildpathHPFS; /* full path (so far) to extracted file, */
  1193. static char *buildpathFAT; /* both HPFS/EA (main) and FAT versions */
  1194. static char *endHPFS; /* corresponding pointers to end of */
  1195. static char *endFAT; /* buildpath ('\0') */
  1196. #endif
  1197. # define FN_MASK 7
  1198. # define FUNCTION (flag & FN_MASK)
  1199. /*---------------------------------------------------------------------------
  1200. APPEND_DIR: append the path component to the path being built and check
  1201. for its existence. If doesn't exist and we are creating directories, do
  1202. so for this one; else signal success or error as appropriate.
  1203. ---------------------------------------------------------------------------*/
  1204. if (FUNCTION == APPEND_DIR) {
  1205. char *p = pathcomp;
  1206. int longdirEA, too_long=FALSE;
  1207. Trace((stderr, "appending dir segment [%s]\n", FnFilter1(pathcomp)));
  1208. while ((*G.os2.endHPFS = *p++) != '\0') /* copy to HPFS filename */
  1209. ++G.os2.endHPFS;
  1210. if (IsFileNameValid(G.os2.buildpathHPFS)) {
  1211. longdirEA = FALSE;
  1212. p = pathcomp;
  1213. while ((*G.os2.endFAT = *p++) != '\0') /* copy to FAT filename, too */
  1214. ++G.os2.endFAT;
  1215. } else {
  1216. longdirEA = TRUE;
  1217. /* GRR: check error return? */
  1218. map2fat(pathcomp, &G.os2.endFAT); /* map, put in FAT fn, update endFAT */
  1219. }
  1220. /* GRR: could do better check, see if overrunning buffer as we go:
  1221. * check endHPFS-G.os2.buildpathHPFS after each append, set warning variable
  1222. * if within 20 of FILNAMSIZ; then if var set, do careful check when
  1223. * appending. Clear variable when begin new path. */
  1224. /* next check: need to append '/', at least one-char name, '\0' */
  1225. if ((G.os2.endHPFS-G.os2.buildpathHPFS) > FILNAMSIZ-3)
  1226. too_long = TRUE; /* check if extracting dir? */
  1227. #ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
  1228. if (GetFileTime(G.os2.buildpathFAT) == -1 || stat(G.os2.buildpathFAT, &G.statbuf))
  1229. #else
  1230. if (stat(G.os2.buildpathFAT, &G.statbuf)) /* path doesn't exist */
  1231. #endif
  1232. {
  1233. if (!G.create_dirs) { /* told not to create (freshening) */
  1234. free(G.os2.buildpathHPFS);
  1235. free(G.os2.buildpathFAT);
  1236. /* path doesn't exist: nothing to do */
  1237. return MPN_INF_SKIP;
  1238. }
  1239. if (too_long) { /* GRR: should allow FAT extraction w/o EAs */
  1240. Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
  1241. FnFilter1(G.os2.buildpathHPFS)));
  1242. free(G.os2.buildpathHPFS);
  1243. free(G.os2.buildpathFAT);
  1244. /* no room for filenames: fatal */
  1245. return MPN_ERR_TOOLONG;
  1246. }
  1247. if (MKDIR(G.os2.buildpathFAT, 0777) == -1) { /* create the directory */
  1248. Info(slide, 1, ((char *)slide, LoadFarString(CantCreateDir),
  1249. FnFilter2(G.os2.buildpathFAT), FnFilter1(G.filename)));
  1250. free(G.os2.buildpathHPFS);
  1251. free(G.os2.buildpathFAT);
  1252. /* path didn't exist, tried to create, failed */
  1253. return MPN_ERR_SKIP;
  1254. }
  1255. G.os2.created_dir = TRUE;
  1256. /* only set EA if creating directory */
  1257. /* GRR: need trailing '/' before function call? */
  1258. if (longdirEA) {
  1259. #ifdef DEBUG
  1260. int e =
  1261. #endif
  1262. SetLongNameEA(G.os2.buildpathFAT, pathcomp);
  1263. Trace((stderr, "APPEND_DIR: SetLongNameEA() returns %d\n", e));
  1264. }
  1265. } else if (!S_ISDIR(G.statbuf.st_mode)) {
  1266. Info(slide, 1, ((char *)slide, LoadFarString(DirIsntDirectory),
  1267. FnFilter2(G.os2.buildpathFAT), FnFilter1(G.filename)));
  1268. free(G.os2.buildpathHPFS);
  1269. free(G.os2.buildpathFAT);
  1270. /* path existed but wasn't dir */
  1271. return MPN_ERR_SKIP;
  1272. }
  1273. if (too_long) {
  1274. Info(slide, 1, ((char *)slide, LoadFarString(PathTooLong),
  1275. FnFilter1(G.os2.buildpathHPFS)));
  1276. free(G.os2.buildpathHPFS);
  1277. free(G.os2.buildpathFAT);
  1278. /* no room for filenames: fatal */
  1279. return MPN_ERR_TOOLONG;
  1280. }
  1281. *G.os2.endHPFS++ = '/';
  1282. *G.os2.endFAT++ = '/';
  1283. *G.os2.endHPFS = *G.os2.endFAT = '\0';
  1284. Trace((stderr, "buildpathHPFS now = [%s]\n",
  1285. FnFilter1(G.os2.buildpathHPFS)));
  1286. Trace((stderr, "buildpathFAT now = [%s]\n",
  1287. FnFilter1(G.os2.buildpathFAT)));
  1288. return MPN_OK;
  1289. } /* end if (FUNCTION == APPEND_DIR) */
  1290. /*---------------------------------------------------------------------------
  1291. GETPATH: copy full FAT path to the string pointed at by pathcomp (want
  1292. filename to reflect name used on disk, not EAs; if full path is HPFS,
  1293. buildpathFAT and buildpathHPFS will be identical). Also free both paths.
  1294. ---------------------------------------------------------------------------*/
  1295. if (FUNCTION == GETPATH) {
  1296. Trace((stderr, "getting and freeing FAT path [%s]\n",
  1297. FnFilter1(G.os2.buildpathFAT)));
  1298. Trace((stderr, "freeing HPFS path [%s]\n",
  1299. FnFilter1(G.os2.buildpathHPFS)));
  1300. strcpy(pathcomp, G.os2.buildpathFAT);
  1301. free(G.os2.buildpathFAT);
  1302. free(G.os2.buildpathHPFS);
  1303. G.os2.buildpathHPFS = G.os2.buildpathFAT = G.os2.endHPFS = G.os2.endFAT = (char *)NULL;
  1304. return MPN_OK;
  1305. }
  1306. /*---------------------------------------------------------------------------
  1307. APPEND_NAME: assume the path component is the filename; append it and
  1308. return without checking for existence.
  1309. ---------------------------------------------------------------------------*/
  1310. if (FUNCTION == APPEND_NAME) {
  1311. char *p = pathcomp;
  1312. int error = MPN_OK;
  1313. Trace((stderr, "appending filename [%s]\n", FnFilter1(pathcomp)));
  1314. /* The buildpathHPFS buffer has been allocated large enough to
  1315. * hold the complete combined name, so there is no need to check
  1316. * for OS filename size limit overflow within the copy loop.
  1317. */
  1318. while ((*G.os2.endHPFS = *p++) != '\0') { /* copy to HPFS filename */
  1319. ++G.os2.endHPFS;
  1320. }
  1321. /* Now, check for OS filename size overflow. When detected, the
  1322. * mapped HPFS name is truncated and a warning message is shown.
  1323. */
  1324. if ((G.os2.endHPFS-G.os2.buildpathHPFS) >= FILNAMSIZ) {
  1325. G.os2.buildpathHPFS[FILNAMSIZ-1] = '\0';
  1326. Info(slide, 1, ((char *)slide, LoadFarString(PathTooLongTrunc),
  1327. FnFilter1(G.filename), FnFilter2(G.os2.buildpathHPFS)));
  1328. error = MPN_INF_TRUNC; /* filename truncated */
  1329. }
  1330. /* GRR: how can longnameEA ever be set before this point??? we don't want
  1331. * to save the original name to EAs if user renamed it, do we?
  1332. *
  1333. * if (!G.os2.longnameEA && ((G.os2.longnameEA = !IsFileNameValid(name)) != 0))
  1334. */
  1335. /* The buildpathFAT buffer has the same allocated size as the
  1336. * buildpathHPFS buffer, so there is no need for an overflow check
  1337. * within the following copy loop, either.
  1338. */
  1339. if (G.pInfo->vollabel || IsFileNameValid(G.os2.buildpathHPFS)) {
  1340. G.os2.longnameEA = FALSE;
  1341. /* copy to FAT filename, too */
  1342. p = pathcomp;
  1343. while ((*G.os2.endFAT = *p++) != '\0')
  1344. ++G.os2.endFAT;
  1345. } else {
  1346. G.os2.longnameEA = TRUE;
  1347. if ((G.os2.lastpathcomp = (char *)malloc(strlen(pathcomp)+1)) ==
  1348. (char *)NULL)
  1349. {
  1350. Info(slide, 1, ((char *)slide,
  1351. "checkdir warning: cannot save longname EA: out of memory\n"));
  1352. G.os2.longnameEA = FALSE;
  1353. /* can't set .LONGNAME extended attribute */
  1354. error = MPN_INF_TRUNC;
  1355. } else /* used and freed in close_outfile() */
  1356. strcpy(G.os2.lastpathcomp, pathcomp);
  1357. /* map, put in FAT fn, update endFAT */
  1358. map2fat(pathcomp, &G.os2.endFAT);
  1359. }
  1360. /* Check that the FAT path does not exceed the FILNAMSIZ limit, and
  1361. * truncate when neccessary.
  1362. * Note that truncation can only happen when the HPFS path (which is
  1363. * never shorter than the FAT path) has been already truncated.
  1364. * So, emission of the warning message and setting the error code
  1365. * has already happened.
  1366. */
  1367. if ((G.os2.endFAT-G.os2.buildpathFAT) >= FILNAMSIZ)
  1368. G.os2.buildpathFAT[FILNAMSIZ-1] = '\0';
  1369. Trace((stderr, "buildpathHPFS: %s\nbuildpathFAT: %s\n",
  1370. FnFilter1(G.os2.buildpathHPFS), FnFilter2(G.os2.buildpathFAT)));
  1371. return error; /* could check for existence, prompt for new name... */
  1372. } /* end if (FUNCTION == APPEND_NAME) */
  1373. /*---------------------------------------------------------------------------
  1374. INIT: allocate and initialize buffer space for the file currently being
  1375. extracted. If file was renamed with an absolute path, don't prepend the
  1376. extract-to path.
  1377. ---------------------------------------------------------------------------*/
  1378. if (FUNCTION == INIT) {
  1379. Trace((stderr, "initializing buildpathHPFS and buildpathFAT to "));
  1380. #ifdef ACORN_FTYPE_NFS
  1381. if ((G.os2.buildpathHPFS = (char *)malloc(G.os2.fnlen+G.os2.rootlen+
  1382. (uO.acorn_nfs_ext ? 5 : 1)))
  1383. #else
  1384. if ((G.os2.buildpathHPFS = (char *)malloc(G.os2.fnlen+G.os2.rootlen+1))
  1385. #endif
  1386. == (char *)NULL)
  1387. return MPN_NOMEM;
  1388. #ifdef ACORN_FTYPE_NFS
  1389. if ((G.os2.buildpathFAT = (char *)malloc(G.os2.fnlen+G.os2.rootlen+
  1390. (uO.acorn_nfs_ext ? 5 : 1)))
  1391. #else
  1392. if ((G.os2.buildpathFAT = (char *)malloc(G.os2.fnlen+G.os2.rootlen+1))
  1393. #endif
  1394. == (char *)NULL) {
  1395. free(G.os2.buildpathHPFS);
  1396. return MPN_NOMEM;
  1397. }
  1398. if (G.pInfo->vollabel) { /* use root or renamed path, but don't store */
  1399. /* GRR: for network drives, do strchr() and return IZ_VOL_LABEL if not [1] */
  1400. if (G.os2.renamed_fullpath && pathcomp[1] == ':')
  1401. *G.os2.buildpathHPFS = (char)ToLower(*pathcomp);
  1402. else if (!G.os2.renamed_fullpath && G.os2.rootlen > 1 && G.os2.rootpath[1] == ':')
  1403. *G.os2.buildpathHPFS = (char)ToLower(*G.os2.rootpath);
  1404. else {
  1405. ULONG lMap;
  1406. DosQueryCurrentDisk(&G.os2.nLabelDrive, &lMap);
  1407. *G.os2.buildpathHPFS = (char)(G.os2.nLabelDrive - 1 + 'a');
  1408. }
  1409. G.os2.nLabelDrive = *G.os2.buildpathHPFS - 'a' + 1; /* save for mapname() */
  1410. if (uO.volflag == 0 || *G.os2.buildpathHPFS < 'a' || /* no labels/bogus? */
  1411. (uO.volflag == 1 && !isfloppy(G.os2.nLabelDrive))) { /* -$: no fixed */
  1412. free(G.os2.buildpathHPFS);
  1413. free(G.os2.buildpathFAT);
  1414. return MPN_VOL_LABEL; /* skipping with message */
  1415. }
  1416. *G.os2.buildpathHPFS = '\0';
  1417. } else if (G.os2.renamed_fullpath) /* pathcomp = valid data */
  1418. strcpy(G.os2.buildpathHPFS, pathcomp);
  1419. else if (G.os2.rootlen > 0)
  1420. strcpy(G.os2.buildpathHPFS, G.os2.rootpath);
  1421. else
  1422. *G.os2.buildpathHPFS = '\0';
  1423. G.os2.endHPFS = G.os2.buildpathHPFS;
  1424. G.os2.endFAT = G.os2.buildpathFAT;
  1425. while ((*G.os2.endFAT = *G.os2.endHPFS) != '\0') {
  1426. ++G.os2.endFAT;
  1427. ++G.os2.endHPFS;
  1428. }
  1429. Trace((stderr, "[%s]\n", FnFilter1(G.os2.buildpathHPFS)));
  1430. return MPN_OK;
  1431. }
  1432. /*---------------------------------------------------------------------------
  1433. ROOT: if appropriate, store the path in rootpath and create it if neces-
  1434. sary; else assume it's a zipfile member and return. This path segment
  1435. gets used in extracting all members from every zipfile specified on the
  1436. command line. Note that under OS/2 and MS-DOS, if a candidate extract-to
  1437. directory specification includes a drive letter (leading "x:"), it is
  1438. treated just as if it had a trailing '/'--that is, one directory level
  1439. will be created if the path doesn't exist, unless this is otherwise pro-
  1440. hibited (e.g., freshening).
  1441. ---------------------------------------------------------------------------*/
  1442. #if (!defined(SFX) || defined(SFX_EXDIR))
  1443. if (FUNCTION == ROOT) {
  1444. Trace((stderr, "initializing root path to [%s]\n",
  1445. FnFilter1(pathcomp)));
  1446. if (pathcomp == (char *)NULL) {
  1447. G.os2.rootlen = 0;
  1448. return MPN_OK;
  1449. }
  1450. if (G.os2.rootlen > 0) /* rootpath was already set, nothing to do */
  1451. return MPN_OK;
  1452. if ((G.os2.rootlen = strlen(pathcomp)) > 0) {
  1453. int had_trailing_pathsep=FALSE, has_drive=FALSE, add_dot=FALSE;
  1454. char *tmproot;
  1455. if ((tmproot = (char *)malloc(G.os2.rootlen+3)) == (char *)NULL) {
  1456. G.os2.rootlen = 0;
  1457. return MPN_NOMEM;
  1458. }
  1459. strcpy(tmproot, pathcomp);
  1460. if (isalpha((uch)tmproot[0]) && tmproot[1] == ':')
  1461. has_drive = TRUE; /* drive designator */
  1462. if (tmproot[G.os2.rootlen-1] == '/') {
  1463. tmproot[--G.os2.rootlen] = '\0';
  1464. had_trailing_pathsep = TRUE;
  1465. }
  1466. if (has_drive && (G.os2.rootlen == 2)) {
  1467. if (!had_trailing_pathsep) /* i.e., original wasn't "x:/" */
  1468. add_dot = TRUE; /* relative path: add '.' before '/' */
  1469. } else if (G.os2.rootlen > 0) { /* need not check "x:." and "x:/" */
  1470. #ifdef MSC /* MSC 6.00 bug: stat(non-existent-dir) == 0 [exists!] */
  1471. if (GetFileTime(tmproot) == -1 ||
  1472. SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))
  1473. #else
  1474. if (SSTAT(tmproot, &G.statbuf) || !S_ISDIR(G.statbuf.st_mode))
  1475. #endif
  1476. { /* path does not exist */
  1477. if (!G.create_dirs /* || iswild(tmproot) */
  1478. ) {
  1479. free(tmproot);
  1480. G.os2.rootlen = 0;
  1481. return MPN_INF_SKIP; /* treat as stored file */
  1482. }
  1483. /* create directory (could add loop here scanning tmproot
  1484. * to create more than one level, but really necessary?) */
  1485. if (MKDIR(tmproot, 0777) == -1) {
  1486. Info(slide, 1, ((char *)slide,
  1487. LoadFarString(CantCreateExtractDir),
  1488. FnFilter1(tmproot)));
  1489. free(tmproot);
  1490. G.os2.rootlen = 0;
  1491. /* path didn't exist, tried to create, failed: */
  1492. /* file exists, or need 2+ directory levels */
  1493. return MPN_ERR_SKIP;
  1494. }
  1495. }
  1496. }
  1497. if (add_dot) /* had just "x:", make "x:." */
  1498. tmproot[G.os2.rootlen++] = '.';
  1499. tmproot[G.os2.rootlen++] = '/';
  1500. tmproot[G.os2.rootlen] = '\0';
  1501. if ((G.os2.rootpath = realloc(tmproot, G.os2.rootlen+1)) == NULL) {
  1502. free(tmproot);
  1503. G.os2.rootlen = 0;
  1504. return MPN_NOMEM;
  1505. }
  1506. Trace((stderr, "rootpath now = [%s]\n", FnFilter1(G.os2.rootpath)));
  1507. }
  1508. return MPN_OK;
  1509. }
  1510. #endif /* !SFX || SFX_EXDIR */
  1511. /*---------------------------------------------------------------------------
  1512. END: free rootpath, immediately prior to program exit.
  1513. ---------------------------------------------------------------------------*/
  1514. if (FUNCTION == END) {
  1515. Trace((stderr, "freeing rootpath\n"));
  1516. if (G.os2.rootlen > 0) {
  1517. free(G.os2.rootpath);
  1518. G.os2.rootlen = 0;
  1519. }
  1520. return MPN_OK;
  1521. }
  1522. return MPN_INVALID; /* should never reach */
  1523. } /* end function checkdir() */
  1524. /***********************/
  1525. /* Function isfloppy() */ /* more precisely, is it removable? */
  1526. /***********************/
  1527. static int isfloppy(nDrive)
  1528. int nDrive; /* 1 == A:, 2 == B:, etc. */
  1529. {
  1530. uch ParmList[1] = {0};
  1531. uch DataArea[1] = {0};
  1532. char Name[3];
  1533. HFILE handle;
  1534. #ifdef __32BIT__
  1535. ULONG rc;
  1536. ULONG action;
  1537. #else
  1538. USHORT rc;
  1539. USHORT action;
  1540. #endif
  1541. Name[0] = (char) (nDrive + 'A' - 1);
  1542. Name[1] = ':';
  1543. Name[2] = 0;
  1544. rc = DosOpen(Name, &handle, &action, 0L, FILE_NORMAL, FILE_OPEN,
  1545. OPEN_FLAGS_DASD | OPEN_FLAGS_FAIL_ON_ERROR |
  1546. OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0L);
  1547. if (rc == ERROR_NOT_READY) /* must be removable */
  1548. return TRUE;
  1549. else if (rc) { /* other error: do default a/b heuristic instead */
  1550. Trace((stderr, "error in DosOpen(DASD): guessing...\n", rc));
  1551. return (nDrive == 1 || nDrive == 2)? TRUE : FALSE;
  1552. }
  1553. rc = DosDevIOCtl(DataArea, sizeof(DataArea), ParmList, sizeof(ParmList),
  1554. DSK_BLOCKREMOVABLE, IOCTL_DISK, handle);
  1555. DosClose(handle);
  1556. if (rc) { /* again, just check for a/b */
  1557. Trace((stderr, "error in DosDevIOCtl category IOCTL_DISK, function "
  1558. "DSK_BLOCKREMOVABLE\n (rc = 0x%04x): guessing...\n", rc));
  1559. return (nDrive == 1 || nDrive == 2)? TRUE : FALSE;
  1560. } else {
  1561. return DataArea[0] ? FALSE : TRUE;
  1562. }
  1563. } /* end function isfloppy() */
  1564. static int IsFileNameValid(const char *name)
  1565. {
  1566. HFILE hf;
  1567. #ifdef __32BIT__
  1568. ULONG uAction;
  1569. #else
  1570. USHORT uAction;
  1571. #endif
  1572. switch( DosOpen((PSZ) name, &hf, &uAction, 0, 0, FILE_OPEN,
  1573. OPEN_ACCESS_READONLY | OPEN_SHARE_DENYNONE, 0) )
  1574. {
  1575. case ERROR_INVALID_NAME:
  1576. case ERROR_FILENAME_EXCED_RANGE:
  1577. return FALSE;
  1578. case NO_ERROR:
  1579. DosClose(hf);
  1580. default:
  1581. return TRUE;
  1582. }
  1583. }
  1584. /**********************/
  1585. /* Function map2fat() */
  1586. /**********************/
  1587. static void map2fat(pathcomp, pEndFAT)
  1588. char *pathcomp, **pEndFAT;
  1589. {
  1590. char *ppc = pathcomp; /* variable pointer to pathcomp */
  1591. char *pEnd = *pEndFAT; /* variable pointer to buildpathFAT */
  1592. char *pBegin = *pEndFAT; /* constant pointer to start of this comp. */
  1593. char *last_dot = (char *)NULL; /* last dot not converted to underscore */
  1594. int dotname = FALSE; /* flag: path component begins with dot */
  1595. /* ("." and ".." don't count) */
  1596. register unsigned workch; /* hold the character being tested */
  1597. /* Only need check those characters which are legal in HPFS but not
  1598. * in FAT: to get here, must already have passed through mapname.
  1599. * (GRR: oops, small bug--if char was quoted, no longer have any
  1600. * knowledge of that.) Also must truncate path component to ensure
  1601. * 8.3 compliance...
  1602. */
  1603. while ((workch = (uch)*ppc++) != 0) {
  1604. switch (workch) {
  1605. case '[': /* add '"' '+' ',' '=' ?? */
  1606. case ']':
  1607. *pEnd++ = '_'; /* convert brackets to underscores */
  1608. break;
  1609. case '.':
  1610. if (pEnd == *pEndFAT) { /* nothing appended yet... */
  1611. if (*ppc == '\0') /* don't bother appending a */
  1612. break; /* "./" component to the path */
  1613. else if (*ppc == '.' && ppc[1] == '\0') { /* "../" */
  1614. *pEnd++ = '.'; /* add first dot, unchanged... */
  1615. ++ppc; /* skip second dot, since it will */
  1616. } else { /* be "added" at end of if-block */
  1617. *pEnd++ = '_'; /* FAT doesn't allow null filename */
  1618. dotname = TRUE; /* bodies, so map .exrc -> _.exrc */
  1619. } /* (extra '_' now, "dot" below) */
  1620. } else if (dotname) { /* found a second dot, but still */
  1621. dotname = FALSE; /* have extra leading underscore: */
  1622. *pEnd = '\0'; /* remove it by shifting chars */
  1623. pEnd = *pEndFAT + 1; /* left one space (e.g., .p1.p2: */
  1624. while (pEnd[1]) { /* __p1 -> _p1_p2 -> _p1.p2 when */
  1625. *pEnd = pEnd[1]; /* finished) [opt.: since first */
  1626. ++pEnd; /* two chars are same, can start */
  1627. } /* shifting at second position] */
  1628. }
  1629. last_dot = pEnd; /* point at last dot so far... */
  1630. *pEnd++ = '_'; /* convert dot to underscore for now */
  1631. break;
  1632. default:
  1633. *pEnd++ = (char)workch;
  1634. } /* end switch */
  1635. } /* end while loop */
  1636. *pEnd = '\0'; /* terminate buildpathFAT */
  1637. /* NOTE: keep in mind that pEnd points to the end of the path
  1638. * component, and *pEndFAT still points to the *beginning* of it...
  1639. * Also note that the algorithm does not try to get too fancy:
  1640. * if there are no dots already, the name either gets truncated
  1641. * at 8 characters or the last underscore is converted to a dot
  1642. * (only if more characters are saved that way). In no case is
  1643. * a dot inserted between existing characters.
  1644. */
  1645. if (last_dot == (char *)NULL) { /* no dots: check for underscores... */
  1646. char *plu = strrchr(pBegin, '_'); /* pointer to last underscore */
  1647. if (plu == (char *)NULL) { /* no dots, no underscores: truncate at 8 */
  1648. *pEndFAT += 8; /* chars (could insert '.' and keep 11...) */
  1649. if (*pEndFAT > pEnd)
  1650. *pEndFAT = pEnd; /* oops...didn't have 8 chars to truncate */
  1651. else
  1652. **pEndFAT = '\0';
  1653. } else if (MIN(plu - pBegin, 8) + MIN(pEnd - plu - 1, 3) > 8) {
  1654. last_dot = plu; /* be lazy: drop through to next if-block */
  1655. } else if ((pEnd - *pEndFAT) > 8) {
  1656. *pEndFAT += 8; /* more fits into just basename than if */
  1657. **pEndFAT = '\0'; /* convert last underscore to dot */
  1658. } else
  1659. *pEndFAT = pEnd; /* whole thing fits into 8 chars or less */
  1660. }
  1661. if (last_dot != (char *)NULL) { /* one dot (or two, in the case of */
  1662. *last_dot = '.'; /* "..") is OK: put it back in */
  1663. if ((last_dot - pBegin) > 8) {
  1664. char *p, *q;
  1665. int i;
  1666. p = last_dot;
  1667. q = last_dot = pBegin + 8;
  1668. for (i = 0; (i < 4) && *p; ++i) /* too many chars in basename: */
  1669. *q++ = *p++; /* shift ".ext" left and */
  1670. *q = '\0'; /* truncate/terminate it */
  1671. *pEndFAT = q;
  1672. } else if ((pEnd - last_dot) > 4) { /* too many chars in extension */
  1673. *pEndFAT = last_dot + 4;
  1674. **pEndFAT = '\0';
  1675. } else
  1676. *pEndFAT = pEnd; /* filename is fine; point at terminating zero */
  1677. if ((last_dot - pBegin) > 0 && last_dot[-1] == ' ')
  1678. last_dot[-1] = '_'; /* NO blank in front of '.'! */
  1679. }
  1680. } /* end function map2fat() */
  1681. static int SetLongNameEA(char *name, char *longname)
  1682. {
  1683. EAOP eaop;
  1684. FEALST fealst;
  1685. eaop.fpFEAList = (PFEALIST) &fealst;
  1686. eaop.fpGEAList = NULL;
  1687. eaop.oError = 0;
  1688. strcpy((char *) fealst.szName, ".LONGNAME");
  1689. strcpy((char *) fealst.szValue, longname);
  1690. fealst.cbList = sizeof(fealst) - CCHMAXPATH + strlen((char *) fealst.szValue);
  1691. fealst.cbName = (BYTE) strlen((char *) fealst.szName);
  1692. fealst.cbValue = sizeof(USHORT) * 2 + strlen((char *) fealst.szValue);
  1693. #ifdef __32BIT__
  1694. fealst.oNext = 0;
  1695. #endif
  1696. fealst.fEA = 0;
  1697. fealst.eaType = 0xFFFD;
  1698. fealst.eaSize = strlen((char *) fealst.szValue);
  1699. return DosSetPathInfo(name, FIL_QUERYEASIZE,
  1700. (PBYTE) &eaop, sizeof(eaop), 0);
  1701. }
  1702. /****************************/
  1703. /* Function close_outfile() */
  1704. /****************************/
  1705. /* GRR: need to return error level!! */
  1706. void close_outfile(__G) /* only for extracted files, not directories */
  1707. __GDEF
  1708. {
  1709. fclose(G.outfile);
  1710. /* set extra fields, both stored-in-zipfile and .LONGNAME flavors */
  1711. if (G.extra_field) { /* zipfile extra field may have extended attribs */
  1712. int err = EvalExtraFields(__G__ G.filename, G.extra_field,
  1713. G.lrec.extra_field_length);
  1714. if (err == IZ_EF_TRUNC) {
  1715. if (uO.qflag)
  1716. Info(slide, 1, ((char *)slide, "%-22s ",
  1717. FnFilter1(G.filename)));
  1718. Info(slide, 1, ((char *)slide, LoadFarString(TruncEAs),
  1719. makeword(G.extra_field+2)-10, uO.qflag? "\n" : ""));
  1720. }
  1721. }
  1722. if (G.os2.longnameEA) {
  1723. #ifdef DEBUG
  1724. int e =
  1725. #endif
  1726. SetLongNameEA(G.filename, G.os2.lastpathcomp);
  1727. Trace((stderr, "close_outfile: SetLongNameEA() returns %d\n", e));
  1728. free(G.os2.lastpathcomp);
  1729. }
  1730. /* set date/time and permissions */
  1731. SetPathAttrTimes(__G__ G.pInfo->file_attr, 0);
  1732. } /* end function close_outfile() */
  1733. /******************************/
  1734. /* Function check_for_newer() */
  1735. /******************************/
  1736. int check_for_newer(__G__ filename) /* return 1 if existing file newer or equal; */
  1737. __GDEF
  1738. char *filename; /* 0 if older; -1 if doesn't exist yet */
  1739. {
  1740. ulg existing, archive;
  1741. #ifdef USE_EF_UT_TIME
  1742. iztimes z_utime;
  1743. #endif
  1744. if ((existing = (ulg)GetFileTime(filename)) == (ulg)-1)
  1745. return DOES_NOT_EXIST;
  1746. #ifdef USE_EF_UT_TIME
  1747. if (G.extra_field &&
  1748. #ifdef IZ_CHECK_TZ
  1749. G.tz_is_valid &&
  1750. #endif
  1751. (ef_scan_for_izux(G.extra_field, G.lrec.extra_field_length, 0,
  1752. G.lrec.last_mod_dos_datetime, &z_utime, NULL)
  1753. & EB_UT_FL_MTIME))
  1754. {
  1755. TTrace((stderr, "check_for_newer: using Unix extra field mtime\n"));
  1756. archive = Utime2DosDateTime(z_utime.mtime);
  1757. } else {
  1758. archive = G.lrec.last_mod_dos_datetime;
  1759. }
  1760. #else /* !USE_EF_UT_TIME */
  1761. archive = G.lrec.last_mod_dos_datetime;
  1762. #endif /* ?USE_EF_UT_TIME */
  1763. return (existing >= archive);
  1764. } /* end function check_for_newer() */
  1765. #ifndef SFX
  1766. /*************************/
  1767. /* Function dateformat() */
  1768. /*************************/
  1769. int dateformat()
  1770. {
  1771. /*-----------------------------------------------------------------------------
  1772. For those operating systems which support it, this function returns a value
  1773. which tells how national convention says that numeric dates are displayed.
  1774. Return values are DF_YMD, DF_DMY and DF_MDY.
  1775. -----------------------------------------------------------------------------*/
  1776. switch (GetCountryInfo()) {
  1777. case 0:
  1778. return DF_MDY;
  1779. case 1:
  1780. return DF_DMY;
  1781. case 2:
  1782. return DF_YMD;
  1783. }
  1784. return DF_MDY; /* default if error */
  1785. } /* end function dateformat() */
  1786. /************************/
  1787. /* Function version() */
  1788. /************************/
  1789. void version(__G)
  1790. __GDEF
  1791. {
  1792. int len;
  1793. #if defined(__IBMC__) || defined(__WATCOMC__) || defined(_MSC_VER)
  1794. char buf[80];
  1795. #endif
  1796. len = sprintf((char *)slide, LoadFarString(CompiledWith),
  1797. #if defined(__GNUC__)
  1798. # ifdef __EMX__ /* __EMX__ is defined as "1" only (sigh) */
  1799. "emx+gcc ", __VERSION__,
  1800. # else
  1801. "gcc ", __VERSION__,
  1802. # endif
  1803. #elif defined(__IBMC__)
  1804. "IBM ",
  1805. # if (__IBMC__ < 200)
  1806. (sprintf(buf, "C Set/2 %d.%02d", __IBMC__/100,__IBMC__%100), buf),
  1807. # elif (__IBMC__ < 300)
  1808. (sprintf(buf, "C Set++ %d.%02d", __IBMC__/100,__IBMC__%100), buf),
  1809. # else
  1810. (sprintf(buf, "Visual Age C++ %d.%02d", __IBMC__/100,__IBMC__%100), buf),
  1811. # endif
  1812. #elif defined(__WATCOMC__)
  1813. "Watcom C", (sprintf(buf, " (__WATCOMC__ = %d)", __WATCOMC__), buf),
  1814. #elif defined(__TURBOC__)
  1815. # ifdef __BORLANDC__
  1816. "Borland C++",
  1817. # if (__BORLANDC__ < 0x0460)
  1818. " 1.0",
  1819. # elif (__BORLANDC__ == 0x0460)
  1820. " 1.5", /* from Kai Uwe: three less than DOS */
  1821. # else
  1822. " 2.0", /* (__BORLANDC__ == 0x0500)? */
  1823. # endif
  1824. # else
  1825. "Turbo C", /* these are probably irrelevant */
  1826. # if (__TURBOC__ >= 661)
  1827. "++ 1.0 or later",
  1828. # elif (__TURBOC__ == 661)
  1829. " 3.0?",
  1830. # elif (__TURBOC__ == 397)
  1831. " 2.0",
  1832. # else
  1833. " 1.0 or 1.5?",
  1834. # endif
  1835. # endif
  1836. #elif defined(MSC)
  1837. "Microsoft C ",
  1838. # ifdef _MSC_VER
  1839. (sprintf(buf, "%d.%02d", _MSC_VER/100, _MSC_VER%100), buf),
  1840. # else
  1841. "5.1 or earlier",
  1842. # endif
  1843. #else
  1844. "unknown compiler", "",
  1845. #endif /* ?compilers */
  1846. "OS/2",
  1847. /* GRR: does IBM C/2 identify itself as IBM rather than Microsoft? */
  1848. #if (defined(MSC) || (defined(__WATCOMC__) && !defined(__386__)))
  1849. # if defined(M_I86HM) || defined(__HUGE__)
  1850. " (16-bit, huge)",
  1851. # elif defined(M_I86LM) || defined(__LARGE__)
  1852. " (16-bit, large)",
  1853. # elif defined(M_I86MM) || defined(__MEDIUM__)
  1854. " (16-bit, medium)",
  1855. # elif defined(M_I86CM) || defined(__COMPACT__)
  1856. " (16-bit, compact)",
  1857. # elif defined(M_I86SM) || defined(__SMALL__)
  1858. " (16-bit, small)",
  1859. # elif defined(M_I86TM) || defined(__TINY__)
  1860. " (16-bit, tiny)",
  1861. # else
  1862. " (16-bit)",
  1863. # endif
  1864. #else
  1865. " (32-bit)",
  1866. #endif
  1867. #ifdef __DATE__
  1868. " on ", __DATE__
  1869. #else
  1870. "", ""
  1871. #endif
  1872. );
  1873. (*G.message)((zvoid *)&G, slide, (ulg)len, 0);
  1874. /* MSC can't handle huge macro expansions */
  1875. /* temporary debugging code for Borland compilers only */
  1876. /* __TCPLUSPLUS__, __BCPLUSPLUS__ not defined for v1.5 */
  1877. #if (defined(__TURBOC__) && defined(DEBUG))
  1878. Info(slide, 0, ((char *)slide, "\t(__TURBOC__ = 0x%04x = %d)\n", __TURBOC__,
  1879. __TURBOC__));
  1880. #ifdef __BORLANDC__
  1881. Info(slide, 0, ((char *)slide, "\t(__BORLANDC__ = 0x%04x)\n",__BORLANDC__));
  1882. #else
  1883. Info(slide, 0, ((char *)slide, "\tdebug(__BORLANDC__ not defined)\n"));
  1884. #endif
  1885. #endif /* __TURBOC__ && DEBUG */
  1886. } /* end function version() */
  1887. #endif /* !SFX */
  1888. #endif /* !FUNZIP */
  1889. #ifdef MY_ZCALLOC /* Special zcalloc function for MEMORY16 (MSDOS/OS2) */
  1890. #if defined(MSC) || defined(__WATCOMC__)
  1891. #if (!defined(_MSC_VER) || (_MSC_VER < 700))
  1892. # define _halloc halloc
  1893. # define _hfree hfree
  1894. #endif
  1895. zvoid far *zcalloc (unsigned items, unsigned size)
  1896. {
  1897. return (zvoid far *)_halloc((long)items, size);
  1898. }
  1899. zvoid zcfree (zvoid far *ptr)
  1900. {
  1901. _hfree((void huge *)ptr);
  1902. }
  1903. #endif /* MSC || __WATCOMC__ */
  1904. #endif /* MY_ZCALLOC */
  1905. #ifndef FUNZIP
  1906. /* This table can be static because it is pseudo-constant */
  1907. static unsigned char cUpperCase[256], cLowerCase[256];
  1908. static BOOL bInitialized=FALSE;
  1909. /* Initialize the tables of upper- and lowercase characters, including
  1910. handling of country-dependent characters. */
  1911. static void InitNLS(void)
  1912. {
  1913. unsigned nCnt, nU;
  1914. COUNTRYCODE cc;
  1915. if (bInitialized == FALSE) {
  1916. bInitialized = TRUE;
  1917. for ( nCnt = 0; nCnt < 256; nCnt++ )
  1918. cUpperCase[nCnt] = cLowerCase[nCnt] = (unsigned char) nCnt;
  1919. cc.country = cc.codepage = 0;
  1920. DosMapCase(sizeof(cUpperCase), &cc, (PCHAR) cUpperCase);
  1921. for ( nCnt = 0; nCnt < 256; nCnt++ ) {
  1922. nU = cUpperCase[nCnt];
  1923. if (nU != nCnt && cLowerCase[nU] == (unsigned char) nU)
  1924. cLowerCase[nU] = (unsigned char) nCnt;
  1925. }
  1926. for ( nCnt = 'A'; nCnt <= 'Z'; nCnt++ )
  1927. cLowerCase[nCnt] = (unsigned char) (nCnt - 'A' + 'a');
  1928. }
  1929. }
  1930. int IsUpperNLS(int nChr)
  1931. {
  1932. return (cUpperCase[nChr] == (unsigned char) nChr);
  1933. }
  1934. int ToLowerNLS(int nChr)
  1935. {
  1936. return cLowerCase[nChr];
  1937. }
  1938. char *StringLower(char *szArg)
  1939. {
  1940. unsigned char *szPtr;
  1941. for ( szPtr = (unsigned char *) szArg; *szPtr; szPtr++ )
  1942. *szPtr = cLowerCase[*szPtr];
  1943. return szArg;
  1944. }
  1945. #ifdef MORE
  1946. int screensize(int *tt_rows, int *tt_cols)
  1947. {
  1948. #ifdef __EMX__
  1949. int dst[2];
  1950. _scrsize(dst);
  1951. if (tt_rows != NULL) *tt_rows = dst[1];
  1952. if (tt_cols != NULL) *tt_cols = dst[0];
  1953. #else
  1954. VIOMODEINFO vmi;
  1955. vmi.cb = sizeof(vmi);
  1956. VioGetMode(&vmi, 0);
  1957. if (tt_rows != NULL) *tt_rows = vmi.row;
  1958. if (tt_cols != NULL) *tt_cols = vmi.col;
  1959. #endif
  1960. return 0;
  1961. }
  1962. #endif /* MORE */
  1963. #if defined(__IBMC__) && defined(__DEBUG_ALLOC__)
  1964. void DebugMalloc(void)
  1965. {
  1966. _dump_allocated(0); /* print out debug malloc memory statistics */
  1967. }
  1968. #endif
  1969. #if defined(REENTRANT) && defined(USETHREADID)
  1970. ulg GetThreadId(void)
  1971. {
  1972. PTIB pptib; /* Address of a pointer to the
  1973. Thread Information Block */
  1974. PPIB pppib; /* Address of a pointer to the
  1975. Process Information Block */
  1976. DosGetInfoBlocks(&pptib, &pppib);
  1977. return pptib->tib_ptib2->tib2_ultid;
  1978. }
  1979. #endif /* defined(REENTRANT) && defined(USETHREADID) */
  1980. void os2GlobalsCtor(__GPRO)
  1981. {
  1982. G.os2.nLastDrive = (USHORT)(-1);
  1983. #ifdef OS2DLL
  1984. G.os2.rexx_mes = "0";
  1985. #endif
  1986. InitNLS();
  1987. }
  1988. #endif /* !FUNZIP */