Skip to content

Commit

Permalink
Fixed __PHYSFS_platformRealPath(), and changed userdir behaviour. We'…
Browse files Browse the repository at this point in the history
…re now feature-complete on the Mac, as far as I can tell.
  • Loading branch information
icculus committed Apr 6, 2002
1 parent fb712cb commit f56737b
Showing 1 changed file with 36 additions and 13 deletions.
49 changes: 36 additions & 13 deletions platform/macclassic.c
Expand Up @@ -139,22 +139,22 @@ char **__PHYSFS_platformDetectAvailableCDs(void)
} /* __PHYSFS_platformDetectAvailableCDs */


char *__PHYSFS_platformCalcBaseDir(const char *argv0)
static char *convFSSpecToPath(FSSpec *spec, int includeFile)
{
char *ptr;
char *retval = NULL;
UInt32 retLength = 0;
CInfoPBRec infoPB;
Str255 str255;
FSSpec spec;

/* Get the name of the binary's parent directory. */
memcpy(&spec, &procfsspec, sizeof (FSSpec));

str255[0] = spec->name[0];
memcpy(&str255[1], &spec->name[1], str255[0]);

memset(&infoPB, '\0', sizeof (CInfoPBRec));
infoPB.dirInfo.ioNamePtr = str255; /* put name in here. */
infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of bin's volume. */
infoPB.dirInfo.ioDrParID = spec.parID; /* ID of bin's dir. */
infoPB.dirInfo.ioFDirIndex = -1; /* get dir (not file) info. */
infoPB.dirInfo.ioVRefNum = spec->vRefNum; /* ID of bin's volume. */
infoPB.dirInfo.ioDrParID = spec->parID; /* ID of bin's dir. */
infoPB.dirInfo.ioFDirIndex = (includeFile) ? 0 : -1;

/* walk the tree back to the root dir (volume), building path string... */
do
Expand All @@ -167,7 +167,9 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
free(retval);
BAIL_MACRO(ERR_OS_ERROR, NULL);
} /* if */


infoPB.dirInfo.ioFDirIndex = -1; /* look at parent dir next time. */

/* allocate more space for the retval... */
retLength += str255[0] + 1; /* + 1 for a ':' or null char... */
ptr = (char *) malloc(retLength);
Expand All @@ -191,6 +193,16 @@ char *__PHYSFS_platformCalcBaseDir(const char *argv0)
} while (infoPB.dirInfo.ioDrDirID != fsRtDirID);

return(retval);
} /* convFSSpecToPath */


char *__PHYSFS_platformCalcBaseDir(const char *argv0)
{
FSSpec spec;

/* Get the name of the binary's parent directory. */
FSMakeFSSpec(procfsspec.vRefNum, procfsspec.parID, procfsspec.name, &spec);
return(convFSSpecToPath(&spec, 0));
} /* __PHYSFS_platformCalcBaseDir */


Expand Down Expand Up @@ -224,7 +236,12 @@ char *__PHYSFS_platformGetUserName(void)

char *__PHYSFS_platformGetUserDir(void)
{
#if 0
return(NULL); /* bah...use default behaviour, I guess. */
#else
/* (Hmm. Default behaviour is broken in the base library. :) ) */
return(__PHYSFS_platformCalcBaseDir(NULL));
#endif
} /* __PHYSFS_platformGetUserDir */


Expand Down Expand Up @@ -528,10 +545,16 @@ char *__PHYSFS_platformCurrentDir(void)

char *__PHYSFS_platformRealPath(const char *path)
{
/* !!! FIXME: This isn't nearly right. */
char *retval = (char *) malloc(strlen(path) + 1);
strcpy(retval, path);
return(retval);
/*
* fnameToFSSpec() will resolve any symlinks to get to the real
* file's FSSpec, which, when converted, will contain the real
* direct path to a given file. convFSSpecToPath() mallocs a
* return value buffer.
*/

FSSpec spec;
BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, ERR_OS_ERROR, NULL);
return(convFSSpecToPath(&spec, 1));
} /* __PHYSFS_platformRealPath */


Expand Down

0 comments on commit f56737b

Please sign in to comment.