platform/macclassic.c
changeset 166 ed10fe7cb16e
parent 162 06ed1dc94f73
child 169 34829282ffe8
equal deleted inserted replaced
165:cbb1b0dcf6da 166:ed10fe7cb16e
    71     err = GetProcessInformation(&psn, &procInfo);
    71     err = GetProcessInformation(&psn, &procInfo);
    72     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
    72     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
    73 
    73 
    74     /* Get the name of the binary's parent directory. */
    74     /* Get the name of the binary's parent directory. */
    75     memset(&infoPB, '\0', sizeof (CInfoPBRec));
    75     memset(&infoPB, '\0', sizeof (CInfoPBRec));
    76     infoPB.dirInfo.ioNamePtr = str255;       /* put name in here.         */
    76     infoPB.dirInfo.ioNamePtr = str255;        /* put name in here.         */
    77     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of bin's volume.       */ 
    77     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of bin's volume.       */ 
    78     infoPB.dirInfo.ioDrParID = spec.parID;    /* ID of bin's dir.          */
    78     infoPB.dirInfo.ioDrParID = spec.parID;    /* ID of bin's dir.          */
    79     infoPB.dirInfo.ioFDirIndex = -1;          /* get dir (not file) info.  */
    79     infoPB.dirInfo.ioFDirIndex = -1;          /* get dir (not file) info.  */
    80 
    80 
    81     /* walk the tree back to the root dir (volume), building path string... */
    81     /* walk the tree back to the root dir (volume), building path string... */
    82     do
    82     do
    83     {
    83     {
    84         /* check parent dir of what we last looked at... */
    84         /* check parent dir of what we last looked at... */
    85         infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
    85         infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID;
    86         if (PBGetCatInfoAsync(&infoPB) != noErr)
    86         if (PBGetCatInfoSync(&infoPB) != noErr)
    87         {
    87         {
    88             if (retval != NULL)
    88             if (retval != NULL)
    89                 free(retval);
    89                 free(retval);
    90             BAIL_MACRO(ERR_OS_ERROR, NULL);
    90             BAIL_MACRO(ERR_OS_ERROR, NULL);
    91         } /* if */
    91         } /* if */
   161     extern int _stricmp(const char *, const char *);
   161     extern int _stricmp(const char *, const char *);
   162     return(_stricmp(x, y));  /* (*shrug*) */
   162     return(_stricmp(x, y));  /* (*shrug*) */
   163 } /* __PHYSFS_platformStricmp */
   163 } /* __PHYSFS_platformStricmp */
   164 
   164 
   165 
   165 
       
   166 static OSErr fnameToFSSpec(const char *fname, FSSpec *spec)
       
   167 {
       
   168     Str255 str255;
       
   169     int len = strlen(fname);
       
   170     if (len > 255)
       
   171         return(bdNamErr);
       
   172 
       
   173     /* !!! FIXME: What happens with relative pathnames? */
       
   174 
       
   175     str255[0] = strlen(fname);
       
   176     memcpy(&str255[1], fname, str255[0]);
       
   177     return(FSMakeFSSpec(0, 0, str255, spec));
       
   178 } /* fnameToFSSpec */
       
   179 
       
   180 
   166 int __PHYSFS_platformExists(const char *fname)
   181 int __PHYSFS_platformExists(const char *fname)
   167 {
   182 {
   168     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
   183     FSSpec spec;
       
   184     return(fnameToFSSpec(fname, &spec) == noErr);
   169 } /* __PHYSFS_platformExists */
   185 } /* __PHYSFS_platformExists */
   170 
   186 
   171 
   187 
   172 int __PHYSFS_platformIsSymLink(const char *fname)
   188 int __PHYSFS_platformIsSymLink(const char *fname)
   173 {
   189 {
   175 } /* __PHYSFS_platformIsSymlink */
   191 } /* __PHYSFS_platformIsSymlink */
   176 
   192 
   177 
   193 
   178 int __PHYSFS_platformIsDirectory(const char *fname)
   194 int __PHYSFS_platformIsDirectory(const char *fname)
   179 {
   195 {
   180     BAIL_MACRO(ERR_NOT_IMPLEMENTED, 0);
   196     FSSpec spec;
       
   197     CInfoPBRec infoPB;
       
   198 
       
   199     BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, ERR_OS_ERROR, 0);
       
   200     memset(&infoPB, '\0', sizeof (CInfoPBRec));
       
   201     infoPB.dirInfo.ioNamePtr = spec.name;     /* put name in here.       */
       
   202     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
       
   203     infoPB.dirInfo.ioDrParID = spec.parID;    /* ID of bin's dir.        */
       
   204     infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
       
   205     BAIL_IF_MACRO(PBGetCatInfoSync(&infoPB) != noErr, ERR_OS_ERROR, 0);
       
   206     return((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0);
   181 } /* __PHYSFS_platformIsDirectory */
   207 } /* __PHYSFS_platformIsDirectory */
   182 
   208 
   183 
   209 
   184 char *__PHYSFS_platformCvtToDependent(const char *prepend,
   210 char *__PHYSFS_platformCvtToDependent(const char *prepend,
   185                                       const char *dirName,
   211                                       const char *dirName,
   219 
   245 
   220 
   246 
   221 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   247 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   222                                                   int omitSymLinks)
   248                                                   int omitSymLinks)
   223 {
   249 {
   224     BAIL_MACRO(ERR_NOT_IMPLEMENTED, NULL);
   250     LinkedStringList *retval = NULL;
       
   251     LinkedStringList *l = NULL;
       
   252     LinkedStringList *prev = NULL;
       
   253     UInt16 i = 0;
       
   254     FSSpec spec;
       
   255     CInfoPBRec infoPB;
       
   256     Str255 str255;
       
   257 
       
   258     BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, ERR_OS_ERROR, 0);
       
   259 
       
   260     while (1)
       
   261     {
       
   262         memset(&infoPB, '\0', sizeof (CInfoPBRec));
       
   263         str255[0] = 0;
       
   264         infoPB.dirInfo.ioNamePtr = str255;        /* store name in here.     */
       
   265         infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
       
   266         infoPB.dirInfo.ioDrParID = spec.parID;    /* ID of bin's dir.        */
       
   267         infoPB.dirInfo.ioFDirIndex = ++i;         /* file (not parent) info. */
       
   268         if (PBGetCatInfoSync(&infoPB) != noErr)
       
   269             break;
       
   270 
       
   271         l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
       
   272         if (l == NULL)
       
   273             break;
       
   274 
       
   275         l->str = (char *) malloc(str255[0] + 1);
       
   276         if (l->str == NULL)
       
   277         {
       
   278             free(l);
       
   279             break;
       
   280         } /* if */
       
   281 
       
   282         memcpy(l->str, &str255[1], str255[0]);
       
   283         l->str[str255[0]] = '\0';
       
   284 
       
   285         if (retval == NULL)
       
   286             retval = l;
       
   287         else
       
   288             prev->next = l;
       
   289 
       
   290         prev = l;
       
   291         l->next = NULL;
       
   292     } /* while */
       
   293 
       
   294     return(retval);
   225 } /* __PHYSFS_platformEnumerateFiles */
   295 } /* __PHYSFS_platformEnumerateFiles */
   226 
   296 
   227 
   297 
   228 char *__PHYSFS_platformCurrentDir(void)
   298 char *__PHYSFS_platformCurrentDir(void)
   229 {
   299 {