platform/macclassic.c
changeset 185 4959e825c3ef
parent 183 352d940a99d0
child 214 19846c18071b
equal deleted inserted replaced
184:ddc4dd13277d 185:4959e825c3ef
   137     retval[cd_count - 1] = NULL;
   137     retval[cd_count - 1] = NULL;
   138     return(retval);
   138     return(retval);
   139 } /* __PHYSFS_platformDetectAvailableCDs */
   139 } /* __PHYSFS_platformDetectAvailableCDs */
   140 
   140 
   141 
   141 
   142 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
   142 static char *convFSSpecToPath(FSSpec *spec, int includeFile)
   143 {
   143 {
   144     char *ptr;
   144     char *ptr;
   145     char *retval = NULL;
   145     char *retval = NULL;
   146     UInt32 retLength = 0;
   146     UInt32 retLength = 0;
   147     CInfoPBRec infoPB;
   147     CInfoPBRec infoPB;
   148     Str255 str255;
   148     Str255 str255;
   149     FSSpec spec;
   149 
   150     
   150     str255[0] = spec->name[0];
   151     /* Get the name of the binary's parent directory. */
   151     memcpy(&str255[1], &spec->name[1], str255[0]);
   152     memcpy(&spec, &procfsspec, sizeof (FSSpec));
   152 
   153     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   153     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   154     infoPB.dirInfo.ioNamePtr = str255;          /* put name in here.         */
   154     infoPB.dirInfo.ioNamePtr = str255;          /* put name in here.         */
   155     infoPB.dirInfo.ioVRefNum = spec.vRefNum;    /* ID of bin's volume.       */ 
   155     infoPB.dirInfo.ioVRefNum = spec->vRefNum;   /* ID of bin's volume.       */ 
   156     infoPB.dirInfo.ioDrParID = spec.parID;      /* ID of bin's dir.          */
   156     infoPB.dirInfo.ioDrParID = spec->parID;     /* ID of bin's dir.          */
   157     infoPB.dirInfo.ioFDirIndex = -1;            /* get dir (not file) info.  */
   157     infoPB.dirInfo.ioFDirIndex = (includeFile) ? 0 : -1;
   158 
   158 
   159     /* walk the tree back to the root dir (volume), building path string... */
   159     /* walk the tree back to the root dir (volume), building path string... */
   160     do
   160     do
   161     {
   161     {
   162         /* check parent dir of what we last looked at... */
   162         /* check parent dir of what we last looked at... */
   165         {
   165         {
   166             if (retval != NULL)
   166             if (retval != NULL)
   167                 free(retval);
   167                 free(retval);
   168             BAIL_MACRO(ERR_OS_ERROR, NULL);
   168             BAIL_MACRO(ERR_OS_ERROR, NULL);
   169         } /* if */
   169         } /* if */
   170         
   170 
       
   171         infoPB.dirInfo.ioFDirIndex = -1;  /* look at parent dir next time. */
       
   172 
   171         /* allocate more space for the retval... */
   173         /* allocate more space for the retval... */
   172         retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
   174         retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
   173         ptr = (char *) malloc(retLength);
   175         ptr = (char *) malloc(retLength);
   174         if (ptr == NULL)
   176         if (ptr == NULL)
   175         {
   177         {
   189         } /* if */
   191         } /* if */
   190         retval = ptr;
   192         retval = ptr;
   191     } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
   193     } while (infoPB.dirInfo.ioDrDirID != fsRtDirID);
   192 
   194 
   193     return(retval);
   195     return(retval);
       
   196 } /* convFSSpecToPath */
       
   197 
       
   198 
       
   199 char *__PHYSFS_platformCalcBaseDir(const char *argv0)
       
   200 {
       
   201     FSSpec spec;
       
   202     
       
   203     /* Get the name of the binary's parent directory. */
       
   204     FSMakeFSSpec(procfsspec.vRefNum, procfsspec.parID, procfsspec.name, &spec);
       
   205     return(convFSSpecToPath(&spec, 0));
   194 } /* __PHYSFS_platformCalcBaseDir */
   206 } /* __PHYSFS_platformCalcBaseDir */
   195 
   207 
   196 
   208 
   197 char *__PHYSFS_platformGetUserName(void)
   209 char *__PHYSFS_platformGetUserName(void)
   198 {
   210 {
   222 } /* __PHYSFS_platformGetUserName */
   234 } /* __PHYSFS_platformGetUserName */
   223 
   235 
   224 
   236 
   225 char *__PHYSFS_platformGetUserDir(void)
   237 char *__PHYSFS_platformGetUserDir(void)
   226 {
   238 {
       
   239 #if 0
   227     return(NULL);  /* bah...use default behaviour, I guess. */
   240     return(NULL);  /* bah...use default behaviour, I guess. */
       
   241 #else
       
   242     /* (Hmm. Default behaviour is broken in the base library.  :)  )  */
       
   243     return(__PHYSFS_platformCalcBaseDir(NULL));
       
   244 #endif
   228 } /* __PHYSFS_platformGetUserDir */
   245 } /* __PHYSFS_platformGetUserDir */
   229 
   246 
   230 
   247 
   231 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
   248 PHYSFS_uint64 __PHYSFS_platformGetThreadID(void)
   232 {
   249 {
   526 } /* __PHYSFS_platformCurrentDir */
   543 } /* __PHYSFS_platformCurrentDir */
   527 
   544 
   528 
   545 
   529 char *__PHYSFS_platformRealPath(const char *path)
   546 char *__PHYSFS_platformRealPath(const char *path)
   530 {
   547 {
   531     /* !!! FIXME: This isn't nearly right. */
   548     /*
   532     char *retval = (char *) malloc(strlen(path) + 1);
   549      * fnameToFSSpec() will resolve any symlinks to get to the real
   533     strcpy(retval, path);
   550      *  file's FSSpec, which, when converted, will contain the real
   534     return(retval);
   551      *  direct path to a given file. convFSSpecToPath() mallocs a
       
   552      *  return value buffer.
       
   553      */
       
   554 
       
   555     FSSpec spec;
       
   556     BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, ERR_OS_ERROR, NULL);
       
   557     return(convFSSpecToPath(&spec, 1));
   535 } /* __PHYSFS_platformRealPath */
   558 } /* __PHYSFS_platformRealPath */
   536 
   559 
   537 
   560 
   538 int __PHYSFS_platformMkDir(const char *path)
   561 int __PHYSFS_platformMkDir(const char *path)
   539 {
   562 {