LinkedStringList *__PHYSFS_platformEnumerateFiles(const char *dirname, int omitSymLinks) { LinkedStringList *ret = NULL, *p = NULL; UInt16 i; UInt16 max; FSSpec spec; CInfoPBRec infoPB; Str255 str255; long dirID; BAIL_IF_MACRO(fnameToFSSpec(dirname, &spec) != noErr, NULL, 0); /* get the dir ID of what we want to enumerate... */ memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; /* name of dir to enum. */ infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of file's volume. */ infoPB.dirInfo.ioDrDirID = spec.parID; /* ID of dir. */ infoPB.dirInfo.ioFDirIndex = 0; /* file (not parent) info. */ BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, NULL); if ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) == 0) BAIL_MACRO(ERR_NOT_A_DIR, NULL); dirID = infoPB.dirInfo.ioDrDirID; max = infoPB.dirInfo.ioDrNmFls; for (i = 1; i <= max; i++) { FSSpec aliasspec; Boolean alias = 0; Boolean folder = 0; memset(&infoPB, '\0', sizeof (CInfoPBRec)); str255[0] = 0; infoPB.dirInfo.ioNamePtr = str255; /* store name in here. */ infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of dir's volume. */ infoPB.dirInfo.ioDrDirID = dirID; /* ID of dir. */ infoPB.dirInfo.ioFDirIndex = i; /* next file's info. */ if (PBGetCatInfoSync(&infoPB) != noErr) continue; /* skip this file. Oh well. */ if (FSMakeFSSpec(spec.vRefNum, dirID, str255, &aliasspec) != noErr) continue; /* skip it. */ if (IsAliasFile(&aliasspec, &alias, &folder) != noErr) continue; /* skip it. */ if ((alias) && (omitSymLinks)) continue; /* still here? Add it to the list. */ ret = __PHYSFS_addToLinkedStringList(ret, &p, (const char *) &str255[1], str255[0]); } /* for */ return(ret); } /* __PHYSFS_platformEnumerateFiles */
OSErr GetFullPath( const FSSpec* spec, Str255 fullPath) { CInfoPBRec myPB; Str255 dirName; OSErr myErr; fullPath[0] = '\0'; BlockMoveData(spec->name, fullPath, spec->name[spec->name[0]]+1 ); myPB.dirInfo.ioNamePtr = dirName; myPB.dirInfo.ioVRefNum = spec->vRefNum; myPB.dirInfo.ioDrParID = spec->parID; myPB.dirInfo.ioFDirIndex = -1; do{ myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID; myErr = PBGetCatInfoSync(&myPB); dirName[0]++; dirName[ dirName[0] ]=':'; if( dirName[0]+fullPath[0]>=254 ){ fullPath[0]=0; return 1; } BlockMoveData(fullPath+1, dirName+dirName[0]+1, fullPath[0]); dirName[0]+=fullPath[0]; BlockMoveData(dirName, fullPath, dirName[0]+1); }while( !(myPB.dirInfo.ioDrDirID == fsRtDirID) ); return noErr; }
int __PHYSFS_platformIsSymLink(const char *fname) { OSErr err; FSSpec spec; Boolean a = 0; Boolean f = 0; CInfoPBRec infoPB; char *ptr; char *dir = alloca(strlen(fname) + 1); BAIL_IF_MACRO(dir == NULL, ERR_OUT_OF_MEMORY, 0); strcpy(dir, fname); ptr = strrchr(dir, ':'); if (ptr == NULL) /* just a volume name? Can't be a symlink. */ return(0); /* resolve aliases up to the actual file... */ *ptr = '\0'; BAIL_IF_MACRO(fnameToFSSpec(dir, &spec) != noErr, NULL, 0); *ptr = strlen(ptr + 1); /* ptr is now a pascal string. Yikes! */ memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; infoPB.dirInfo.ioVRefNum = spec.vRefNum; infoPB.dirInfo.ioDrDirID = spec.parID; infoPB.dirInfo.ioFDirIndex = 0; BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, 0); err = FSMakeFSSpec(spec.vRefNum, infoPB.dirInfo.ioDrDirID, (const unsigned char *) ptr, &spec); BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0); BAIL_IF_MACRO(oserr(IsAliasFile(&spec, &a, &f)) != noErr, NULL, 0); return(a); } /* __PHYSFS_platformIsSymlink */
PHYSFS_sint64 __PHYSFS_platformGetLastModTime(const char *fname) { FSSpec spec; CInfoPBRec infoPB; UInt32 modDate; if (fnameToFSSpec(fname, &spec) != noErr) return(-1); /* fnameToFSSpec() sets physfs error message. */ memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; infoPB.dirInfo.ioVRefNum = spec.vRefNum; infoPB.dirInfo.ioDrDirID = spec.parID; infoPB.dirInfo.ioFDirIndex = 0; BAIL_IF_MACRO(oserr(PBGetCatInfoSync(&infoPB)) != noErr, NULL, -1); modDate = ((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0) ? infoPB.dirInfo.ioDrMdDat : infoPB.hFileInfo.ioFlMdDat; /* epoch is different on MacOS. They use Jan 1, 1904, apparently. */ /* subtract seconds between those epochs, counting leap years. */ modDate -= 2082844800; return((PHYSFS_sint64) modDate); } /* __PHYSFS_platformGetLastModTime */
/* jijun 4/22/97, 4/23/97 */ void setneuronhome(const char* p) { CInfoPBRec myPB; short vRefNum; long dirID; Str255 dirName; char prePath[256]; static char fullPath[256]; OSErr err = HGetVol ((0), &vRefNum, &dirID); if (err==noErr) { myPB.dirInfo.ioNamePtr = dirName; myPB.dirInfo.ioVRefNum = vRefNum; myPB.dirInfo.ioDrParID = dirID; myPB.dirInfo.ioFDirIndex= -1; do { myPB.dirInfo.ioDrDirID = myPB.dirInfo.ioDrParID; err = PBGetCatInfoSync(&myPB); if (err==noErr) { dirName[dirName[0]+1]='\0'; strcpy(prePath, (char*)&dirName[1]); strcat(prePath, ":"); strcat(prePath, fullPath); strcpy(fullPath, prePath); } } while (myPB.dirInfo.ioDrDirID > 2); } neuron_home=fullPath; // get rid of last ':' neuron_home[strlen(neuron_home)-1] = '\0'; // debugfile("neuron_home = %s\n", neuron_home); }
/* ** GetDirModDate returns the modification date of a directory. If there is ** an error getting the modification date, -1 is returned to indicate ** something went wrong. */ static long GetDirModDate(short vRefNum, long dirID) { CInfoPBRec pb; Str31 tempName; long modDate; /* Protection against File Sharing problem */ tempName[0] = 0; pb.dirInfo.ioNamePtr = tempName; pb.dirInfo.ioVRefNum = vRefNum; pb.dirInfo.ioDrDirID = dirID; pb.dirInfo.ioFDirIndex = -1; /* use ioDrDirID */ if ( PBGetCatInfoSync(&pb) == noErr ) { modDate = pb.dirInfo.ioDrMdDat; } else { modDate = -1; } return ( modDate ); }
DIR *opendir(const char *dirname) { DIR* dirp = (DIR*)calloc(1, sizeof(DIR)); if (dirp != NULL) { OSErr err; Str255 s; CInfoPBRec pb = { 0 }; if (strcmp(dirname, ".")) { get_path(dirname, s); pb.hFileInfo.ioNamePtr = s; } else pb.hFileInfo.ioNamePtr = NULL; err = PBGetCatInfoSync(&pb); if (err != noErr || (pb.hFileInfo.ioFlAttrib & ioDirMask) == 0) { free(dirp); dirp = NULL; } else { dirp->file.vRefNum = pb.hFileInfo.ioVRefNum; dirp->file.parID = pb.hFileInfo.ioDirID; dirp->file.name[0] = '\0'; dirp->index = 1; } } return dirp; }
static pascal OSErr GetCatInfoNoName(short vRefNum, long dirID, ConstStr255Param name, CInfoPBPtr pb) { Str31 tempName; OSErr error; /* Protection against File Sharing problem */ if ( (name == NULL) || (name[0] == 0) ) { tempName[0] = 0; pb->dirInfo.ioNamePtr = tempName; pb->dirInfo.ioFDirIndex = -1; /* use ioDirID */ } else { pb->dirInfo.ioNamePtr = (StringPtr)name; pb->dirInfo.ioFDirIndex = 0; /* use ioNamePtr and ioDirID */ } pb->dirInfo.ioVRefNum = vRefNum; pb->dirInfo.ioDrDirID = dirID; error = PBGetCatInfoSync(pb); pb->dirInfo.ioNamePtr = NULL; return ( error ); }
bool Location_Disk_FSSpec::get_IsDirectory( void ) const { bool res = false; if( mIsDirectory == kUnknown ) // we need to use OS to define the result. { const FSSpec* pSpec = get_FSSpec(); CInfoPBRec pb; pb.dirInfo.ioNamePtr = (StringPtr) &(pSpec->name); pb.dirInfo.ioVRefNum = pSpec->vRefNum; pb.dirInfo.ioDrDirID = pSpec->parID; pb.dirInfo.ioFDirIndex = 0; OSErr err = PBGetCatInfoSync(&pb); if( (err == noErr) && (pb.hFileInfo.ioFlAttrib & kioFlAttribDirMask) != 0 ) res = true; } else { res = bool( mIsDirectory == kDirectory ); } return res; }
/* * Convert a filename to a string for display purposes. * See pp 2-44--2-46 of IM:Files * * XXX static storage considered harmful */ const char *filename_to_str(const Filename *fn) { CInfoPBRec pb; Str255 dirname; OSErr err; static char *path = NULL; char *newpath; if (path != NULL) sfree(path); path = snewn(fn->fss.name[0], char); p2cstrcpy(path, fn->fss.name); pb.dirInfo.ioNamePtr = dirname; pb.dirInfo.ioVRefNum = fn->fss.vRefNum; pb.dirInfo.ioDrParID = fn->fss.parID; pb.dirInfo.ioFDirIndex = -1; do { pb.dirInfo.ioDrDirID = pb.dirInfo.ioDrParID; err = PBGetCatInfoSync(&pb); /* XXX Assume not A/UX */ newpath = snewn(strlen(path) + dirname[0] + 2, char); p2cstrcpy(newpath, dirname); strcat(newpath, ":"); strcat(newpath, path); sfree(path); path = newpath; } while (pb.dirInfo.ioDrDirID != fsRtDirID); return path; }
unsigned long PAS_getDataSize(FSSpec *spec) { short refNum; OSErr err; Str255 temp; CInfoPBRec cbrec; err = FSpOpenDF(spec, fsRdPerm, &refNum); memcpy( temp, spec->name, spec->name[0] + 1); cbrec.hFileInfo.ioNamePtr = temp; cbrec.hFileInfo.ioDirID = spec->parID; cbrec.hFileInfo.ioVRefNum = spec->vRefNum; cbrec.hFileInfo.ioFDirIndex = 0; err = PBGetCatInfoSync(&cbrec); FSClose(refNum); if(err != noErr) { cbrec.hFileInfo.ioFlLgLen = err; } return (cbrec.hFileInfo.ioFlLgLen); }
PGPError pgpPlatformNextFileInDirectory( PFLDirectoryIterRef iter, PFLFileSpecRef * outRef ) { PGPError err = kPGPError_NoErr; FSSpec spec; HFileInfo pb; *outRef = NULL; pb.ioNamePtr = spec.name; pb.ioVRefNum = iter->vRefNum; pb.ioDirID = iter->parID; pb.ioFDirIndex = iter->dirIndex; if ( PBGetCatInfoSync( (CInfoPBPtr)&pb ) != noErr ) { if ( pb.ioResult == fnfErr ) err = kPGPError_EndOfIteration; else err = kPGPError_FileOpFailed; } else { spec.vRefNum = iter->vRefNum; spec.parID = iter->parID; err = PFLNewFileSpecFromFSSpec( iter->memoryMgr, &spec, outRef ); } if ( IsntPGPError( err ) ) iter->dirIndex++; return err; }
DIR * opendir (const char *name) /* Open a directory stream on NAME. */ /* Return a DIR stream on the directory, or NULL if it could not be opened. */ { CInfoPBRec cat_info; FSSpec spec; Boolean targetIsFolder, wasAliased; if (indx) { // We don't support more than one dir open at a time closedir((DIR *)1); // Fail hard return((DIR *)0); } dir_volume=0; // Default to the application directory dir_ID=0; while (name[0]=='.') ++name; // Don't allow leading '.', avoids device names CToPCpy(fname,name); if (!FSMakeFSSpec(0,0,fname,&spec)) { // Figure out where user is pointing ResolveAliasFile(&spec, true, &targetIsFolder, &wasAliased); cat_info.dirInfo.ioCompletion=(IOCompletionUPP)0; cat_info.dirInfo.ioNamePtr=spec.name; cat_info.dirInfo.ioVRefNum=spec.vRefNum; cat_info.dirInfo.ioFDirIndex = 0; // Use full spec cat_info.dirInfo.ioDrDirID=spec.parID; cat_info.dirInfo.ioFVersNum=0; if (!PBGetCatInfoSync(&cat_info) && (cat_info.dirInfo.ioFlAttrib&16)) spec.parID=cat_info.dirInfo.ioDrDirID; // Found it, save it's volume and dirID dir_volume=spec.vRefNum; dir_ID=spec.parID; } else return ((DIR *)0); indx=1; return((DIR *)1); }
extern void convertSpecToPath(FSSpec * s, char * p, int pLen) { OSStatus err = noErr; CInfoPBRec params; Str255 dirName; int totLen = 0, dirLen = 0; memcpy(p, s->name + 1, s->name[0]); totLen += s->name[0]; params.dirInfo.ioNamePtr = dirName; params.dirInfo.ioVRefNum = s->vRefNum; params.dirInfo.ioDrParID = s->parID; params.dirInfo.ioFDirIndex = -1; do { params.dirInfo.ioDrDirID = params.dirInfo.ioDrParID; err = PBGetCatInfoSync(¶ms); if ((err != noErr) || (totLen + dirName[0] + 2 > pLen)) { p[0] = 0; return; } dirName[++dirName[0]] = ':'; memmove(p + dirName[0], p, totLen); memcpy(p, dirName + 1, dirName[0]); totLen += dirName[0]; } while (params.dirInfo.ioDrParID != fsRtParID); p[totLen] = 0; return; }
static OSErr FSpGetCatInfo(FSSpecPtr fss, short ioFDirIndex, CInfoPBPtr cpb) // A simple wrapper for GetCatInfo. { cpb->hFileInfo.ioVRefNum = fss->vRefNum; cpb->hFileInfo.ioDirID = fss->parID; cpb->hFileInfo.ioNamePtr = fss->name; cpb->hFileInfo.ioFDirIndex = ioFDirIndex; return PBGetCatInfoSync(cpb); }
/* internal functions */ static OSErr GetCatInfos(CInfoPBRec *paramBlock, FSSpec *spec, short index) { paramBlock->hFileInfo.ioCompletion = 0; paramBlock->hFileInfo.ioNamePtr = spec->name; paramBlock->hFileInfo.ioVRefNum = spec->vRefNum; paramBlock->hFileInfo.ioFDirIndex = index; paramBlock->hFileInfo.ioDirID = spec->parID; return PBGetCatInfoSync (paramBlock); }
static OSErr GenerateUniqueName( short vRefNum, /* Volume on which the following directories * are located. */ long dirID1, /* ID of first directory. */ long dirID2, /* ID of second directory. May be the same * as the first. */ Str31 uniqueName) /* Filled with filename for a file that is * not located in either of the above two * directories. */ { OSErr err; long i; CInfoPBRec pb; static unsigned char hexStr[16] = "0123456789ABCDEF"; static long startSeed = 248923489; pb.hFileInfo.ioVRefNum = vRefNum; pb.hFileInfo.ioFDirIndex = 0; pb.hFileInfo.ioNamePtr = uniqueName; while (1) { startSeed++; pb.hFileInfo.ioNamePtr[0] = 8; for (i = 1; i <= 8; i++) { pb.hFileInfo.ioNamePtr[i] = hexStr[((startSeed >> ((8-i)*4)) & 0xf)]; } pb.hFileInfo.ioDirID = dirID1; err = PBGetCatInfoSync(&pb); if (err == fnfErr) { if (dirID1 != dirID2) { pb.hFileInfo.ioDirID = dirID2; err = PBGetCatInfoSync(&pb); } if (err == fnfErr) { return noErr; } } if (err == noErr) { continue; } return err; } }
static char *convFSSpecToPath(FSSpec *spec, int includeFile) { char *ptr; char *retval = NULL; UInt32 retLength = 0; CInfoPBRec infoPB; Str255 str255; 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 = (includeFile) ? 0 : -1; /* walk the tree back to the root dir (volume), building path string... */ do { /* check parent dir of what we last looked at... */ infoPB.dirInfo.ioDrDirID = infoPB.dirInfo.ioDrParID; if (oserr(PBGetCatInfoSync(&infoPB)) != noErr) { if (retval != NULL) free(retval); return(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); if (ptr == NULL) { if (retval != NULL) free(retval); BAIL_MACRO(ERR_OUT_OF_MEMORY, NULL); } /* if */ /* prepend new dir to retval and cleanup... */ memcpy(ptr, &str255[1], str255[0]); ptr[str255[0]] = '\0'; /* null terminate it. */ if (retval != NULL) { strcat(ptr, ":"); strcat(ptr, retval); free(retval); } /* if */ retval = ptr; } while (infoPB.dirInfo.ioDrDirID != fsRtDirID); return(retval); } /* convFSSpecToPath */
pascal void FSpCreateResFileCompat(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag) { #if !__MACOSSEVENFIVEONEORLATER if ( #if !__MACOSSEVENORLATER (!FSHasFSSpecCalls() && !QTHasFSSpecCalls()) || #endif /* !__MACOSSEVENORLATER */ !HasFSpCreateScriptSupportFix() ) { OSErr result; CInfoPBRec pb; HCreateResFile(spec->vRefNum, spec->parID, spec->name); if ( ResError() == noErr ) { /* get info on created item */ pb.hFileInfo.ioVRefNum = spec->vRefNum; pb.hFileInfo.ioDirID = spec->parID; pb.hFileInfo.ioNamePtr = (StringPtr) &(spec->name); pb.hFileInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&pb); if ( result == noErr ) { /* Set fdScript in FXInfo */ /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */ /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */ /* (smRoman is 0). fdScript is valid if high bit is set (see IM-6, page 9-38) */ pb.hFileInfo.ioFlXFndrInfo.fdScript = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); /* Set creator/fileType */ pb.hFileInfo.ioFlFndrInfo.fdCreator = creator; pb.hFileInfo.ioFlFndrInfo.fdType = fileType; /* Restore ioDirID field in pb which was changed by PBGetCatInfo */ pb.hFileInfo.ioDirID = spec->parID; result = PBSetCatInfoSync(&pb); } /* Set ResErr low memory global to result */ LMSetResErr(result); } return; } else #endif /* !__MACOSSEVENFIVEONEORLATER */ { FSpCreateResFile(spec, creator, fileType, scriptTag); return; } }
/* フルパスからボリューム番号とディレクトリIDを取得する */ static OSErr PathToSpec(const char *pathname, short *vRefNum, long *dirID, Boolean *is_dir) { FSSpec spec; OSErr err; UInt8 temp[257]; int i; CInfoPBRec pbr; HParamBlockRec hpbr; if( is_dir ) *is_dir = FALSE; temp[0] = strlen(pathname); strcpy((char*)&temp[1], pathname); if (!strchr(pathname, ':')) { /* : が含まれない場合 (ボリューム?) */ hpbr.volumeParam.ioNamePtr = temp; i = 1; do { hpbr.volumeParam.ioVolIndex = i; err = PBHGetVInfoSync(&hpbr); temp[temp[0] + 1] = 0; if (err == noErr && !strcmp((char*)&temp[1], pathname)) { *vRefNum = hpbr.volumeParam.ioVRefNum; *dirID = fsRtDirID; if( is_dir ) *is_dir = TRUE; return err; } i++; } while (err == noErr); return err; } err = FSMakeFSSpec(-1, 1, temp, &spec); if (err != noErr) return err; /* dirIDを取得する */ pbr.hFileInfo.ioNamePtr = spec.name; pbr.hFileInfo.ioVRefNum = spec.vRefNum; pbr.hFileInfo.ioFDirIndex = 0; pbr.hFileInfo.ioDirID = spec.parID; pbr.hFileInfo.ioACUser = 0; err = PBGetCatInfoSync(&pbr); if (err == noErr ){ *vRefNum = pbr.hFileInfo.ioVRefNum; *dirID = pbr.hFileInfo.ioDirID; if (pbr.hFileInfo.ioFlAttrib & 16) { if( is_dir ) *is_dir = TRUE; } return noErr; } return err; }
pascal OSErr FSpCreateCompat(const FSSpec *spec, OSType creator, OSType fileType, ScriptCode scriptTag) { #if !__MACOSSEVENFIVEONEORLATER OSErr result; UniversalFMPB pb; if ( #if !__MACOSSEVENORLATER (!FSHasFSSpecCalls() && !QTHasFSSpecCalls()) || #endif /* !__MACOSSEVENORLATER */ !HasFSpCreateScriptSupportFix() ) { /* If FSpCreate isn't called, this code will be executed */ pb.hPB.fileParam.ioVRefNum = spec->vRefNum; pb.hPB.fileParam.ioDirID = spec->parID; pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name); pb.hPB.fileParam.ioFVersNum = 0; result = PBHCreateSync(&(pb.hPB)); if ( result == noErr ) { /* get info on created item */ pb.ciPB.hFileInfo.ioFDirIndex = 0; result = PBGetCatInfoSync(&(pb.ciPB)); if ( result == noErr ) { /* Set fdScript in FXInfo */ /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */ /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */ /* (smRoman is 0). fdScript is valid if high bit is set (see IM-6, page 9-38) */ pb.ciPB.hFileInfo.ioFlXFndrInfo.fdScript = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); /* Set creator/fileType */ pb.ciPB.hFileInfo.ioFlFndrInfo.fdCreator = creator; pb.ciPB.hFileInfo.ioFlFndrInfo.fdType = fileType; /* Restore ioDirID field in pb which was changed by PBGetCatInfo */ pb.ciPB.hFileInfo.ioDirID = spec->parID; result = PBSetCatInfoSync(&(pb.ciPB)); } } return ( result ); } else #endif /* !__MACOSSEVENFIVEONEORLATER */ { return ( FSpCreate(spec, creator, fileType, scriptTag) ); } }
static OSErr GenerateUniqueName(short volume, long *startSeed, long dir1, long dir2, StringPtr uniqueName) { OSErr error = noErr; long i; CInfoPBRec cinfo; unsigned char hexStr[16]; for ( i = 0; i < 16; ++i ) { if ( i < 10 ) { hexStr[i] = 0x30 + i; } else { hexStr[i] = 0x37 + i; } } cinfo.hFileInfo.ioVRefNum = volume; cinfo.hFileInfo.ioFDirIndex = 0; cinfo.hFileInfo.ioNamePtr = uniqueName; while ( error != fnfErr ) { (*startSeed)++; cinfo.hFileInfo.ioNamePtr[0] = 8; for ( i = 1; i <= 8; i++ ) { cinfo.hFileInfo.ioNamePtr[i] = hexStr[((*startSeed >> ((8-i)*4)) & 0xf)]; } cinfo.hFileInfo.ioDirID = dir1; error = fnfErr; for ( i = 1; i <= 2; i++ ) { error = error & PBGetCatInfoSync(&cinfo); cinfo.hFileInfo.ioDirID = dir2; if ( (error != fnfErr) && (error != noErr) ) { return ( error ); } } } return ( noErr ); }
/*////////////////////////////////////// // Returns directory info structure of // file spec /////////////////////////////////////*/ static OSErr FSpGetPBRec(const FSSpec* fileSpec, CInfoPBRec *infoRec) { CInfoPBRec myInfoRec = {0}; OSErr err = noErr; myInfoRec.hFileInfo.ioNamePtr = (unsigned char *)fileSpec->name; myInfoRec.hFileInfo.ioVRefNum = fileSpec->vRefNum; myInfoRec.hFileInfo.ioDirID = fileSpec->parID; err = PBGetCatInfoSync(&myInfoRec); if (err == noErr) *infoRec = myInfoRec; return err; }
int __PHYSFS_platformIsDirectory(const char *fname) { FSSpec spec; CInfoPBRec infoPB; OSErr err; BAIL_IF_MACRO(fnameToFSSpec(fname, &spec) != noErr, NULL, 0); memset(&infoPB, '\0', sizeof (CInfoPBRec)); infoPB.dirInfo.ioNamePtr = spec.name; /* put name in here. */ infoPB.dirInfo.ioVRefNum = spec.vRefNum; /* ID of file's volume. */ infoPB.dirInfo.ioDrDirID = spec.parID; /* ID of bin's dir. */ infoPB.dirInfo.ioFDirIndex = 0; /* file (not parent) info. */ err = PBGetCatInfoSync(&infoPB); BAIL_IF_MACRO(oserr(err) != noErr, NULL, 0); return((infoPB.dirInfo.ioFlAttrib & kioFlAttribDirMask) != 0); } /* __PHYSFS_platformIsDirectory */
int mstat(const char* file, struct stat* st) { CInfoPBRec pb; unsigned char path[256]; int result = 0; memset(&pb, 0, sizeof(CInfoPBRec)); if (strcmp(file, ".") == 0) { memset(st, 0, sizeof(struct stat)); st->st_mode = S_IFDIR; st->st_ino = -1; } else { result = get_path(file, path); if (result == 0) { pb.hFileInfo.ioNamePtr = path; if (PBGetCatInfoSync(&pb) != noErr) result = -1; else { memset(st, 0, sizeof(struct stat)); if (pb.hFileInfo.ioFlAttrib & ioDirMask) st->st_mode = S_IFDIR; else st->st_mode = S_IFREG; st->st_ino = pb.hFileInfo.ioFlStBlk; st->st_dev = pb.hFileInfo.ioVRefNum; st->st_nlink = 1; st->st_size = pb.hFileInfo.ioFlLgLen; st->st_atime = pb.hFileInfo.ioFlMdDat; st->st_mtime = pb.hFileInfo.ioFlMdDat; st->st_ctime = pb.hFileInfo.ioFlCrDat; } } } return result; }
static PGPError sParentDirProc( PFLConstFileSpecRef ref, PFLFileSpecRef * outParent ) { PGPError err = kPGPError_NoErr; MyData * myData; FSSpec spec; HFileInfo pb; PGPValidateParam( ref->type == kPFLFileSpecMacType ); myData = GetMyData( ref ); spec = myData->spec; if( myData->specIsValid ) { pb.ioNamePtr = spec.name; pb.ioVRefNum = spec.vRefNum; pb.ioDirID = spec.parID; pb.ioFDirIndex = -1; if ( PBGetCatInfoSync( (CInfoPBPtr)&pb ) != noErr ) { if ( pb.ioResult == fnfErr ) err = kPGPError_FileNotFound; else err = kPGPError_FileOpFailed; } else { spec.vRefNum = pb.ioVRefNum; spec.parID = pb.ioFlParID; err = PFLNewFileSpecFromFSSpec( ref->memoryMgr, &spec, outParent ); } } else { err = kPGPError_FileNotFound; } return( err ); }
static void set_file_type(FSSpec * spec, int binary_file) { CInfoPBRec pb; OSErr ioResult; pb.hFileInfo.ioNamePtr = spec->name; pb.hFileInfo.ioVRefNum = spec->vRefNum; pb.hFileInfo.ioFDirIndex = 0; pb.hFileInfo.ioDirID = spec->parID; if (!(ioResult = PBGetCatInfoSync(&pb))) { pb.hFileInfo.ioFlFndrInfo.fdType = __gettype(binary_file); /*mm-960729*/ pb.hFileInfo.ioFlFndrInfo.fdCreator = __getcreator(binary_file); /*mm-960729*/ pb.hFileInfo.ioDirID = spec->parID; ioResult = PBSetCatInfoSync(&pb); } }
static int fetchFileSpec(FSSpec *spec,unsigned char *name,long *parentDirectory) { long aliasGestaltInfo; CInfoPBRec pb; Boolean result,ignore; FSSpec spec2; OSErr err; pb.hFileInfo.ioNamePtr = name; pb.hFileInfo.ioFVersNum = 0; pb.hFileInfo.ioFDirIndex = 0; pb.hFileInfo.ioVRefNum = spec->vRefNum; pb.hFileInfo.ioDirID = spec->parID; if (PBGetCatInfoSync(&pb) == noErr) { if (pb.hFileInfo.ioFlFndrInfo.fdFlags & kIsAlias) { err = FSMakeFSSpecCompat(spec->vRefNum, spec->parID, name,&spec2); #if TARGET_CPU_PPC if ((Gestalt(gestaltAliasMgrAttr, &aliasGestaltInfo) == noErr) && aliasGestaltInfo & (1<<gestaltAliasMgrResolveAliasFileWithMountOptions) && ((Ptr) ResolveAliasFileWithMountFlags != (Ptr)kUnresolvedCFragSymbolAddress)) { err = ResolveAliasFileWithMountFlags(&spec2,false,&ignore,&ignore,kResolveAliasFileNoUI); } else #endif err = ResolveAliasFile(&spec2,false,&ignore,&ignore); if (err == noErr) { fetchFileSpec(&spec2,spec2.name,parentDirectory); *spec = spec2; result = true; goto done; } } spec->parID = pb.hFileInfo.ioDirID; result = true; goto done; } result = false; done: if (parentDirectory != nil) *parentDirectory = pb.dirInfo.ioDrParID; return result; }
pascal OSErr FSpDirCreateCompat(const FSSpec *spec, ScriptCode scriptTag, long *createdDirID) { #if !__MACOSSEVENORLATER if ( !FSHasFSSpecCalls() && !QTHasFSSpecCalls() ) { OSErr result; UniversalFMPB pb; pb.hPB.fileParam.ioVRefNum = spec->vRefNum; pb.hPB.fileParam.ioDirID = spec->parID; pb.hPB.fileParam.ioNamePtr = (StringPtr) &(spec->name); result = PBDirCreateSync(&(pb.hPB)); *createdDirID = pb.hPB.fileParam.ioDirID; if ( result == noErr ) { /* get info on created item */ pb.ciPB.dirInfo.ioFDirIndex = 0; pb.ciPB.dirInfo.ioDrDirID = spec->parID; result = PBGetCatInfoSync(&(pb.ciPB)); if ( result == noErr ) { /* Set frScript in DXInfo */ /* The negative script constants (smSystemScript, smCurrentScript, and smAllScripts) */ /* don't make sense on disk, so only use scriptTag if scriptTag >= smRoman */ /* (smRoman is 0). frScript is valid if high bit is set (see IM-6, page 9-38) */ pb.ciPB.dirInfo.ioDrFndrInfo.frScript = (scriptTag >= smRoman) ? ((char)scriptTag | (char)0x80) : (smRoman); /* Restore ioDirID field in pb which was changed by PBGetCatInfo */ pb.ciPB.dirInfo.ioDrDirID = spec->parID; result = PBSetCatInfoSync(&(pb.ciPB)); } } return ( result ); } else #endif /* !__MACOSSEVENORLATER */ { return ( FSpDirCreate(spec, scriptTag, createdDirID) ); } }
struct dirent *readdir(DIR *dirp) { if (dirp) { CInfoPBRec pb = { 0 }; pb.hFileInfo.ioVRefNum = dirp->file.vRefNum; pb.hFileInfo.ioDirID = dirp->file.parID; pb.hFileInfo.ioFDirIndex = dirp->index++; pb.hFileInfo.ioNamePtr = dirp->file.name; if (PBGetCatInfoSync(&pb) != noErr) return NULL; memcpy(dirp->ent.d_name, dirp->file.name + 1, dirp->file.name[0]); dirp->ent.d_name[dirp->file.name[0]] = 0; return &dirp->ent; } return NULL; }