platform/macclassic.c
changeset 362 ac8c846a0a66
parent 335 1d4720c018c3
child 393 468f75bf4d7d
equal deleted inserted replaced
361:0f945e89d537 362:ac8c846a0a66
   301         char *ptr;
   301         char *ptr;
   302         char *start;
   302         char *start;
   303         char *path = alloca(strlen(fname) + 1);
   303         char *path = alloca(strlen(fname) + 1);
   304         strcpy(path, fname);
   304         strcpy(path, fname);
   305         ptr = strchr(path, ':');
   305         ptr = strchr(path, ':');
   306         BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
   306         BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
   307         ptr = strchr(ptr + 1, ':');
   307         ptr = strchr(ptr + 1, ':');
   308         BAIL_IF_MACRO(!ptr, ERR_FILE_NOT_FOUND, err); /* just in case */
   308         BAIL_IF_MACRO(!ptr, ERR_NO_SUCH_FILE, err); /* just in case */
   309         *ptr = '\0';
   309         *ptr = '\0';
   310         err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
   310         err = fnameToFSSpecNoAlias(path, spec); /* get first dir. */
   311         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
   311         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, err);
   312         start = ptr;
   312         start = ptr;
   313         ptr = strchr(start + 1, ':');
   313         ptr = strchr(start + 1, ':');
   456 
   456 
   457 
   457 
   458 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   458 LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname,
   459                                                   int omitSymLinks)
   459                                                   int omitSymLinks)
   460 {
   460 {
   461     LinkedStringList *retval = NULL;
   461     LinkedStringList *ret = NULL, *p = NULL;
   462     LinkedStringList *l = NULL;
       
   463     LinkedStringList *prev = NULL;
       
   464     UInt16 i;
   462     UInt16 i;
   465     UInt16 max;
   463     UInt16 max;
   466     FSSpec spec;
   464     FSSpec spec;
   467     CInfoPBRec infoPB;
   465     CInfoPBRec infoPB;
   468     Str255 str255;
   466     Str255 str255;
   507 
   505 
   508         if ((alias) && (omitSymLinks))
   506         if ((alias) && (omitSymLinks))
   509             continue;
   507             continue;
   510 
   508 
   511         /* still here? Add it to the list. */
   509         /* still here? Add it to the list. */
   512 
   510         ret = __PHYSFS_addToLinkedStringList(ret, &p, &str255[1], str255[0]);
   513         l = (LinkedStringList *) malloc(sizeof (LinkedStringList));
       
   514         if (l == NULL)
       
   515             break;
       
   516 
       
   517         l->str = (char *) malloc(str255[0] + 1);
       
   518         if (l->str == NULL)
       
   519         {
       
   520             free(l);
       
   521             break;
       
   522         } /* if */
       
   523 
       
   524         memcpy(l->str, &str255[1], str255[0]);
       
   525         l->str[str255[0]] = '\0';
       
   526 
       
   527         if (retval == NULL)
       
   528             retval = l;
       
   529         else
       
   530             prev->next = l;
       
   531 
       
   532         prev = l;
       
   533         l->next = NULL;
       
   534     } /* for */
   511     } /* for */
   535 
   512 
   536     return(retval);
   513     return(ret);
   537 } /* __PHYSFS_platformEnumerateFiles */
   514 } /* __PHYSFS_platformEnumerateFiles */
   538 
   515 
   539 
   516 
   540 char *__PHYSFS_platformCurrentDir(void)
   517 char *__PHYSFS_platformCurrentDir(void)
   541 {
   518 {
   586     FSSpec spec;
   563     FSSpec spec;
   587     OSErr err = fnameToFSSpec(fname, &spec);
   564     OSErr err = fnameToFSSpec(fname, &spec);
   588     BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, NULL);
   565     BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, NULL);
   589     if (err == fnfErr)
   566     if (err == fnfErr)
   590     {
   567     {
   591         BAIL_IF_MACRO(!createIfMissing, ERR_FILE_NOT_FOUND, NULL);
   568         BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
   592         err = HCreate(spec.vRefNum, spec.parID, spec.name,
   569         err = HCreate(spec.vRefNum, spec.parID, spec.name,
   593                       procInfo.processSignature, 'BINA');
   570                       procInfo.processSignature, 'BINA');
   594         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
   571         BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, NULL);
   595         created = 1;
   572         created = 1;
   596     } /* if */
   573     } /* if */