home *** CD-ROM | disk | FTP | other *** search
/ ftp.muug.mb.ca / 2014.06.ftp.muug.mb.ca.tar / ftp.muug.mb.ca / pub / src / unzip.tar.gz / unzip.tar / unzip / MAC.arc / macfile.c next >
C/C++ Source or Header  |  1991-03-10  |  4KB  |  137 lines

  1. /*---------------------------------------------------------------------------
  2.  
  3.   mac.c
  4.  
  5.   This source file is used by the mac port to support commands not available
  6.   directly on the Mac, i.e. mkdir().
  7.   It also helps determine if we're running on a Mac with HFS and a disk
  8.   formatted for HFS (HFS - Hierarchical File System; compared to its predecessor,
  9.   MFS - Macintosh File System).
  10.   
  11.   ---------------------------------------------------------------------------*/
  12.  
  13. #include "unzip.h"
  14.  
  15. #ifdef MACOS
  16. static short wAppVRefNum;
  17. static long lAppDirID;
  18. int hfsflag;            /* set if disk has hierarchical file system */
  19.  
  20. void macfstest(int vrefnum, int wd)
  21. {
  22.     Str255 st;
  23.  
  24.     /* is this machine running HFS file system? */
  25. #ifdef THINK_C
  26.     if (FSFCBLen <= 0) {
  27. #else
  28.     if (*(short *)FSFCBLen <= 0) {
  29. #endif
  30.         hfsflag = false;
  31.     }
  32.     else
  33.     {
  34.         hfsflag = true;
  35.     }
  36.  
  37.     /* get the file's volume reference number and directory ID */
  38.     if (hfsflag == true) {
  39.         WDPBRec    wdpb;
  40.         OSErr err = noErr;
  41.  
  42.         if (vrefnum != 0) {
  43.             wdpb.ioCompletion = false;
  44.             wdpb.ioNamePtr = st;
  45.             wdpb.ioWDIndex = 0;
  46.             wdpb.ioVRefNum = vrefnum;
  47.             err = PBHGetVol(&wdpb, false);
  48.         
  49.             if (err == noErr) {
  50.                 wAppVRefNum = wdpb.ioWDVRefNum;
  51.                 lAppDirID = wdpb.ioWDDirID;
  52.             }
  53.         }
  54.  
  55.         /* is the disk we're using formatted for HFS? */
  56.         hfsflag = IsHFSDisk(wAppVRefNum);
  57.     }
  58. } /* mactest */
  59.  
  60. static int IsHFSDisk(short wRefNum)
  61. {
  62.     /* get info about the specified volume */
  63.     if (hfsflag == true) {
  64.         HParamBlockRec    hpbr;
  65.         Str255 temp;
  66.         short wErr;
  67.         
  68.         hpbr.volumeParam.ioCompletion = 0;
  69.         hpbr.volumeParam.ioNamePtr = temp;
  70.         hpbr.volumeParam.ioVRefNum = wRefNum;
  71.         hpbr.volumeParam.ioVolIndex = 0;
  72.         wErr = PBHGetVInfo(&hpbr, 0);
  73.  
  74.         if (wErr == noErr && hpbr.volumeParam.ioVFSID == 0
  75.             && hpbr.volumeParam.ioVSigWord == 0x4244) {
  76.                 return true;
  77.         }
  78.     }
  79.  
  80.     return false;
  81. } /* IsHFSDisk */
  82.  
  83. int mkdir(char *path, int mode)
  84. {
  85.     OSErr    err = -1;
  86.  
  87.     if (path != 0 && strlen(path)<256 && hfsflag == true) {
  88.         HParamBlockRec    hpbr;
  89.         Str255    st;
  90.         short     wVol;
  91.         long      lDirID;
  92.  
  93.         CtoPstr(path);
  94.         hpbr.fileParam.ioNamePtr = st;
  95.         hpbr.fileParam.ioCompletion = NULL;
  96.         err = PBHGetVol((WDPBPtr)&hpbr, false);
  97.         if (err == noErr) {
  98.             wVol = hpbr.wdParam.ioWDVRefNum;
  99.             lDirID = hpbr.wdParam.ioWDDirID;
  100.             hpbr.fileParam.ioCompletion = NULL;
  101.             hpbr.fileParam.ioVRefNum = wVol;
  102.             hpbr.fileParam.ioDirID = lDirID;
  103.             hpbr.fileParam.ioNamePtr = path;
  104.             err = PBDirCreate(&hpbr, false);
  105.         }    
  106.         PtoCstr(path);
  107.     }
  108.  
  109.     return err;
  110. } /* mkdir */
  111.  
  112. void SetMacVol(char *pch, short wVRefNum)
  113. {
  114.     OSErr err = -1;
  115.  
  116.     if (hfsflag == true) {
  117.         HParamBlockRec  hpbr;
  118.         Str255  st;
  119.  
  120.         hpbr.wdParam.ioCompletion = NULL;
  121.         hpbr.wdParam.ioNamePtr = st;
  122.         hpbr.wdParam.ioVRefNum = wVRefNum;
  123.         hpbr.wdParam.ioWDIndex = 0;
  124.         hpbr.wdParam.ioWDProcID = 0;
  125.         hpbr.wdParam.ioWDVRefNum = 0;
  126.         err = PBGetWDInfo(&hpbr, false);
  127.         if (err == noErr) {
  128.             hpbr.wdParam.ioCompletion = NULL;
  129.             hpbr.wdParam.ioNamePtr = NULL;
  130.             err = PBHSetVol(&hpbr, false);
  131.         }
  132.     } else {
  133.         err = SetVol(pch, wVRefNum);
  134.     }
  135. } /* SetMacVol */
  136. #endif /* MACOS */
  137.