platform/macclassic.c
changeset 393 468f75bf4d7d
parent 362 ac8c846a0a66
child 424 a691527e9f6e
equal deleted inserted replaced
392:bcc8e4dca868 393:468f75bf4d7d
   380     if (ptr == NULL)  /* just a volume name? Can't be a symlink. */
   380     if (ptr == NULL)  /* just a volume name? Can't be a symlink. */
   381         return(0);
   381         return(0);
   382 
   382 
   383     /* resolve aliases up to the actual file... */
   383     /* resolve aliases up to the actual file... */
   384     *ptr = '\0';
   384     *ptr = '\0';
   385     BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, ERR_OS_ERROR, 0);
   385     BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, NULL, 0);
   386 
   386 
   387     *ptr = strlen(ptr + 1);  /* ptr is now a pascal string. Yikes! */
   387     *ptr = strlen(ptr + 1);  /* ptr is now a pascal string. Yikes! */
   388     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   388     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   389     infoPB.dirInfo.ioNamePtr = spec.name;
   389     infoPB.dirInfo.ioNamePtr = spec.name;
   390     infoPB.dirInfo.ioVRefNum = spec.vRefNum;
   390     infoPB.dirInfo.ioVRefNum = spec.vRefNum;
   404 {
   404 {
   405     FSSpec spec;
   405     FSSpec spec;
   406     CInfoPBRec infoPB;
   406     CInfoPBRec infoPB;
   407     OSErr err;
   407     OSErr err;
   408 
   408 
   409     BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, ERR_OS_ERROR, 0);
   409     BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, NULL, 0);
   410     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   410     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   411     infoPB.dirInfo.ioNamePtr = spec.name;     /* put name in here.       */
   411     infoPB.dirInfo.ioNamePtr = spec.name;     /* put name in here.       */
   412     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
   412     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
   413     infoPB.dirInfo.ioDrDirID = spec.parID;    /* ID of bin's dir.        */
   413     infoPB.dirInfo.ioDrDirID = spec.parID;    /* ID of bin's dir.        */
   414     infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
   414     infoPB.dirInfo.ioFDirIndex = 0;           /* file (not parent) info. */
   464     FSSpec spec;
   464     FSSpec spec;
   465     CInfoPBRec infoPB;
   465     CInfoPBRec infoPB;
   466     Str255 str255;
   466     Str255 str255;
   467     long dirID;
   467     long dirID;
   468 
   468 
   469     BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, ERR_OS_ERROR, 0);
   469     BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, NULL, 0);
   470 
   470 
   471     /* get the dir ID of what we want to enumerate... */
   471     /* get the dir ID of what we want to enumerate... */
   472     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   472     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   473     infoPB.dirInfo.ioNamePtr = spec.name;     /* name of dir to enum.    */
   473     infoPB.dirInfo.ioNamePtr = spec.name;     /* name of dir to enum.    */
   474     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
   474     infoPB.dirInfo.ioVRefNum = spec.vRefNum;  /* ID of file's volume.    */ 
   534      *  direct path to a given file. convFSSpecToPath() mallocs a
   534      *  direct path to a given file. convFSSpecToPath() mallocs a
   535      *  return value buffer.
   535      *  return value buffer.
   536      */
   536      */
   537 
   537 
   538     FSSpec spec;
   538     FSSpec spec;
   539     BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, ERR_OS_ERROR, NULL);
   539     BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, NULL);
   540     return(convFSSpecToPath(&spec, 1));
   540     return(convFSSpecToPath(&spec, 1));
   541 } /* __PHYSFS_platformRealPath */
   541 } /* __PHYSFS_platformRealPath */
   542 
   542 
   543 
   543 
   544 int __PHYSFS_platformMkDir(const char *path)
   544 int __PHYSFS_platformMkDir(const char *path)
   546     SInt32 val = 0;
   546     SInt32 val = 0;
   547     FSSpec spec;
   547     FSSpec spec;
   548     OSErr err = fnameToFSSpec(path, &spec);
   548     OSErr err = fnameToFSSpec(path, &spec);
   549 
   549 
   550     BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
   550     BAIL_IF_MACRO(err == noErr, ERR_FILE_EXISTS, 0);
   551     BAIL_IF_MACRO(err != fnfErr, ERR_OS_ERROR, 0);
   551     BAIL_IF_MACRO(err != fnfErr, NULL, 0);
   552 
   552 
   553     err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
   553     err = DirCreate(spec.vRefNum, spec.parID, spec.name, &val);
   554     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
   554     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
   555     return(1);
   555     return(1);
   556 } /* __PHYSFS_platformMkDir */
   556 } /* __PHYSFS_platformMkDir */
   560 {
   560 {
   561     int created = 0;
   561     int created = 0;
   562     SInt16 *retval = NULL;
   562     SInt16 *retval = NULL;
   563     FSSpec spec;
   563     FSSpec spec;
   564     OSErr err = fnameToFSSpec(fname, &spec);
   564     OSErr err = fnameToFSSpec(fname, &spec);
   565     BAIL_IF_MACRO((err != noErr) && (err != fnfErr), ERR_OS_ERROR, NULL);
   565     BAIL_IF_MACRO((err != noErr) && (err != fnfErr), NULL, NULL);
   566     if (err == fnfErr)
   566     if (err == fnfErr)
   567     {
   567     {
   568         BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
   568         BAIL_IF_MACRO(!createIfMissing, ERR_NO_SUCH_FILE, NULL);
   569         err = HCreate(spec.vRefNum, spec.parID, spec.name,
   569         err = HCreate(spec.vRefNum, spec.parID, spec.name,
   570                       procInfo.processSignature, 'BINA');
   570                       procInfo.processSignature, 'BINA');
   732     SInt16 ref = *((SInt16 *) opaque);
   732     SInt16 ref = *((SInt16 *) opaque);
   733     SInt16 vRefNum;
   733     SInt16 vRefNum;
   734     HParamBlockRec hpbr;
   734     HParamBlockRec hpbr;
   735     Str63 volName;
   735     Str63 volName;
   736 
   736 
   737     BAIL_IF_MACRO(GetVRefNum (ref, &vRefNum) != noErr, ERR_OS_ERROR, 0);
   737     BAIL_IF_MACRO(GetVRefNum(ref, &vRefNum) != noErr, ERR_OS_ERROR, 0);
   738 
   738 
   739     memset(&hpbr, '\0', sizeof (HParamBlockRec));
   739     memset(&hpbr, '\0', sizeof (HParamBlockRec));
   740     hpbr.volumeParam.ioNamePtr = volName;
   740     hpbr.volumeParam.ioNamePtr = volName;
   741     hpbr.volumeParam.ioVRefNum = vRefNum;
   741     hpbr.volumeParam.ioVRefNum = vRefNum;
   742     hpbr.volumeParam.ioVolIndex = 0;
   742     hpbr.volumeParam.ioVolIndex = 0;
   752 
   752 
   753 int __PHYSFS_platformDelete(const char *path)
   753 int __PHYSFS_platformDelete(const char *path)
   754 {
   754 {
   755     FSSpec spec;
   755     FSSpec spec;
   756     OSErr err;
   756     OSErr err;
   757     BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, ERR_OS_ERROR, 0);
   757     BAIL_IF_MACRO(fnameToFSSpec(path, &spec) != noErr, NULL, 0);
   758     err = HDelete(spec.vRefNum, spec.parID, spec.name);
   758     err = HDelete(spec.vRefNum, spec.parID, spec.name);
   759     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
   759     BAIL_IF_MACRO(err != noErr, ERR_OS_ERROR, 0);
   760     return(1);
   760     return(1);
   761 } /* __PHYSFS_platformDelete */
   761 } /* __PHYSFS_platformDelete */
   762 
   762 
   789 {
   789 {
   790     FSSpec spec;
   790     FSSpec spec;
   791     CInfoPBRec infoPB;
   791     CInfoPBRec infoPB;
   792     UInt32 modDate;
   792     UInt32 modDate;
   793 
   793 
   794     BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, ERR_OS_ERROR, -1);
   794     if (fnameToFSSpec(fname, &spec) != noErr)
       
   795         return(-1); /* fnameToFSSpec() sets physfs error message. */
   795 
   796 
   796     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   797     memset(&infoPB, '\0', sizeof (CInfoPBRec));
   797     infoPB.dirInfo.ioNamePtr = spec.name;
   798     infoPB.dirInfo.ioNamePtr = spec.name;
   798     infoPB.dirInfo.ioVRefNum = spec.vRefNum;
   799     infoPB.dirInfo.ioVRefNum = spec.vRefNum;
   799     infoPB.dirInfo.ioDrDirID = spec.parID;
   800     infoPB.dirInfo.ioDrDirID = spec.parID;