home *** CD-ROM | disk | FTP | other *** search
/ Celestin Apprentice 2 / Apprentice-Release2.iso / Source Code / C / Libraries / stdwin / Ports / mac / fullpath.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-06  |  1.3 KB  |  71 lines  |  [TEXT/????]

  1. /* GET FULL PATHNAME OF A FILE. */
  2.  
  3. #include "macwin.h"
  4.  
  5. #ifdef MPW
  6. #include <Files.h>
  7. #endif
  8. #ifdef THINK_C_PRE_5_0
  9. #include <HFS.h>
  10. #endif
  11.  
  12. /* Mac file system parameters */
  13. #define MAXPATH 256    /* Max path name length+1 */
  14. #define SEP ':'        /* Separator in path names */
  15. #define ROOTID 2    /* DirID of a volume's root directory */
  16.  
  17. /* Macro to find out whether we can do HFS-only calls: */
  18. #define FSFCBLen (* (short *) 0x3f6)
  19. #define hfsrunning() (FSFCBLen > 0)
  20.  
  21. char *
  22. getdirname(dir)
  23.     int dir; /* WDRefNum */
  24. {
  25.     union {
  26.         HFileInfo f;
  27.         DirInfo d;
  28.         WDPBRec w;
  29.         VolumeParam v;
  30.     } pb;
  31.     static char cwd[2*MAXPATH];
  32.     unsigned char namebuf[MAXPATH];
  33.     short err;
  34.     long dirid= 0;
  35.     char *next= cwd + sizeof cwd - 1;
  36.     int len;
  37.     
  38.     if (!hfsrunning())
  39.         return "";
  40.     
  41.     for (;;) {
  42.         pb.d.ioNamePtr= namebuf;
  43.         pb.d.ioVRefNum= dir;
  44.         pb.d.ioFDirIndex= -1;
  45.         pb.d.ioDrDirID= dirid;
  46.         err= PBGetCatInfo(&pb.d, FALSE);
  47.         if (err != noErr) {
  48.             dprintf("PBCatInfo err %d", err);
  49.             return NULL;
  50.         }
  51.         *--next= SEP;
  52.         len= namebuf[0];
  53.         /* XXX There is no overflow check on cwd here! */
  54.         strncpy(next -= len, (char *)namebuf+1, len);
  55.         if (pb.d.ioDrDirID == ROOTID)
  56.             break;
  57.         dirid= pb.d.ioDrParID;
  58.     }
  59.     return next;
  60. }
  61.  
  62. void
  63. fullpath(buf, wdrefnum, file)
  64.     char *buf;
  65.     int wdrefnum;
  66.     char *file;
  67. {
  68.     strcpy(buf, getdirname(wdrefnum));
  69.     strcat(buf, file);
  70. }
  71.